<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Android api level 14 (android 4.0).
android.permission.INTERNET permission.
android.permission.ACCESS_NETWORK_STATE permission.
com.google.android.gms.permission.AD_ID permission.
The project must include Google Play Services library (com.google.android.gms:play-services-ads-identifier module).
The project must include Google Play Install Referrer (com.android.installreferrer:installreferrer module).
For Huawei AppGallery apps, the project must include Huawei Media Services (com.huawei.hms:ads-identifier module), so MyTracker can obtain OAID.
iOS 9.0.
Connected frameworks AdSupport, SystemConfiguration, CoreTelephony, CoreData, UIKit, iAd, StoreKit, AdServices, and AppTrackingTransparency.
libz.tbd library linked.
Import MyTracker.unitypackage package (get the last version at https://github.com/myTrackerSDK/mytracker-unity/releases) into your Unity project.
For Android build: add dependencies to the project through Assets → Play Services Resolver → Android Resolver → Resolve Client Jars.
For iOS build: add dependencies using CocoaPods after you created xCode project.
AndroidManifest.xml
The Unity environment supports the merge of the default manifest and the manifests that come with the various plug-ins. In the event of an error or post-processing, you might need to manually change the manifest of the Android application. For it to work properly, the following permissions must be specified in the manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
To track traffic sources, the service and receiver must be specified in the receiver:
<application>
<receiver android:name="com.my.tracker.campaign.MultipleInstallReceiver"
android:permission="android.permission.INSTALL_PACKAGES"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"/>
</intent-filter>
</receiver>
<service android:name="com.my.tracker.campaign.CampaignService" />
</application>
Proguard
If you are using Proguard, the following exceptions must be added:
-keep class com.my.tracker.** { *; }
-dontwarn com.my.tracker.**
-keep class com.android.installreferrer.** { *; }
-keep class com.android.vending.billing.** { *; }
-keep class com.android.billingclient.api.** { *; }
-keep class com.google.android.gms.** { *; }
Gradle build tool provides automatic import of these exceptions while processing AAR files
For MyTracker SDK to work properly, configuration and initialization of the tracker must be
done at the beginning of initializing of the application.
To initialize a tracker, you must specify your SDK_KEY
.
If necessary, before initialization, you can adjust the parameters of the
tracker.
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.
public class YourMonoBehaviour : MonoBehaviour
{
public void Awake()
{
#if !UNITY_IOS && !UNITY_ANDROID
return;
#endif
// Setting up the configuration if needed
var myTrackerConfig = MyTracker.MyTrackerConfig;
// ...
// Setting up params
// ...
// Initialize the tracker
#if UNITY_IOS
MyTracker.Init("SDK_KEY_IOS");
#elif UNITY_ANDROID
MyTracker.Init("SDK_KEY_ANDROID");
#endif
}
}
Configuration can be set up through the MyTrackerConfig
class instance, available through
the MyTracker.MyTrackerConfig
property. The following parameters can be configured:
IsTrackingLaunchEnabled: tracking of app launches. True by default.
Boolean IsTrackingLaunchEnabled { get; set; }
LaunchTimeout: an interval in seconds during which the app launch will not be counted and the session will stay uninterrupted. 30 seconds by default. A value between 30-7200 seconds can be selected.
Int32 LaunchTimeout { get; set; }
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. A value between 1-86400 seconds can be set up.
Int32 BufferingPeriod { get; set; }
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).
Int32 ForcingPeriod { get; set; }
IsTrackingLocationEnabled: location tracking. True for iOS and false for Android platforms 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.
For the Android platform, this parameter is disabled by default since SDK version 3.0.2
Boolean IsTrackingLocationEnabled { get; set; }
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
public RegionEnum Region { set; }
RegisterForSkAdAttribution: SKAdNetwork attribution support. YES by default.
SKAdNetwork is Apple's solution to attribute app installations to a particular campaign while maintaining user privacy.
By default, when a user first launches the app on iOS 14.5+ devices,
MyTracker SDK v2.1.2 and newer calls the SKAdNetwork method — RegisterForSkAdAttribution
,
to pass advertisement-driven install notifications to ad networks.
For its parts, the ad network can send data to MyTracker.
Since iOS 15, you can send a copy of the SKAN data directly to MyTracker
in addition to sending it to ad networks.
You can choose to turn the RegisterForSkAdAttribution
parameter off and set up SKAdNetwork methods on your own.
Without SKAdNetwork, you will not be able to track attribution on devices
if the user denied permission.
For more details, refer to the iOS & SKAdNetwork section and the Apple documentation
Boolean RegisterForSkAdAttribution { get; set; }
Enabling/disabling of debug mode is made through static
properties of MyTracker
class. False by default.
Boolean IsDebugMode { get; set; }
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.
public void SetUserInfo()
{
var myTrackerParams = MyTracker.MyTrackerParams;
// Set user id
myTrackerParams.CustomUserId = "user_id";
}
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 through static properties of MyTracker
class.
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 userId
parameter.
userId is a required parameter since SDK version 2.0.1
void TrackRegistrationEvent(String userId)
Login event. You should call the method right after user successfully authorized in the app.
Pass the user identifier in the userId
parameter.
userId is a required parameter since SDK version 2.0.1
void TrackLoginEvent(String userId)
Invite sent event. The extra eventParams
parameter allows for any key-value parameters to be
added for the event. Max. length of key and value — 255 chars.
void TrackInviteEvent(IDictionary<String, String> eventParams = null)
Level reached event. The level
parameter is the level number. The extra eventParams
parameter allows
for any key-value parameters to be added for the event. Max. length of key and value — 255
chars.
void TrackLevelEvent(Int32? level = null, IDictionary<String, String> eventParams = null)
Custom event with a specified name. The extra eventParams
parameter allows for any key-value
parameters to be added for the event. Max name, key or value length — 255 chars.
void TrackEvent(String name, IDictionary<String, String> eventParams = null)
Example:
var IDictionary<String, String> eventCustomParams = new Dictionary<String, String>();
eventCustomParams["someParamKey1"] = "someParamValue1";
eventCustomParams["someParamKey2"] = "someParamValue2";
MyTracker.TrackEvent("eventName", eventCustomParams));
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.
void Flush()
On iOS platform all in-app payments and subscriptions events will be tracked automatically. To track payments
on Android platform you must use the TrackPurchaseEvent(...)
method (which calls will be ignored on
iOS). If your application use Unity Purchase:
void TrackPurchaseEvent(Product product, IDictionary<String, String> eventParams = null)
product
— instance of Product class
eventParams
— optional parameter to pass any additional event parameters in key-value form.
Maximum length of key and value is 255 characters
If your application is not using Unity Purchase:
#if UNITY_ANDROID
void TrackPurchaseEvent(String skuDetails, String purchaseData, String dataSignature, IDictionary<String, String> eventParams = null)
#endif
skuDetails
— return value of the getSkuDetails()
method call according to documentation
purchaseData
— JSON object in INAPP_PURCHASE_DATA field of the getBuyIntent()
method
return value, according to documentation
dataSignature
— string from INAPP_DATA_SIGNATURE field of the getBuyIntent()
method
return value
eventParams
— optional parameter to pass any additional event parameters in key-value form.
Maximum length of key and value is 255 characters
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.
public static String InstanceId { get; }
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:
gaid
, androidId
, appSetId
,
idfa
, iosVendorId
,
and/or the user identifier customUserID
(in this case, S2S data will generate stats on users).
Learn more
Deep links allow sending additional parameters to the app. So a user can go to a specific app screen. For more details, see the Deep Links section.
To support deferred deep links, an action listener must be set up with the
MyTracker.SetAttributionListener
method. The listener will be called just once, following first app launch if
a deferred deep link is found. As a delegate parameter, the MyTrackerAttribution
attribution object,
which contains the Deeplink property, is passed.
public class YourMonoBehaviour : MonoBehaviour
{
public void Awake()
{
#if !UNITY_IOS && !UNITY_ANDROID
return;
#endif
// Setting up the configuration if needed
var myTrackerConfig = MyTracker.MyTrackerConfig;
// ...
// Setting up params
// ...
// Setting up Listener
MyTracker.SetAttributionListener(attribution => Debug.Log("Attribution: " + attribution.Deeplink));
// Initialize the tracker
#if UNITY_IOS
MyTracker.Init("SDK_KEY_IOS");
#elif UNITY_ANDROID
MyTracker.Init("SDK_KEY_ANDROID");
#endif
}
}