Unity SDK - Basic Integration

Prerequisites

Complete these prerequisite steps before installing the Singular Unity SDK to ensure a smooth integration process.

Required Prerequisites:


Installation

Installing via Unity Package Manager (UPM)

The Singular Unity SDK is installed through Unity Package Manager using Git URLs. Follow these steps to add the SDK to your project.

Installation Steps

  1. Open Package Manager: In Unity, navigate to Window > Package Manager.
  2. Add package from Git: Click the [+] button in the top-left corner and select "Add package from git URL".
  3. Enter the Git URL:
    • For Standard SDK: Enter https://github.com/singular-labs/Singular-Unity-SDK.git
    • For Kids SDK: Enter https://github.com/singular-labs/Singular-Unity-SDK.git#kids
  4. Complete installation: Click "Add" to install the SDK package.

Not Using Google EDM4U? If your project doesn't use the External Dependency Manager, you must manually download and add native dependencies.

Manual Dependency Installation

  1. Download dependencies: Download the appropriate Plugins.zip file from Singular's S3 bucket:
  2. Extract to Assets: Extract the downloaded files and move them to Assets > Plugins in your Unity project.
  3. Configure iOS framework: Navigate to Assets > Plugins > iOS and select Singular.xcframework.
  4. Embed binary: In the Inspector pane, check the option "Add to Embedded Binaries".

Android Configuration Tips

Configure your Android build settings to ensure proper SDK functionality. Unity provides multiple ways to customize Android manifests and Gradle files.

How to Update AndroidManifest.xml
#

You can modify the AndroidManifest using one of two methods:

Method 1: Unity Custom Manifest

  1. Navigate to File > Build Settings > Player Settings > Publishing Settings.
  2. Enable "Custom Main Manifest" under the Publishing Settings section.
  3. Unity generates a default AndroidManifest.xml file at Assets/Plugins/Android/AndroidManifest.xml.
  4. Edit this file to add required permissions and configurations.

Source: Unity Android Manifest Documentation

Method 2: Android Studio

  1. Export your project from Unity using File > Build Settings > Export Project.
  2. Open the exported project in Android Studio.
  3. Edit the AndroidManifest.xml file directly in Android Studio.
How to Update Gradle Build Files
#

Method 1: Unity Custom Template

  1. Navigate to File > Build Settings > Player Settings > Publishing Settings.
  2. Enable "Custom Gradle Template" under the Publishing Settings section.
  3. Unity generates a mainTemplate.gradle file at Assets/Plugins/Android/mainTemplate.gradle.
  4. Add your custom Gradle configurations to this file.

Source: Unity Gradle Overview Documentation

Method 2: Android Studio

  1. Export your project from Unity.
  2. Open the project in Android Studio.
  3. Edit the app's build.gradle file directly.
Resolving Duplicate Class Errors
#

When building Android apps in Unity, you may encounter "Duplicate class" errors caused by multiple SDKs including the same transitive dependencies. This commonly occurs with the Android Vending Licensing library when using both AppLovin SDK and Singular SDK.

Example Error:

Duplicate class com.android.vending.licensing.ILicensingService found in modules 
applovin-sdk-13.5.0.aar -> jetified-applovin-sdk-13.5.0-runtime (com.applovin:applovin-sdk:13.5.0) 
and singular_sdk-12.10.0.aar -> jetified-singular_sdk-12.10.0-runtime (com.singular.sdk:singular_sdk:12.10.0)

Solution 1: Using External Dependency Manager (EDM4U)

If your project uses External Dependency Manager for Unity (recommended), add exclusion rules to your Dependencies XML file.

  1. Locate your *Dependencies.xml file in your Unity project (typically in Assets/Editor or a similar location).
  2. Add an exclusion rule to one of the SDK dependencies:
XML
<dependencies>
  <androidPackages>
    <androidPackage spec="com.applovin:applovin-sdk:13.5.0">
      <androidSdkPackageIds>
        <exclude group="com.android.vending" module="licensing"/>
      </androidSdkPackageIds>
    </androidPackage>
    <androidPackage spec="com.singular.sdk:singular_sdk:12.10.0" />
  </androidPackages>
