dependencies:
...
mytracker_sdk:
path: PATH_TO_SDK
...
Android api level 21 (android 5.0)
android.permission.INTERNET permission
android.permission.ACCESS_NETWORK_STATE permission
com.google.android.gms.permission.AD_ID permission
Required dependencies that will be added automatically:
Google Play Services (com.google.android.gms:play-services-ads-identifier, com.google.android.gms:play-services-appset modules)
Google Play Install Referrer (com.android.installreferrer:installreferrer module)
Huawei Media Services (com.huawei.hms:hms-ads-identifier module)
Minimum supported iOS version — 12.4
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).
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.
PATH_TO_SDK
and specify it as a dependency in pubspec.yaml of your application:dependencies:
...
mytracker_sdk:
path: PATH_TO_SDK
...
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();
MyTrackerConfig trackerConfig = await MyTracker.getTrackerConfig();
// ...
// Setting up params
// ...
// Initialize the tracker
await MyTracker.init(SDK_KEY);
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. False by default.
If your Android app requests access to the user's location, we recommend enabling tracking for more accurate analytics. In the app description in Google Play, be sure to specify "Yes" in the question about collecting location data.
This parameter is disabled by default since SDK version 3.1.0
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)
Enabling and disabling debug mode can be done via MyTracker
class static methods.
False by default.
Future setDebugMode(boolean debugMode)
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.
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()
To send data from your server to MyTracker (for example, untracked data, offline events, etc.), you might need a special device identifier — instanceId
.
The instanceId
is a device identifier (UUID v4), that generated at the first app launch
and unchanged until a user delete the app (or app data) from device.
The instanceId
can get via MyTracker
class static method (you should not use it in the main thread).
Future<String?> instanceId = MyTracker.getInstanceId()
It's essential to collect instanceId
as soon as possible
and send the identifier to your server
if you use this ID for work with S2S API.
Instead of instanceId
you can use any other device ID
and/or the user identifier customUserID
(in this case, S2S data will generate stats on users).
Learn more