LogoLogo
My AppsLive demoNewsArticles
  • Introduction
  • 📌Product updates: 2025
    • 2024
    • 2023
  • Getting Started
    • Registration
    • Adding a space
    • Adding an app to the space
  • Basic Events & Custom Events
  • Integration
    • Expert Tips
      • What to track
      • Payments & Anti-cheat
      • Check your integration
    • Integration of SDK 2.0+
      • SDK Integration
        • Android
        • iOS
        • macOS
        • Windows
        • Web
          • Web SDK Integration
          • Web SDK Releases
        • Unity
        • Unreal Engine
        • Godot Engine
      • Automatic payment tracking
        • App Store
        • Google Play
      • Setting up Events
        • Basic methods
        • Secondary methods
        • User profile
        • Anticheat methods
        • Track sessions
      • Push notifications
        • Android
        • iOS
        • Windows (UWP)
        • Unity
          • Android
          • iOS
          • Windows (UWP/WSA)
        • Unreal Engine
      • A/B testing
        • Description of A/B testing on the SDK side
        • Working with A/B tests in the devtodev interface
        • A/B testing examples
    • Test Devices
    • Server API
      • Data API 2.0
      • Subscription API
      • Push API
        • IOS
        • Android
        • Windows UWP
        • Windows
      • Raw Export
      • Labels API
      • Data API
    • Import historical data via API
    • Data Export
      • Data Export to Cloud Storage (BigQuery / Amazon S3)
    • Integration of SDK 1.0+ (deprecated)
      • SDK Integration
        • iOS
        • Android
        • Windows 8.1 and 10
        • Web
        • Unity
        • Mac OS
        • Adobe Air
        • UE4
      • Setting up Events
        • Basic methods
        • Secondary methods
        • User profile
        • Anti-cheat Methods
      • Push Notifications
        • IOS
        • Android
        • Windows 8.1 and Windows 10
        • Unity
        • Abode Air
        • UE4
  • 3rd Party Sources
    • Attribution Trackers
      • AppsFlyer
      • Adjust
      • Branch.io
      • Kochava
      • Tenjin
      • Tune (MAT)
      • Singular
      • Custom postback API
      • Facebook Ads referral decryption
    • App Marketplace Data
      • App Store Connect Stats
      • App Store Subscriptions
      • Google Play Console Stats
      • Google Play Subscriptions
      • AppGallery Connect Stats
    • Ad revenue
      • AdColony
      • AdMob
      • Facebook
      • MoPub
      • Unity Ads
      • Vungle
      • Ad revenue API
    • Cohort export
  • Reports and Functionality
    • Space-related Reports and Functionality
      • Overview
      • Custom dashboards & Reports
      • SQL
        • SQL tips
        • SQL Query examples
      • Audience overlap
    • Project-related Reports and Functionality
      • Overview
        • Real-Time Dashboard
        • Acquisition reports
        • Engagement reports
        • Monetization reports
        • In-game analysis reports
        • Cohort analysis
      • Reports
      • Push Notifications
        • Android Notifications
        • IOS Notifications
        • Windows Notifications
        • Button Templates
      • Predictions
      • Users & Segments
      • Filters
      • A/B Testing
      • Tuning
      • Settings
  • Metrics and Glossary
    • Ad networks metrics
    • Market Metrics
    • Prediction Metrics
    • SDK Metrics
    • Subscription metrics
  • Space Management
  • User Profile Management
  • Limits
  • Scenarios and Best Practices
    • Analytics use cases
    • Match-3
    • MMORPG Games
    • Hyper-Casual games
    • Social Casino
    • RPG games
    • Farming games
    • Non-gaming app
  • FAQ
    • Identification
    • Raw Data
    • All about data discrepancies
  • Slack
Powered by GitBook
On this page
  • SDK Initialization
  • Specific integration features of certain platforms
  • Windows Standalone
  • Android
  • iOS

Was this helpful?

Export as PDF
  1. On the go
  2. Integration of SDK v2.0+
  3. SDK Integration

Unity

Last updated 3 years ago

Was this helpful?

SDK Initialization

This SDK version does not support WebGL. WebGL support will be added in the next releases.

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:

1.

Attention! When importing to Unity 2020, you may face the following error:

Assembly 'Assets/Plugins/DevToDev/Analytics/Windows/AnalyticsWindowsEditor.dll' will not be loaded due to errors: AnalyticsWindowsEditor references strong named Newtonsoft.Json Assembly references: 13.0.0.0 Found in project: 12.0.0.0. Assembly Version Validation can be disabled in Player Settings "Assembly Version Validation"

The error might occur due to the conflict between our package’s NewtonsoftJson dependency version and the one used in the VersionControl package. There are two ways to resolve this issue:

A. If you don’t use the VersionControl package, remove it from the package list. Choose Window->Package Manager in the Unity window:

In the window that appears, choose Packages: In Project from a drop-down list at the top. After that, select Version Control from the package list and click Remove. B. If you use Unity’s Version Control, you need to replace the newtonsoft.Json package. Open the directory of your main project (the one you want to integrate analytics with) MainProject\Library\PackageCache\ and move the com.unity.nuget.newtonsoft-json folder to the MainProject\Packages\ folder. It should look something like this:

2. 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 or use it only for error handling DTDLogLevel.Error 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.Debug,
    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.

Android

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

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.

If you want to disable tracking of advertising identifiers, you need to open the DTDPostProcesssAnalytics.cs file and comment out the line 39.

Add the following strings to proguard.txt ():

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

read more about Unity proguard here
the detailed instruction
Import the DTDAnalytics.unitypackage from GitHub repository.