Unity SDK - Methods Reference
This document provides a comprehensive reference for all methods available in the Singular SDK for Unity applications. The Singular Unity SDK wraps the native iOS and Android SDKs, providing a unified C# interface for mobile attribution, deep linking, revenue tracking, and analytics. Each method is presented with a description, signature, and practical usage examples.
AdRevenue
SingularSDK.AdRevenue Method
Tracks ad revenue from mediation platforms. This method allows you to report revenue generated from ad impressions in your Unity application, supporting attribution and ROI analysis for ad monetization.
Signature
public static void AdRevenue(string currency, double amount)
Usage Example
// Track ad revenue from an ad impression
SingularSDK.AdRevenue("USD", 0.05);
ClearGlobalProperties
SingularSDK.ClearGlobalProperties Method
Removes all global properties that were previously set. Global properties are key-value pairs that are automatically included with every event tracked by the SDK.
Signature
public static void ClearGlobalProperties()
Usage Example
// Clear all global properties
SingularSDK.ClearGlobalProperties();
createReferrerShortLink
SingularSDK.createReferrerShortLink Method
Creates a referrer short link for user-to-user attribution campaigns. This method generates a short link that can be shared by users to track referrals and attribute new installs to specific referrers.
Signature
public static void createReferrerShortLink(string baseLink, string referrerName,
string referrerId, Dictionary<string, string> passthroughParams,
ShortLinkCallback completionHandler)
Usage Example
// Create a referrer short link
var passthroughParams = new Dictionary<string, string>
{
{ "promo_code", "WELCOME10" },
{ "campaign", "spring_2024" }
};
SingularSDK.createReferrerShortLink(
"https://yourapp.sng.link/12345",
"John Doe",
"user_12345",
passthroughParams,
(data, error) =>
{
if (error == null)
{
Debug.Log("Short link created: " + data);
}
else
{
Debug.LogError("Error creating short link: " + error);
}
}
);
CustomRevenue
SingularSDK.CustomRevenue Method
Tracks a custom revenue event with a specified event name. This allows you to track revenue from sources other than in-app purchases, such as subscriptions or other monetization methods.
Signature
public static void CustomRevenue(string eventName, string currency, double amount)
public static void CustomRevenue(Dictionary<string, object> args,
string eventName, string currency, double amount)
Usage Example
// Track custom revenue event
SingularSDK.CustomRevenue("subscription_renewal", "USD", 9.99);
// Track custom revenue with additional attributes
var attributes = new Dictionary<string, object>
{
{ "subscription_type", "premium" },
{ "billing_period", "monthly" }
};
SingularSDK.CustomRevenue(attributes, "subscription_renewal", "USD", 9.99);
EndSingularSession
SingularSDK.EndSingularSession Method
Manually ends the current Singular session. This is typically called when the app goes to the background if you need explicit control over session management.
Signature
public static void EndSingularSession()
Usage Example
// End the current session
SingularSDK.EndSingularSession();
Event
SingularSDK.Event Method
Tracks a custom event in your Unity application. Events can be tracked with just a name, or with additional attributes as key-value pairs for more detailed analytics.
Signature
public static void Event(string name)
public static void Event(Dictionary<string, object> args, string name)
public static void Event(string name, params object[] args)
Usage Example
// Track a simple event
SingularSDK.Event("level_completed");
// Track event with dictionary attributes
var attributes = new Dictionary<string, object>
{
{ "level", 5 },
{ "score", 1250 },
{ "time_seconds", 45.3 }
};
SingularSDK.Event(attributes, "level_completed");
// Track event with params array (key-value pairs)
SingularSDK.Event("item_purchased",
"item_name", "Golden Sword",
"item_category", "weapons",
"price", 4.99);
GetAPID
SingularSDK.GetAPID Method
Returns the Singular APID (Attribution Platform ID) for the current device. This identifier is used internally by Singular for attribution and analytics. iOS only.
Signature
public static string GetAPID()
Usage Example
// Get the APID
string apid = SingularSDK.GetAPID();
Debug.Log("APID: " + apid);
GetGlobalProperties
SingularSDK.GetGlobalProperties Method
Retrieves all currently set global properties as a JSON string. Global properties are key-value pairs that are automatically included with every tracked event.
Signature
public static string GetGlobalProperties()
Usage Example
// Get all global properties
string globalProps = SingularSDK.GetGlobalProperties();
Debug.Log("Global Properties: " + globalProps);
GetIDFA
SingularSDK.GetIDFA Method
Returns the IDFA (Identifier for Advertisers) for the current iOS device. This method requires proper ATT (App Tracking Transparency) authorization. iOS only.
Signature
public static string GetIDFA()
Usage Example
// Get the IDFA (iOS only)
string idfa = SingularSDK.GetIDFA();
Debug.Log("IDFA: " + idfa);
GetLimitDataSharing
SingularSDK.GetLimitDataSharing Method
Returns the current data sharing limitation status. This indicates whether the SDK is currently limiting data collection and sharing based on privacy settings.
Signature
public static bool GetLimitDataSharing()
Usage Example
// Check if data sharing is limited
bool isLimited = SingularSDK.GetLimitDataSharing();
Debug.Log("Data sharing limited: " + isLimited);
HandlePushNotification
SingularSDK.HandlePushNotification Method
Processes push notification payloads for attribution and deep link handling. This method should be called when your app receives a push notification. iOS only.
Signature
public static void HandlePushNotification(Dictionary<string, string> pushNotificationPayload)
Usage Example
// Handle push notification (iOS only)
var pushPayload = new Dictionary<string, string>
{
{ "aps", "{"alert":"New message"}" },
{ "deep_link", "myapp://promo/spring2024" }
};
SingularSDK.HandlePushNotification(pushPayload);
InAppPurchase
SingularSDK.InAppPurchase Method
Tracks in-app purchases from Unity IAP. This method supports both Unity IAP 4.x and 5.x and automatically validates purchase receipts with Apple and Google.
Signature
public static void InAppPurchase(Product product, Dictionary<string, object> attributes)
Usage Example
// Track in-app purchase
void OnPurchaseComplete(Product product)
{
var attributes = new Dictionary<string, object>
{
{ "category", "consumables" },
{ "location", "main_store" }
};
SingularSDK.InAppPurchase(product, attributes);
}
InitializeSingularSDK
SingularSDK.InitializeSingularSDK Method
Manually initializes the Singular SDK. This method should only be called if you have set InitializeOnAwake to false in the SDK configuration. Otherwise, the SDK initializes automatically.
Signature
public static void InitializeSingularSDK()
Usage Example
// Manually initialize the SDK (only if InitializeOnAwake = false)
SingularSDK.InitializeSingularSDK();
IsAllTrackingStopped
SingularSDK.IsAllTrackingStopped Method
Returns whether all tracking has been stopped. When tracking is stopped, the SDK will not send any events or collect any data.
Signature
public static bool IsAllTrackingStopped()
Usage Example
// Check if tracking is stopped
bool isTrackingStopped = SingularSDK.IsAllTrackingStopped();
Debug.Log("Tracking stopped: " + isTrackingStopped);
LimitDataSharing
SingularSDK.LimitDataSharing Method
Sets whether the SDK should limit data sharing. When enabled, the SDK will restrict certain data collection and sharing activities to comply with privacy regulations.
Signature
public static void LimitDataSharing(bool limitDataSharingValue)
Usage Example
// Enable limited data sharing based on user consent
SingularSDK.LimitDataSharing(true);
RegisterDeviceTokenForUninstall
SingularSDK.RegisterDeviceTokenForUninstall Method
Registers the device token for uninstall tracking. This enables Singular to detect when users uninstall your app. iOS only.
Signature
public static void RegisterDeviceTokenForUninstall(string APNSToken)
Usage Example
// Register APNS token for uninstall tracking (iOS only)
void OnTokenReceived(string token)
{
SingularSDK.RegisterDeviceTokenForUninstall(token);
}
RestartSingularSession
SingularSDK.RestartSingularSession Method
Manually restarts the Singular session. This is typically called when the app returns to the foreground if you need explicit control over session management.
Signature
public static void RestartSingularSession(string key, string secret)
Usage Example
// Restart the session
SingularSDK.RestartSingularSession("YOUR_API_KEY", "YOUR_SECRET");
ResumeAllTracking
SingularSDK.ResumeAllTracking Method
Resumes all tracking after it was previously stopped. This re-enables event tracking and data collection.
Signature
public static void ResumeAllTracking()
Usage Example
// Resume tracking
SingularSDK.ResumeAllTracking();
Revenue
SingularSDK.Revenue Method
Tracks a revenue event. This is the primary method for tracking purchases and other monetization events that are not automatically tracked through Unity IAP.
Signature
public static void Revenue(string currency, double amount)
public static void Revenue(Dictionary<string, object> args,
string currency, double amount)
Usage Example
// Track simple revenue
SingularSDK.Revenue("USD", 9.99);
// Track revenue with attributes
var attributes = new Dictionary<string, object>
{
{ "product_id", "premium_upgrade" },
{ "product_name", "Premium Subscription" },
{ "product_category", "subscriptions" }
};
SingularSDK.Revenue(attributes, "USD", 9.99);
SetAge
SingularSDK.SetAge Method
Sets the user's age for demographic tracking. The age must be between 0 and 100. iOS only.
Signature
public static void SetAge(int age)
Usage Example
// Set user age (iOS only)
SingularSDK.SetAge(28);
SetConversionValueUpdatedHandler
SingularSDK.SetConversionValueUpdatedHandler Method
Sets a callback handler for SKAdNetwork conversion value updates (iOS 14+). This handler is called whenever the conversion value is updated. iOS only.
Signature
public static void SetConversionValueUpdatedHandler(SingularConversionValueUpdatedHandler handler)
Usage Example
// Set conversion value updated handler (iOS only)
SingularSDK.SetConversionValueUpdatedHandler((conversionValue) =>
{
Debug.Log("Conversion value updated: " + conversionValue);
});
SetConversionValuesUpdatedHandler
SingularSDK.SetConversionValuesUpdatedHandler Method
Sets a callback handler for SKAdNetwork 4.0+ conversion values updates. This handler provides conversion value, coarse conversion value, and lock status. iOS only.
Signature
public static void SetConversionValuesUpdatedHandler(SingularConversionValuesUpdatedHandler handler)
Usage Example
// Set conversion values updated handler (iOS only)
SingularSDK.SetConversionValuesUpdatedHandler((conversionValue, coarse, lockWindow) =>
{
Debug.Log($"CV: {conversionValue}, Coarse: {coarse}, Lock: {lockWindow}");
});
SetCustomUserId
SingularSDK.SetCustomUserId Method
Sets a custom user ID to associate with all tracked events. This allows you to tie Singular data to your own user identification system.
Signature
public static void SetCustomUserId(string customUserId)
Usage Example
// Set custom user ID
SingularSDK.SetCustomUserId("user_123456");
SetDeviceCustomUserId
SingularSDK.SetDeviceCustomUserId Method
This method is depricated and no longer used.
Signature
public static void SetDeviceCustomUserId(string customUserId)
Usage Example
// Set device-level custom user ID
SingularSDK.SetDeviceCustomUserId("device_user_789");
SetFCMDeviceToken
SingularSDK.SetFCMDeviceToken Method
Sets the FCM (Firebase Cloud Messaging) device token for push notification tracking and uninstall detection. Android only.
Signature
public static void SetFCMDeviceToken(string fcmDeviceToken)
Usage Example
// Set FCM token (Android only)
void OnFCMTokenReceived(string token)
{
SingularSDK.SetFCMDeviceToken(token);
}
SetGender
SingularSDK.SetGender Method
Sets the user's gender for demographic tracking. Accepts "m" for male or "f" for female. iOS only.
Signature
public static void SetGender(string gender)
Usage Example
// Set user gender (iOS only)
SingularSDK.SetGender("f");
SetGlobalProperty
SingularSDK.SetGlobalProperty Method
Sets a global property that will be sent with all events. Global properties are key-value pairs that persist across multiple events until cleared or changed.
Signature
public static bool SetGlobalProperty(string key, string value, bool overrideExisting)
Usage Example
// Set a global property
bool success = SingularSDK.SetGlobalProperty("user_level", "premium", true);
// Set multiple global properties
SingularSDK.SetGlobalProperty("app_version", "2.1.0", true);
SingularSDK.SetGlobalProperty("platform", "unity", true);
SetIMEI
SingularSDK.SetIMEI Method
Sets the device IMEI for tracking. This is useful in regions where IMEI tracking is allowed and preferred. Android only.
Signature
public static void SetIMEI(string imei)
Usage Example
// Set device IMEI (Android only)
SingularSDK.SetIMEI("123456789012345");
SetLimitAdvertisingIdentifiers
SingularSDK.SetLimitAdvertisingIdentifiers Method
Enables limited advertising identifiers mode. This affects how the SDK collects and uses device identifiers for tracking, suitable for mixed-audience apps.
Signature
public static void SetLimitAdvertisingIdentifiers(bool isEnabled)
Usage Example
// Enable limited advertising identifiers mode
SingularSDK.SetLimitAdvertisingIdentifiers(true);
SetSingularDeviceAttributionCallbackHandler
SingularSDK.SetSingularDeviceAttributionCallbackHandler Method
Sets a callback handler to receive device attribution data. This handler is invoked when attribution data becomes available, allowing you to access campaign and source information.
-
Create a C# Script
AttributionCallbackwith the Handler code below -
Create an Emtpy Object in the Hierarchy and place it below the SingularSDKObject
-
Add a Script Component to the Empty Object associating the
AttributionCallbackHandler Script
Signature
public static void SetSingularDeviceAttributionCallbackHandler(
SingularDeviceAttributionCallbackHandler handler)
Usage Example
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Singular;
public class AttributionCallback : MonoBehaviour, SingularDeviceAttributionCallbackHandler
{
void Awake()
{
Debug.Log("Registering SingularDeviceAttributionCallbackHandler");
SingularSDK.SetSingularDeviceAttributionCallbackHandler(this);
}
public void OnSingularDeviceAttributionCallback(Dictionary attributionInfo) {
foreach(var kvp in attributionInfo)
{
Debug.Log($"OnSingularDeviceAttributionCallback Key: {kvp.Key}, Value: {kvp.Value}");
}
}
}
SetSingularLinkHandler
SingularSDK.SetSingularLinkHandler Method
Sets a callback handler for Singular Links (deep links). This handler is invoked when a deep link is resolved, providing link parameters and passthrough data.
-
Create a C# Script
DeepLinkManagerwith the Handler code below -
Create an Emtpy Object in the Hierarchy and place it below the SingularSDKObject
-
Add a Script Component to the Empty Object associating the
DeepLinkManagerHandler Script
Signature
public static void SetSingularLinkHandler(SingularLinkHandler linkHandler)
Usage Example
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Singular;
public class DeepLinkManager : MonoBehaviour, SingularLinkHandler
{
void Awake()
{
Debug.Log("Registering SingularLink Handler");
SingularSDK.SetSingularLinkHandler(this);
}
public void OnSingularLinkResolved(SingularLinkParams linkParams)
{
Debug.Log("SingularLink Resolved");
// Extract parameters from the tracking link
string deeplink = linkParams.Deeplink;
string passthrough = linkParams.Passthrough;
bool isDeferred = linkParams.IsDeferred;
// Log the parameters
Debug.Log($"SingularLink Deeplink: {deeplink ?? "null"}");
Debug.Log($"SingularLink Passthrough: {passthrough ?? "null"}");
Debug.Log($"SingularLink is Deferred: {isDeferred}");
// Handle deep link routing
if (!string.IsNullOrEmpty(deeplink))
{
HandleDeepLink(deeplink, isDeferred);
}
}
private void HandleDeepLink(string url, bool isDeferred)
{
// Your deep link routing logic here
Debug.Log($"SingularLink Routing to: {url} (Deferred: {isDeferred})");
// Example: Parse the URL and navigate to the appropriate screen
// if (url.Contains("product"))
// {
// NavigateToProduct(url);
// }
}
}
SetSingularSdidAccessorHandler
SingularSDK.SetSingularSdidAccessorHandler Method
Sets a callback handler to receive the Singular Device ID (SDID). This handler is invoked when the SDID becomes available after SDK initialization.
-
Create a C# Script
SDIDManagerwith the Handler code below -
Create an Emtpy Object in the Hierarchy and place it below the SingularSDKObject
-
Add a Script Component to the Empty Object associating the
SDIDManagerHandler Script
Signature
public static void SetSingularSdidAccessorHandler(SingularSdidAccessorHandler handler)
Usage Example
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Singular;
public class SDIDManager : MonoBehaviour, SingularSdidAccessorHandler
{
void Awake()
{
Debug.Log("Registering SingularSdidAccessorHandler");
SingularSDK.SetSingularSdidAccessorHandler(this);
}
public void DidSetSdid(string sdid)
{
Debug.Log($"SDID Set: {sdid}");
}
public void SdidReceived(string sdid)
{
Debug.Log($"SDID Set: {sdid}");
// Store or use the SDID as needed
}
}
SkanRegisterAppForAdNetworkAttribution
SingularSDK.SkanRegisterAppForAdNetworkAttribution Method
Registers the app for SKAdNetwork attribution. This method should be called early in the app lifecycle for iOS 14.5+ SKAdNetwork support. iOS only.
Signature
public static void SkanRegisterAppForAdNetworkAttribution()
Usage Example
// Register for SKAdNetwork attribution (iOS only)
SingularSDK.SkanRegisterAppForAdNetworkAttribution();
SkanUpdateConversionValue
SingularSDK.SkanUpdateConversionValue Method
Manually updates the SKAdNetwork conversion value. This method is used when manual conversion value management is enabled. iOS only.
Signature
public static bool SkanUpdateConversionValue(int conversionValue)
public static bool SkanUpdateConversionValue(int conversionValue, int coarse, bool lockWindow)
Usage Example
// Update conversion value (iOS only)
bool success = SingularSDK.SkanUpdateConversionValue(5);
// Update with coarse value and lock (SKAdNetwork 4.0+)
bool success2 = SingularSDK.SkanUpdateConversionValue(10, 2, false);
StopAllTracking
SingularSDK.StopAllTracking Method
Stops all tracking and data collection. When tracking is stopped, the SDK will not send any events or collect any data until tracking is resumed.
Signature
public static void StopAllTracking()
Usage Example
// Stop all tracking
SingularSDK.StopAllTracking();
TrackingOptIn
SingularSDK.TrackingOptIn Method
Indicates that the user has opted in to tracking. This method should be called when the user explicitly consents to data collection and tracking.
Signature
public static void TrackingOptIn()
Usage Example
// User opted in to tracking
SingularSDK.TrackingOptIn();
TrackingUnder13
SingularSDK.TrackingUnder13 Method
Indicates that the user is under 13 years old, which affects data collection to comply with COPPA (Children's Online Privacy Protection Act) regulations.
Signature
public static void TrackingUnder13()
Usage Example
// User is under 13 years old
SingularSDK.TrackingUnder13();
UnsetCustomUserId
SingularSDK.UnsetCustomUserId Method
Removes the previously set custom user ID. After calling this method, events will no longer be associated with a custom user ID until a new one is set.
Signature
public static void UnsetCustomUserId()
Usage Example
// Remove custom user ID (e.g., on logout)
SingularSDK.UnsetCustomUserId();
UnsetGlobalProperty
SingularSDK.UnsetGlobalProperty Method
Removes a specific global property by key. This stops the property from being sent with subsequent events.
Signature
public static void UnsetGlobalProperty(string key)
Usage Example
// Remove a specific global property
SingularSDK.UnsetGlobalProperty("user_level");