Unity

SDK Integration

If you have previously used the Unity SDK version 2+, you need to delete the following files and folders in the "Assets" folder of your project:

To integrate devtodev analytics SDK, you can use one of the two methods: by using the Unity Package Manager (recommended) or by manually importing the unitypackage.

Integration by using the Unity Package Manager

If you integrated the devtodev package manually, then you need to delete the Assets/DevToDev and Plugins/DevToDev folders.

  1. Open the Package Manager (Window → Package Manager), click + in the top left corner and select Add package from git URL.

  2. Copy the repository URL https://github.com/devtodev-analytics/package_Analytics.git to the input box and click Add.

  3. Wait for the Unity Package Manager to download the package.

If you work with SDK version 3.5.0 and above, and you want to use Google Ad ID, you need to add devtodev-analytics/package_Google. When developing and publishing apps for kids (COPPA), you do not need devtodev-analytics/package_Google. Read more about working with COPPA in the COPPA section.

You can pick a specific SDK version by adding # and a version number at the end of the URL, for example: https://github.com/devtodev-analytics/package_Analytics.git#v3.3.2

Integration by importing unitypackage

  1. In the Unity Editor menu, open Assets → Import Package → Custom Package

  2. Select the DTDAnalytics.unitypackage that you have just downloaded

  3. Click Import

If you work with SDK version 3.5.0 and above, and you want to use Google Ad ID, you need to import the DTDGoogle.unitypackage. When developing and publishing apps for kids (COPPA), you do not need the DTDGoogle.unitypackage. Read more about working with COPPA in the COPPA section.

SDK Initialization

Create a script with the following code and attach it to the GameObject that will survive the entire life cycle of the app.

using DevToDev.Analytics;
using UnityEngine;

public class DTDObject : MonoBehaviour
{
    void Start()
    { 
#if UNITY_ANDROID
        DTDAnalytics.Initialize("androidAppID");
#elif UNITY_IOS
        DTDAnalytics.Initialize("IosAppID");
#elif UNITY_WEBGL
        DTDAnalytics.Initialize("WebAppID");
#elif UNITY_STANDALONE_WIN
        DTDAnalytics.Initialize("winAppID");
#elif UNITY_STANDALONE_OSX
        DTDAnalytics.Initialize("OsxAppID");
#elif UNITY_WSA
        DTDAnalytics.Initialize("UwpAppID");
#endif
    }
}

You can find the AppID in the settings of the respective app in devtodev (Settings → SDK → Integration → Credentials).

config - an object instance of DTDAnalyticsConfiguration, which is used for specifying additional properties during the initialization.

DTDAnalyticsConfiguration

Parameter

Type

Description

CurrentLevel

Integer

The player level at the moment of devtodev SDK initialization. It’s optional but we recommend using it for improving data accuracy.

UserId

String

A custom user ID assigned by the developer. In the case of default calculation by device IDs, the identifier can be used for searching users in devtodev. In case the project uses calculation by user IDs, the parameter is mandatory because it becomes the principal calculation ID in devtodev.

TrackingAvailability

DTDTrackingStatus (enum)

The property allows or disallows devtodev tracking of the user. By default, it is set to DTDTrackingStatus.Enable. SDK stores the previously assigned value. Pass DTDTrackingStatus.Disable if the user opted out of tracking in line with GDPR.

LogLevel

DTDLogLevel (enum)

The level of logging the SDK activity. The DTDLogLevel.no value is used by default. For troubleshooting during integration it is recommended to set it to DTDLogLevel.Debug, and either switch it off DTDLogLevel.No. Use DTDLogLevel.No in the release version.

ApplicationVersion

String

The app version during the devtodev SDK initialization. Use the property on the WinStandalone platform only. For all other platforms, data is collected automatically.

Example:

var config = new DTDAnalyticsConfiguration
{
    ApplicationVersion = "1.2.3",
    LogLevel = DTDLogLevel.No,
    TrackingAvailability = DTDTrackingStatus.Enable,
    CurrentLevel = 1,
    UserId = "unique_userId"
};
using DevToDev.Analytics;
using UnityEngine;

public class DTDObject : MonoBehaviour
{
    void Start()
    { 
#if UNITY_ANDROID
        DTDAnalytics.Initialize("androidAppID", config);
#elif UNITY_IOS
        DTDAnalytics.Initialize("iOSAppID", config);
#elif UNITY_WEBGL
        DTDAnalytics.Initialize("WebAppID", config);
#elif UNITY_STANDALONE_WIN
        DTDAnalytics.Initialize("winAppID", config);
#elif UNITY_STANDALONE_OSX
        DTDAnalytics.Initialize("OSXAppID", config);
#elif UNITY_WSA
        DTDAnalytics.Initialize("UwpAppID", config);
#endif
    }
}

Specific integration features of certain platforms

Windows Standalone

SDK Activity

