- Notifications
You must be signed in to change notification settings - Fork168
Getting started
- If don't a server running Matomo already, follow these instructions toinstall Matomo on a server.
- Create a new website (or app) in the Matomo web interface.
- Copy and note the Website ID from "Settings > Websites" and your server address.
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.
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.
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>
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.
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); }}
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);
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)
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.
You can also track installs.
TrackHelper.track().download().with(tracker);
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);