</dependencies>

Note: This approach is more persistent than modifying Gradle templates, as Android Resolver may overwrite custom template changes during resolution.

Solution 2: Using Custom Gradle Templates

If you're not using EDM4U, apply exclusion rules directly in your Gradle configuration files.

  1. Navigate to File > Build Settings > Player Settings > Publishing Settings.
  2. Enable "Custom Main Gradle Template" or "Custom Launcher Gradle Template".
  3. Open Assets/Plugins/Android/mainTemplate.gradle (or launcherTemplate.gradle).
  4. Add the exclusion rule to your dependencies block:
Gradle
dependencies {
    implementation('com.applovin:applovin-sdk:13.5.0') {
        exclude group: 'com.android.vending', module: 'licensing'
    }
    implementation 'com.singular.sdk:singular_sdk:12.10.0'
}

Alternative: Apply a global exclusion by adding this after your dependencies block:

Gradle
configurations.all {
    exclude group: 'com.android.vending', module: 'licensing'
}

Verify Resolution

  1. After applying the exclusion, clean your project by deleting Library/Bee and Temp folders.
  2. Rebuild your Android project in Unity.
  3. Verify the duplicate class error no longer appears in the build output.

Why This Works: Both SDKs bundle the same Android licensing library as a transitive dependency. The exclusion tells Gradle to use only one copy, resolving the conflict.

ProGuard Configuration
#

If your project uses ProGuard for code obfuscation, add the following keep rules to your proguard-unity.txt file to prevent the Singular SDK from being stripped:

proguard-unity.txt
-keep class com.singular.sdk.** { *; }
-keep public class com.android.installreferrer.** { *; }
-keep public class com.singular.unitybridge.** { *; }

iOS Configuration Tips

Configure iOS-specific settings to enable proper attribution, deep linking, and testing functionality.

Update CocoaPods Dependencies
#

After building your Unity project for iOS and before building in Xcode, update your CocoaPods dependencies to ensure you have the latest SDK versions.

Terminal
cd /path/to/your/ios/project
pod repo update
pod update
Log IDFV for Testing
#

For testing your integration, log the IDFV (Identifier for Vendor) to quickly add your test device in the Singular SDK Console.

Add IDFV Logging

  1. Open your Xcode project after building from Unity.
  2. Navigate to Classes > UnityAppController.mm.
  3. Find the applicationDidBecomeActive method.
  4. Add the following code to log the IDFV:
Objective-C
// Log IDFV for testing
NSLog(@"Singular === IDFV: %@", [[[UIDevice currentDevice] identifierForVendor] UUIDString]);
  1. Build and run your app in Xcode.
  2. Check the Xcode console logs for the IDFV output.
  3. Copy the IDFV and add it as a test device in the Singular SDK Console.
Configure Deep Link Support
#

Enable Universal Links for deep linking by configuring Associated Domains in your Xcode project.

  1. Add Associated Domain: In Xcode, navigate to your app target's Signing & Capabilities tab.
  2. Enable capability: Click [+] Capability and add "Associated Domains".
  3. Add domain: Add your Singular tracking domain in the format: applinks:yourdomain.sng.link
  4. Configure Team ID: In the Singular dashboard, navigate to your app's settings and add your Apple Team ID. This allows Singular to generate and host the Apple App Site Association (AASA) file required for Universal Links.

Important: Without properly configured Associated Domains and Team ID, Universal Links will not work and users won't be able to open your app from Singular tracking links.


Integrate the SDK

Create the SingularSDK GameObject

The Singular SDK requires a GameObject in your Unity scene hierarchy to function. You can add this GameObject using either the provided prefab or by creating it manually.

Method 1: Use the Singular Prefab (Recommended)
#