The SDK can’t control app activity in case you use Windows Standalone therefore this responsibility is shifted to the developer. While initializing the SDK, the activity starts automatically and after that, the activity status will not auto-change. To track app activity, the developer can use the following methods: DTDAnalytics.StartActivity and DTDAnalytics.StopActivity. It is recommended to use the DTDAnalytics.StopActivity method to stop activity when the app goes into the background or gets closed. You can use the DTDAnalytics.StartActivity method to resume activity when the app gets reopened from the taskbar.

For other platforms, there is no need to manually call the DTDAnalytics.StartActivity and DTDAnalytics.StopActivity methods.

Universal Windows Platform (WSA)

In the version 2019.2, the Executable Only option was added to the Build Type. This option is incompatible with the SDK because the SDK needs access to the project file in order to register the DevToDev.Background service.

Android

To resolve external android dependencies, you need to use External Dependency Manager for Unity.

Add the following strings to proguard.txt (read more about Unity proguard here):

-keep class com.devtodev.** { *; }
-dontwarn com.devtodev.**

Huawei

  1. Select your project in https://developer.huawei.com/consumer/en/service/josp/agc/index.html#/myProject In the “General information” section find “App information” and download the “agconnect-services.json“ file.

  2. If you imported the DTDGoogle package, delete the imported files Assets\Plugins\DevToDev\Android\DTDGoogleAndroid.dll and Assets\DevToDev\Analytics\Editor\GoogleDependencies.xml

  3. Import the DTDHuawei.unitypackage manually from GitHub or use Unity Package Manager with DTDHuawei package.

  4. In the assets/Plugins/Android/ folder create a settingsTemplate.gradle file with the following content:

    import java.nio.file.Files
    
    static void enableJetifier(Project project) {
        project.ext['android.useAndroidX'] = true
        project.ext['android.enableJetifier'] = true
    }
    
    static void addBuildscript(Project project) {
        project.buildscript {
            repositories {
                maven { url 'https://plugins.gradle.org/m2/' } 
                maven { url 'https://developer.huawei.com/repo/' }
            }
    
            dependencies {
                classpath 'com.huawei.agconnect:agcp:1.6.5.300'
            }
        }
    }
    
    static void applyPlugins(Project project) {
        if (project.name != 'launcher') return
    
        project.afterEvaluate {
            it.apply plugin: 'com.huawei.agconnect'
        }
    }
    
    static void copyAppGalleryJson(Project project) {
        if (project.name != 'launcher') return
    
        def destinationFile = new File("${project.rootDir}/launcher/agconnect-services.json")
        if (destinationFile.exists()) return
    
        def sourceFile = new File("${project.rootDir}/unityLibrary/devtodev.plugin/agconnect-services.json")
        Files.copy(sourceFile.toPath(), destinationFile.toPath())
    }
    
    gradle.rootProject {
        it.afterEvaluate {
            it.allprojects {
                enableJetifier(it)
                addBuildscript(it)
                applyPlugins(it)
                copyAppGalleryJson(it)
            }
        }
    }
    
    include ':launcher', ':unityLibrary'
    **INCLUDES**

  5. Open Window → devtodev and select Create android plugin folder

  6. Copy the “agconnect-services.json“ file to the Assets\Plugins\Android\devtodev.plugin folder

  7. Open Assets → External Dependency Manager → Android ResolverAssets → External Dependency Manager → Android Resolver and click Resolve

  8. To proguard add the following rule:

    -keep class com.devtodev.** { *; }
    -dontwarn com.devtodev.**
    -keep class com.huawei.hms.**{*;}

iOS

To integrate with Xcode, the SDK uses PostProcessBuild in the DTDPostProcessAnalytics and DTDPostProcessMessaging scripts. If you use custom PostProcessBuild scripts, add them callbackOrder of less than 98 to avoid conflicts.

Your app must request tracking authorization before it can get the advertising identifier. See the detailed instruction on how to request it.

If you want to disable tracking of advertising identifiers, you need to open the DTDPostProcesssAnalytics.cs file and comment out the line 39: project.AddFrameworkToProject(targetGuid, "AppTrackingTransparency.framework", true);

iOS SDK Signature and Privacy Manifest

At WWDC23 Apple introduced new privacy manifests and xcframework signature. More information about it can be found here.

Apps targeted at children

When developing and publishing apps targeted at children under 13 years old, you need to ensure special conditions for data processing. Any mobile app aimed at children or intended for users in a region with strict regulations on child online protection, must comply with current laws.

If your app has to comply with the legal requirements (COPPA), use the following recommendations:

  • Implement the CoppaControlEnable method. The method disables collection of ad IDs and vendor IDs (IDFA, IDFV).

  • To comply with Apple’s guidelines, remove from Xcode project:

    1. AppTrackingTransparency.framework and all the links pointing to it.

    2. AdSupport.framework and all the links pointing to it.

    3. Set IS_COPPA_ENABLED = true in DTDPostProcessAnalytics.cs (Assets/DevToDev/Analytics/Editor)

Call the CoppaControlEnable method before SDK initialization. If the method was not called, the SDK will work as before.

DTDAnalytics.CoppaControlEnable();
DTDAnalytics.Initialize("App ID", config);

Last updated