Flutter

Basic requirements

Android

  • Android api level 14 (android 4.0)

  • android.permission.INTERNET permission

  • android.permission.ACCESS_NETWORK_STATE permission

Required dependencies that will be added automatically:

iOS

  • Minimum supported iOS version — 9.0

  • xCode version 12.4 or higher

If you need data on IDFA/IDFV from iOS 14+, you should get user permission. To do this, you can use App Tracking Transparency Plugin or implement the permission request yourself.

Location data

If you need to collect location data, you should ad location access permissions and get user permission. To do this, you can use Location Permission Plugin or implement the permission request yourself.

App on Huawei Store

In case of building an app for Huawei App Store you should have the Huawei Media Services library connected to the project (com.huawei.hms:hms-ads-identifier module), so that MyTracker can get OAID.

Integration

  1. Download latest version SDK.
  2. Add the downloaded file to your project at some path PATH_TO_SDK and specify it as a dependency in pubspec.yaml of your application:
dependencies:
  ...
  mytracker_sdk:
    path: PATH_TO_SDK
  ...

Initialization

To initialize SDK, you have to enter your appId. And before that, you may set different settings for the tracker (configurations, parameters, deep links, etc.). App activity such as launches and sessions are tracked automatically.

// Setting up the configuration if needed
MyTrackerParams trackerParams = await MyTracker.getTrackerParams();
MyTrackerParams trackerConfig = await MyTracker.getTrackerConfig();

// ...
// Setting up params
// ...

// Initialize the tracker
await MyTracker.initTracker(SDK_KEY);

API

Tracker configuration

Configuration can be set up in MyTrackerConfig class instance available through MyTracker.getTrackerConfig() method. All parameters can be set up in MyTrackerParams class instance available through MyTracker.getTrackerParams() method. Currently available:

TrackingLaunchEnabled: app launch tracking. True by default.

Future<MyTrackerConfig> setTrackingLaunchEnabled(boolean trackingLaunchEnabled)

LaunchTimeout: an interval (in seconds) during which a new launch is not tracked and a session is not interrupted while app is in background. 30 seconds by default. Possible value range: 30-7200 seconds.

Future<MyTrackerConfig> setLaunchTimeout(int seconds)

BufferingPeriod: the time during which events are accumulated locally on the device before being sent to the MyTracker server. The default value is 900 seconds, allowed values are: 1-86400 seconds (1 day).

Future<MyTrackerConfig> setBufferingPeriod(int seconds)

ForcingPeriod: an interval (in seconds) starting from application install/update during which any new event will be send to the server immediately, without local buffering. Default value is set to 0 (immediate sending is disabled), allowed values are 0-432000 seconds (5 days).

Future<MyTrackerConfig> setForcingPeriod(int seconds)

TrackingLocationEnabled: geolocation tracking. True by default.

Future<MyTrackerConfig> setTrackingLocationEnabled(boolean trackingLocationEnabled)

Region, where the data collection server is located. Choose a region based, for example, on current legislation. Available values:

  • RegionEnum.RU — server on the territory of Russian Federation

  • RegionEnum.EU — server on the territory of Europe

Future<MyTrackerConfig> setRegion(MyTrackerRegion region)

AutotrackingPurchaseEnabled: automatic in-app purchase tracking. True by default.

Future<MyTrackerConfig> setAutotrackingPurchaseEnabled(boolean autotrackingPurchaseEnabled)

Enable/disable debug mode

Enabling and disabling debug mode can be done via MyTracker class static methods. false by default.

Future setDebugMode(boolean debugMode)

Track users

Set the customUserId parameter to track user stats, not only device. It's a unique user identifier in the project, that you specify at the time of registration. The identifier should remain unchanged even when user switch devices. The parameter allows you to estimate the size and activity of user base, regardless of the number of user devices. Also you can keep your customer data consistent if a user changes a device.

It's essential to set the parameter before tracking events to pass user identifier with every event.

Future setUserInfo() async
{
    MyTrackerParams trackerParams = await MyTracker.getTrackerParams();

    // Set user id
     trackerParams.setCustomUserIds(["user_id_0", "user_id_1"]);

}

If customUserId was set to the application with an existing registered users, MyTracker can't calculate exact Lifetime metrics without registration time. For pre-registered users, Lifetime statistic will be count on the date of the first tracked event with customUserId.

To turn off user tracking, pass an empty value in the customUserId parameter.

Track events

Events can be sent via MyTracker class static methods. Before you call methods, set the customUserId parameter to pass user identifier with every tracked event.

The following methods for event tracking are available:

Registration event. You should call the method right after user registered in the app. Pass the user identifier in the required parameter userId. Any optional parameters can be passed with event as "key-value" by optional parameter eventParams. Max key or value length — 255 chars.

Future trackRegistrationEvent(String userId, Map<String, String>? eventParams)

Login event. You should call the method right after user successfully authorized in the app. Pass the user identifier in the required parameter userId. Any optional parameters can be passed with event as "key-value" by optional parameter eventParams. Max key or value length — 255 chars.

Future trackLoginEvent(String userId, Map<String, String>? eventParams)

Any user defined event with a custom name. Any optional parameters can be passed with event as "key-value" by optional parameter eventParams. Max name, key or value length — 255 chars.

Future trackEvent(String name, Map<String, String>? eventParams)

Example:

MyTracker.trackEvent("name", {"key_0": "value_0", "key_1": "value_1"});

Force sending events from local buffer to server and reset buffering timers.

The SDK, which reduces channel load and lowers impact on app performance, collects all data on the device before sending it off to the server and regularly does so in a compressed format. By default, data is sent every 15 minutes. The interval can be changed to anywhere from 1 second to 1 day through the bufferingPeriod property. If the user has quit the app, the events will be sent during next launch. It's extremely important to analyse certain events as soon as possible, especially in the first sessions since installing the app. The flush() method will help.

Future flush()