Log in

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

  • Connected frameworks AdSupport, SystemConfiguration, CoreTelephony, CoreData, UIKit, iAd, StoreKit, AdServices, and AppTrackingTransparency (you can use App Tracking Transparency Plugin).

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.

Integration

  1. Download the latest version of 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 SDK_KEY. 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.

SDK_KEY is generated automatically after you added your application to MyTracker. To get the key, go to the Application list page, select the required application, and copy the key from the Overview tab. Please note that if you build an app for different platforms, you need individual SDK_KEY for each of them.

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

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

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

API

Tracker configuration

Configuration can be set up in the MyTrackerConfig class instance available through the MyTracker.getTrackerConfig() method. All parameters can be set up in MyTrackerParams class instance available through the 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.

Since March 1, 2023, the region parameter is disabled. Regardless of the selected value, the data will be sent to servers located in the Russian Federation. To select a different region, please contact our support team

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 payment 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. For details, see the User tracking section.

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 cannot 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 userId parameter.

Future trackRegistrationEvent(String userId)

Login event. You should call the method right after user successfully authorized in the app. Pass the user identifier in the required userId parameter.

Future trackLoginEvent(String userId)

Any user defined event with a custom name. Any optional parameters can be passed with event as "key-value" by the optional eventParams parameter. 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()
Was this article helpful?