Skip to content

Advanced use

darken edited this page Dec 9, 2021 · 3 revisions

Advanced use

Custom queries

You should be able to use all common actions through the TrackHelper utility, but in some instances you may want full control over what is send to the server.

The base method for any event is track. You can create your own TrackMe objects, set the parameters and hen send it.

TrackMe trackMe = new TrackMe()
trackMe.set...
/* ... */
Tracker tracker = ((YourApplication) getApplication()).getTracker();
tracker.track(trackMe);

Dispatching

The tracker, by default, will dispatch any pending events every 120 seconds. If 0 is used, any event will be dispatched immediatly. If a negative value is used the dispatch timer will never run, a manual dispatch must be used:

        
    Tracker tracker = ((YourApplication) getApplication()).getTracker();
    tracker.setDispatchInterval(-1);
    // Track exception
    try {
        revenue = getRevenue();
    } catch (Exception e) {
        tracker.trackException(e, e.getMessage(), false);
        tracker.dispatch();
        revenue = 0;
    }
    

When there is more than one event in queue, dispatch is done using a POST request with JSON data (Bulktracking). JSON data may be gzipped before being dispatched. This may be set at app init time as follows:

    private void initMatomo() {
      ...
        
        //set dispatcher to json gzip
        getTracker().setDispatchGzipped(true);

      ...
    }

This feature must also be set on server-side using mod_deflate/APACHE or lua_zlib/NGINX (lua_zlib - lua-nginx-module - inflate.lua samples - inflate.lua simplified Matomo sample).

User ID

Providing the Tracker with a user ID lets you connect data collected from multiple devices and multiple browsers for the same user. A user ID is typically a non empty unique string such as username, email address or UUID that uniquely identifies the user.

If no user ID is used, the SDK will generate, manage and persist a random id for you using UUID.random() the id will be lost when the app is reinstalled as we can only store it within the apps settings files.

        ((YourApplication) getApplication()).getTracker().setUserId("user@email.com");

If you set a custom user ID, you must persist it make sure to set it each app initialization.

Modifying default parameters

The Tracker has a method getDefaultTrackMe modifying the object returned by it will change the default values used with each Tracker.track(...) call. Note though that the Tracker will not overwrite any values you set on your own TrackMe object.

If you need this consider making a ticket for it as this implementation details is subject to change.

Clone this wiki locally