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).

iOS

  • iOS 7.0.

  • Active frameworks AdSupport, SystemConfiguration, CoreTelephony, CoreData, CoreLocation, 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: set up Google Play Services. It can be done through Assets → Play Services Resolver → Android Resolver → Resolve Client Jars.

  • For iOS build: dependencies can be added to the project through the MyTrackerPostProcessor script.


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.CampaignReceiver"
              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.google.android.gms.ads.identifier.AdvertisingIdClient {
    com.google.android.gms.ads.identifier.AdvertisingIdClient$Info getAdvertisingIdInfo(android.content.Context);
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {
    java.lang.String getId();
    boolean isLimitAdTrackingEnabled();
}
-keep class com.android.installreferrer.** { *; }
-keep class com.android.vending.billing.** { *; }
-keep class com.android.billingclient.api.** { *; }

Initialization

For myTracker SDK to work properly, the creation, configuration and initialization of the tracker must be done at the beginning of initializing of the application. For the correct operation of myTracker SDK, the creation, configuration and initialization of the tracker must be done at the initial stage of initialization of the application. To create a tracker version, you must specify your SDK_KEY. After creating a tracker version, you need to initialize. If necessary, between creation of a version and initialization, you can adjust the parameters of the tracker.

public class YourMonoBehaviour : MonoBehaviour
{
    public void Awake()
    {
        // Create tracker version depending on the platform
#if UNITY_IOS
        MyTracker.Create("SDK_KEY_IOS");
#elif UNITY_ANDROID
        MyTracker.Create("SDK_KEY_ANDROID");
#else
        return;
#endif

        // Setting up parameters if necessary
        var myTrackerParams = MyTracker.MyTrackerParams;
        // ...
        // Setting up tracker parameters myTrackerParams
        // ...

        // Version initialization
        MyTracker.Init();
    }
}

API

Tracker parameters

Tracker parameters can be set up through MyTrackerParams version, available through MyTracker.MyTrackerParams property. The following parameters can be configured:

Tracking of app launches. True by default.

Boolean MyTrackerParams.IsTrackingLaunchEnabled { get; set; }

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; }

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; }

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; }

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/disable tracking and debug mode

Enabling/disabling of the tracking, as well as enabling of debug mode is made through static properties of MyTracker class.

Enabling/disabling of the tracker. True by default.

Boolean IsEnabled { get; set; }

Enabling/disabling of debug mode. False by default.

Boolean IsDebugMode { get; set; }

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.

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 and/or got a unique identifier. It's essential to set the customUserId parameter before you call TrackRegistrationEvent. This parameter allows you to pass user identifier with tracked event and get reliable user stats.

Boolean TrackRegistrationEvent()

Login event. You should call the method right after user successfully authorized in the app and got a unique identifier. It's essential to set the customUserId parameter before you call TrackLoginEvent. This parameter allows you to pass user identifier with tracked event and get reliable user stats.

Boolean TrackLoginEvent()

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.

Boolean 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.

Boolean 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.

Boolean 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.

Boolean 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:

Boolean 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
Boolean 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

Deferred deep links 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 deep links, an action listener must be set up with the 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()
    {
        // Create tracker version depending on the platform
#if UNITY_IOS
        MyTracker.Create("SDK_KEY_IOS");
#elif UNITY_ANDROID
        MyTracker.Create("SDK_KEY_ANDROID");
#else
        return;
#endif

        // Set up parameters, if necessary
        var myTrackerParams = MyTracker.MyTrackerParams;
        // ...

        // Setting up Listener
        MyTracker.SetAttributionListener(attribution => Debug.Log("Attribution: " + attribution.Deeplink));

        // Initialize version
        MyTracker.Init();
    }
}