Add Prefab to Scene

  1. In the Project pane, navigate to Packages > Singular > SingularSDK > Prefabs.
  2. Drag the SingularSDKObject prefab into your Hierarchy pane.
  3. The prefab is now ready to configure in the Inspector.
Method 2: Create GameObject Manually
#

Manual GameObject Creation

  1. In the Hierarchy pane, right-click and select Create Empty.
  2. Name the GameObject SingularSDKObject (exact name required).
  3. With the GameObject selected, navigate to the Inspector pane.
  4. Click Add Component.
  5. Search for "Singular" and select the Singular SDK script component.

Critical: The GameObject must be named exactly SingularSDKObject for the SDK to function properly.

Configure SDK Settings

Configure your SDK credentials and initialization settings through the Unity Inspector. Your API Key and Secret are required for the SDK to communicate with Singular's servers.

Add API Credentials

  1. Select SingularSDKObject: Click on the SingularSDKObject in your Hierarchy.
  2. Locate credentials: Log into your Singular account and navigate to Developer Tools > SDK Integration > SDK Keys.
  3. Copy keys: Copy your SDK Key and SDK Secret.
  4. Paste in Inspector: In Unity's Inspector pane, paste the credentials into the Singular API Key and Singular API Secret fields.

Critical: Do NOT use the Singular Reporting API Key. Only use the SDK-specific API Key and Secret from the SDK Integration page. Using the wrong credentials will prevent data from being sent to Singular.

Verify Your Integration: After configuration, test your implementation using the Singular SDK Console to ensure events are being tracked correctly.

Default Inspector Settings

The SingularSDKObject comes with sensible defaults. Understanding these settings helps you customize the SDK behavior for your app's requirements.

Default Configuration Options
#
  • Initialize On Awake: Enabled by default. The SDK initializes automatically when the GameObject awakens. Disable this if you need to delay initialization for privacy consent or other requirements.
  • SKAN Enabled: Enabled by default (iOS only). Enables SKAdNetwork attribution in Managed Mode, where Singular automatically updates conversion values based on your configured conversion model.
  • Wait For Tracking Authorization: Set to 0 (disabled). If your app shows the iOS App Tracking Transparency (ATT) prompt, set this to 300 seconds. This delays the SDK session until the user responds to the ATT prompt, ensuring the IDFA can be captured if consent is granted. Leave at 0 if not using ATT.
  • Enable Logging: Enabled by default. Outputs SDK debug logs to help with integration and troubleshooting. Should be disabled in production builds. Works with the Log Level setting (see below).
  • Log Level: Set to 3 (Info) by default. Controls logging verbosity. Lower numbers produce more verbose logs:
    C#
    // Based on Android Logger log levels
    public enum LogLevel {
       Verbose = 2,  // Most verbose
       Debug   = 3,
       Info    = 4,  // Default
       Warn    = 5,
       Error   = 6,
       Assert  = 7   // Least verbose
    }

    Note: Detailed logs are primarily available on Android.

  • DDL Timeout Sec: Set to 0 (uses 60-second default). Determines how long the SDK waits for deferred deep link data from the server. The server stops searching after this timeout if no deferred deep link is found.
  • Session Timeout Sec: Set to 0 (uses 60-second default). Defines how long the app can be backgrounded before the SDK creates a new session upon returning to the foreground.
  • Shortlink Resolve Timeout: Set to 0 (uses 10-second default). Maximum time to wait for short link resolution. Protects user experience by preventing long waits if a short link can't be resolved.

Additional Configuration Options

Facebook (Meta) Install Referrer Configuration
#

As of June 18th, 2025: Meta's Advanced Mobile Measurement (AMM) removes the need for implementing Meta Install Referrer. If AMM reporting is enabled, you do not need to configure Meta Install Referrer.

If you need to support the legacy Meta Install Referrer attribution method, add your Facebook App ID to the SingularSDKObject configuration.

Configuration Steps

  1. Select the SingularSDKObject in your scene hierarchy.
  2. In the Inspector pane, locate the "Facebook App ID" field.
  3. Enter your Facebook App ID (find this in your Facebook Developer Console).

