Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Getting started

darken edited this pageDec 9, 2021 ·6 revisions

Getting started

Setup

Server

Client

Including the library

Add this to your app modules build.gradle file, e.g.~/git/MyApp/app/build.gradle

dependencies {    maven { url'https://jitpack.io' }    implementation'com.github.matomo-org:matomo-sdk-android:<latest-version>'}

Replace<latest-version> with the latest release name, seereleases for the latest one.

You can also build the sdk yourself from the source code and include it as jar/aar file. You might consider this if there are changes that have not yet been released.

Client configuration

Basic

You can simply have your application extend ourMatomoApplication class. You will be forced to implement a few abstract methods.This approach is used in our demo app.

Advanced

You can also manage theTracker yourself. To ensure that the metrics are not over-counted, it is highly recommended that the tracker is created and managed in the Application class (i.e. not created twice). TheTracker itself is thread-safe and can be shared through out your application. It's not recommended to create multipleTracker instances for the same target.

importjava.net.MalformedURLException;publicclassYourApplicationextendsApplication {privateTrackermMatomoTracker;publicsynchronizedTrackergetTracker() {if (mMatomoTracker !=null)returnmMatomoTracker;mMatomoTracker =TrackerBuilder.createDefault("http://your-matomo-domain.tld/matomo.php",1).builld(Matomo.getInstance(this));returnmMatomoTracker;    }//...}

Don't forget to add application name to yourAndroidManifest.xml file.

    <applicationandroid:name=".YourApplication"><!-- activities goes here-->    </application>

Using Matomo

The recommended way to use the library is by using theTrackHelper class. It has methods for all common actions which can be chained in a way that facilities the correct order and use.

Just by using autocompletion onTrackHelper. you can probably get pretty far.

Track screen views

To send a screen view, set the screen path and titles on the tracker

publicclassYourActivityextendsActivity {@OverridepublicvoidonCreate(BundlesavedInstanceState) {super.onCreate(savedInstanceState);Trackertracker = ((MatomoApplication)getApplication()).getTracker();TrackHelper.track().screen("/your_activity").title("Title").with(tracker);    }}

Track events

To collect data about user's interaction with interactive components of your app, like button presses or the use of a particular item in a game usetrackEventmethod.

TrackHelper.track().event("category","action").name("label").value(1000f).with(tracker);

Track goals

If you want to trigger a conversion manually or track some user interaction simply call the methodtrackGoal.Read more about what is aGoal in Matomo.

TrackHelper.track().goal(1).revenue(revenue).with(tracker)

Track custom values

To track a custom name-value pair assigned to your users or screen views useCustom Dimensions. Note that the custom value data is not send by itself, but only with other tracking actions such as screenviews or events.More aboutcustom variables on matomo.org.

Trackertracker = ((MatomoApplication)getApplication()).getTracker();TrackHelper.track().screen("/path").dimension(1,"TestValue").with(tracker);

1 is our dimension slot andTestValue the dimension value.

Track installs

You can also track installs.

TrackHelper.track().download().with(tracker);

Ecommerce

Matomo provides ecommerce analytics that let you measure items added to carts, and learn detailed metrics about abandoned carts and purchased orders.

To track an Ecommerce order usetrackEcommerceOrder method.orderId andgrandTotal (ie. revenue) are required parameters.

Trackertracker = ((MatomoApplication)getApplication()).getTracker();EcommerceItemsitems =newEcommerceItems();items.addItem(newEcommerceItems.Item("sku").name("product").category("category").price(200).quantity(2));items.addItem(newEcommerceItems.Item("sku").name("product2").category("category2").price(400).quantity(3));TrackHelper.track().order("orderId",10000).subTotal(7000).tax(2000).shipping(1000).discount(0).items(items).with(tracker);
Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp