Unity V2 V1

Basic requirements

Android

  • Android api level 14 (android 4.0).

  • android.permission.INTERNET permission.

  • android.permission.ACCESS_NETWORK_STATE 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).

iOS

  • iOS 8.0.

  • Active frameworks AdSupport, SystemConfiguration, CoreTelephony, CoreData, UIKit, iAd, StoreKit.

  • libz.tbd library linked.

Integration

  • 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 may 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

Initialization

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.

public class YourMonoBehaviour : MonoBehaviour
{
    public void Awake()
    {
#if !UNITY_IOS && !UNITY_ANDROID
        return;
#endif

        // etting 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
    }
}

API

Tracker configuration

Configuration can be set up through MyTrackerConfig class instance, available through MyTracker.MyTrackerConfig property. The following parameters can be configured:

IsTrackingLaunchEnabled: tracking of app launches. True by default.

Boolean MyTrackerParams.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: an interval in seconds during which the events will accumulate on the device before being sent to server. 900 seconds by default. 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 by default.

Boolean IsTrackingLocationEnabled { get; set; }

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

public RegionEnum Region { set; }

Enable/disabledebug mode

Enabling/disabling of debug mode is made through static properties of MyTracker class. False by default.

Boolean IsDebugMode { get; set; }

Track users

Set the customUserId parameter to track user statistics, not only device. It is 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 is important 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 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 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 parameter userId.

void TrackRegistrationEvent(String userId)

userId is a required parameter since SDK version 2.0.1

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

void TrackLoginEvent(String userId)

userId is a required parameter since SDK version 2.0.1

Invite sent event. Extra eventParams parameter allows for any key-value parameters to be added for the event. Max. length of key and value – 64 chars.

void TrackInviteEvent(IDictionary<String, String> eventParams = null)

Level reached event. Level parameter is the level number. Extra eventParams parameter allows for any key-value parameters to be added for the event. Max. length of key and value – 64 chars.

void TrackLevelEvent(Int32? level = null, IDictionary<String, String> eventParams = null)

Custom event with a specified name. Extra eventParams parameter allows for any key-value parameters to be added for the event. Max name, key or value length — 64 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 is 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()

Track in app purchases

On iOS platform all in app purchase events will be tracked automatically. To track in app purchases on Android platform you must use 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 params in key-value form. Maximum length of key and value is 64 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 getSkuDetails() method call according to documentation
  • purchaseData — JSON object in INAPP_PURCHASE_DATA field of getBuyIntent() method return value, according to documentation
  • dataSignature — string from INAPP_DATA_SIGNATURE field of getBuyIntent() method return value
  • eventParams – optional parameter to pass any additional event params in key-value form. Maximum length of key and value is 64 characters

S2S tracking

To send data from your server to myTracker (for example, untracked data, offline events, etc.), you need to get special device identifiers — 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.

+ (NSString *)instanceId;
static let instanceId: String

It is important to collect instanceId as soon as possible and send identifiers to your server because you need these IDs to work with S2S API.

Deffered deeplinks allow for any parameters to be sent to the app during first launch of the app following the install. For instance, these parameters can be used to send the user to a specific screen in the app. To support deeplinks, 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 deeplink 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
    }
}