Additional Resources:


Initialize the SDK

Privacy Compliance: When implementing the Singular SDK, comply with privacy laws in your operating regions, including GDPR, CCPA, COPPA, and others. For guidance, see SDK Opt-In and Opt-Out Practices.

Initialize the Singular SDK every time your app launches. SDK initialization is essential for all Singular attribution functionality and creates a new session for calculating user retention metrics.

Automatic Initialization

By default, the SingularSDK.cs script automatically initializes the SDK when your scene loads through Unity's Awake() method. No additional code is required if Initialize On Awake is enabled in the Inspector.

Manual Initialization

If you need to initialize the SDK at a specific time (for example, after obtaining user consent), disable automatic initialization and call the initialization method manually.

Manual Initialization Setup

  1. Select the SingularSDKObject in your scene hierarchy.
  2. In the Inspector pane, uncheck Initialize On Awake.
  3. Call SingularSDK.InitializeSingularSDK() in your code when ready to initialize.

InitializeSingularSDK Method

Use this method to manually initialize the SDK when automatic initialization is disabled.

C#
using UnityEngine;
using Singular;

public class GameInitializer : MonoBehaviour
{
    void Start()
    {
        // Perform any required setup (e.g., consent management)
        CheckUserConsent();

        // Initialize Singular SDK after consent is obtained
        // SDK Key and Secret are configured on the SingularSDKObject
        SingularSDK.InitializeSingularSDK();
    }

    void CheckUserConsent()
    {
        // Your consent logic here
    }
}

Thread Safety: Always call Singular Unity SDK methods from the same thread used for other Unity API calls. The SDK is not thread-safe across multiple threads.


Advanced Configuration

Configure Session Timeout

Customize how long your app can remain in the background before the SDK creates a new session when the app returns to the foreground.

Session Timeout Configuration

The default session timeout is 60 seconds. To change this value:

  1. Select the SingularSDKObject in your scene hierarchy.
  2. In the Inspector pane, locate the Session Timeout Sec field.
  3. Enter your desired timeout value in seconds (e.g., 120 for 2 minutes).
  4. Leave at 0 to use the default 60-second timeout.

Best Practice: Consider your app's typical usage patterns when setting session timeout. Games with frequent short sessions may benefit from a shorter timeout, while productivity apps may need longer timeouts.


Upgrading from .unitypackage to UPM

If you're migrating from the legacy .unitypackage installation method to the modern Unity Package Manager (UPM) approach, follow these critical upgrade steps.

Migration Instructions: .unitypackage to UPM
#

Critical: You must manually remove all existing Singular SDK files before installing the UPM package. Failure to do so will cause conflicts and build errors.

Upgrade Procedure

Complete these steps in order before installing the SDK via Unity Package Manager:

Step-by-Step File Removal
#

1. Remove Code Files

Navigate to your project's /Code folder (typically Assets/Singular/Code) and delete all Singular-related C# scripts.

2. Remove Android Dependencies

Navigate to /Plugins/Android and remove the following Singular files:

  • All .aar files with "singular" in the name
  • All .jar files with "singular" in the name
  • singular-sdk.aar
  • install-referrer-*.aar
  • singular-unitybridge.aar

3. Remove iOS Dependencies

Navigate to /Plugins/iOS and remove the following Singular files:

  • All .h header files (e.g., SingularSDK.h)
  • All .m implementation files (e.g., SingularUnityBridge.m)
  • Singular.xcframework folder

Important: Only remove Singular-specific files. Be careful not to delete other plugin files your project may depend on.

4. Verify Clean State

  1. After removing files, close Unity completely.
  2. Delete the Library folder in your project directory to force Unity to reimport assets.
  3. Reopen your Unity project.
  4. Wait for Unity to finish reimporting assets.
  5. Verify there are no compilation errors before proceeding with UPM installation.

5. Install UPM Package

Now you're ready to install the Singular SDK via Unity Package Manager. Follow the UPM installation instructions at the top of this guide.