Unity SDK - メソッドリファレンス
このドキュメントでは、Unityアプリケーション用のSingular SDKで利用可能なすべてのメソッドの包括的なリファレンスを提供します。Singular Unity SDKはiOSとAndroidのネイティブSDKをラップし、モバイルアトリビューション、ディープリンク、収益トラッキング、アナリティクスのための統一されたC#インターフェースを提供します。各メソッドについて、説明、署名、実際の使用例を示しています。
AdRevenue
SingularSDK.AdRevenueメソッド
メディエーションプラットフォームからの広告収入をトラッキングします。このメソッドを使用すると、Unityアプリケーションの広告インプレッションから生成された収益をレポートすることができ、広告収益化のためのアトリビューションとROI分析をサポートします。
シグネチャ
public static void AdRevenue(string currency, double amount)
使用例
// Track ad revenue from an ad impression
SingularSDK.AdRevenue("USD", 0.05);
ClearGlobalProperties
SingularSDK.ClearGlobalPropertiesメソッド
以前に設定されたすべてのグローバルプロパティを削除します。グローバルプロパティは、SDKによって追跡されるすべてのイベントに自動的に含まれるキーと値のペアです。
シグネチャ
public static void ClearGlobalProperties()
使用例
// Clear all global properties
SingularSDK.ClearGlobalProperties();
createReferrerShortLink
SingularSDK.createReferrerShortLinkメソッド
ユーザー間アトリビューション キャンペーン用のリファラー ショート リンクを作成します。 このメソッドは、リファラーを追跡し、新規インストールを特定のリファラーにアトリビュートするために、ユーザーが共有できるショート リンクを生成します。
シグネチャ
public static void createReferrerShortLink(string baseLink, string referrerName,
string referrerId, Dictionary<string, string> passthroughParams,
ShortLinkCallback completionHandler)
使用例
// 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 メソッド
指定されたイベント名でカスタム収益イベントを追跡します。これにより、サブスクリプションやその他の収益化方法など、アプリ内課金以外のソースからの収益を追跡できます。
シグネチャ
public static void CustomRevenue(string eventName, string currency, double amount)
public static void CustomRevenue(Dictionary<string, object> args,
string eventName, string currency, double amount)
使用例
// 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 メソッド
現在の Singular セッションを手動で終了します。セッション管理を明示的に制御する必要がある場合、これは通常アプリがバックグラウンドに移行するときに呼び出されます。
シグネチャ
public static void EndSingularSession()
使用例
// End the current session
SingularSDK.EndSingularSession();
イベント
SingularSDK.Event メソッド
Unityアプリケーションのカスタムイベントを追跡します。イベントは名前だけで追跡することも、より詳細な分析のためにキーと値のペアとして追加の属性で追跡することもできます。
シグネチャ
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)
使用例
// 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メソッド
現在のデバイスのSingular APID (Attribution Platform ID) を返します。 この識別子はSingular内部でアトリビューションとアナリティクスのために使用されます。
シグネチャ
public static string GetAPID()
使用例
// Get the APID
string apid = SingularSDK.GetAPID();
Debug.Log("APID: " + apid);
GetGlobalProperties
SingularSDK.GetGlobalPropertiesメソッド
現在設定されているすべてのグローバルプロパティをJSON文字列として取得します。グローバルプロパティは、追跡されるすべてのイベントに自動的に含まれるキーと値のペアです。
シグネチャ
public static string GetGlobalProperties()
使用例
// Get all global properties
string globalProps = SingularSDK.GetGlobalProperties();
Debug.Log("Global Properties: " + globalProps);
GetIDFA
SingularSDK.GetIDFAメソッド
現在のiOSデバイスのIDFA (Identifier for Advertisers)を返します。 このメソッドは、適切なATT (App Tracking Transparency)認可を必要とします。
シグネチャ
public static string GetIDFA()
使用例
// Get the IDFA (iOS only)
string idfa = SingularSDK.GetIDFA();
Debug.Log("IDFA: " + idfa);
GetLimitDataSharing
SingularSDK.GetLimitDataSharingメソッド
現在のデータ共有制限ステータスを返します。これは、SDKが現在プライバシー設定に基づいてデータの収集と共有を制限しているかどうかを示します。
シグネチャ
public static bool GetLimitDataSharing()
使用例
// Check if data sharing is limited
bool isLimited = SingularSDK.GetLimitDataSharing();
Debug.Log("Data sharing limited: " + isLimited);
HandlePushNotification
SingularSDK.HandlePushNotificationメソッド
アトリビューションとディープリンク処理のためにプッシュ通知のペイロードを処理します。 このメソッドは、アプリがプッシュ通知を受信したときに呼び出される必要があります。
シグネチャ
public static void HandlePushNotification(Dictionary<string, string> pushNotificationPayload)
使用例
// 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メソッド
Unity IAPからのアプリ内購入をトラッキングします。このメソッドはUnity IAP 4.xと5.xの両方をサポートし、AppleとGoogleで購入レシートを自動的に検証します。
シグネチャ
public static void InAppPurchase(Product product, Dictionary<string, object> attributes)
使用例
// Track in-app purchase
void OnPurchaseComplete(Product product)
{
var attributes = new Dictionary<string, object>
{
{ "category", "consumables" },
{ "location", "main_store" }
};
SingularSDK.InAppPurchase(product, attributes);
}
SingularSDKの初期化
SingularSDK.InitializeSingularSDKメソッド
Singular SDKを手動で初期化します。このメソッドは、SDKコンフィギュレーションでInitializeOnAwakeをfalseに設定している場合にのみ呼び出されます。そうでない場合、SDKは自動的に初期化されます。
シグネチャ
public static void InitializeSingularSDK()
使用例
// Manually initialize the SDK (only if InitializeOnAwake = false)
SingularSDK.InitializeSingularSDK();
IsAllTrackingStopped
SingularSDK.IsAllTrackingStoppedメソッド
すべてのトラッキングが停止されたかどうかを返します。トラッキングが停止されると、SDKはいかなるイベントも送信せず、いかなるデータも収集しません。
シグネチャ
public static bool IsAllTrackingStopped()
使用例
// Check if tracking is stopped
bool isTrackingStopped = SingularSDK.IsAllTrackingStopped();
Debug.Log("Tracking stopped: " + isTrackingStopped);
データ共有の制限
SingularSDK.LimitDataSharingメソッド
SDKがデータ共有を制限するかどうかを設定します。有効にすると、SDKはプライバシー規制を遵守するために特定のデータ収集と共有活動を制限します。
シグネチャ
public static void LimitDataSharing(bool limitDataSharingValue)
使用例
// Enable limited data sharing based on user consent
SingularSDK.LimitDataSharing(true);
RegisterDeviceTokenForUninstall (アンインストールのためのデバイストークンの登録)
SingularSDK.RegisterDeviceTokenForUninstall メソッド
アンインストール追跡用にデバイストークンを登録します。これにより、ユーザーがアプリをアンインストールしたときに Singular が検出できるようになります。
シグネチャ
public static void RegisterDeviceTokenForUninstall(string APNSToken)
使用例
// Register APNS token for uninstall tracking (iOS only)
void OnTokenReceived(string token)
{
SingularSDK.RegisterDeviceTokenForUninstall(token);
}
RestartSingularSession
SingularSDK.RestartSingularSession メソッド
Singularセッションを手動で再起動します。これは通常、セッション管理を明示的に制御する必要がある場合、アプリがフォアグラウンドに戻ったときに呼び出されます。
シグネチャ
public static void RestartSingularSession(string key, string secret)
使用例
// Restart the session
SingularSDK.RestartSingularSession("SDK KEY", "YOUR_SECRET");
ResumeAllTracking
SingularSDK.ResumeAllTracking メソッド
すべてのトラッキングを再開します。これにより、イベントトラッキングとデータ収集が再び有効になります。
シグネチャ
public static void ResumeAllTracking()
使用例
// Resume tracking
SingularSDK.ResumeAllTracking();
収益
SingularSDK.Revenue メソッド
収益イベントをトラッキングします。これは、Unity IAPを通じて自動的に追跡されない購入やその他の収益化イベントを追跡するための主要なメソッドです。
シグネチャ
public static void Revenue(string currency, double amount)
public static void Revenue(Dictionary<string, object> args,
string currency, double amount)
使用例
// 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);
年齢設定
SingularSDK.SetAgeメソッド
人口統計トラッキングのためにユーザーの年齢を設定します。年齢は 0 から 100 の間でなければなりません。
シグネチャ
public static void SetAge(int age)
使用例
// Set user age (iOS only)
SingularSDK.SetAge(28);
SetConversionValueUpdatedHandler
SingularSDK.SetConversionValueUpdatedHandler メソッド
SKAdNetworkのコンバージョン値更新のコールバックハンドラを設定します(iOS 14+)。このハンドラはコンバージョン値が更新されるたびに呼び出されます。
シグネチャ
public static void SetConversionValueUpdatedHandler(SingularConversionValueUpdatedHandler handler)
使用例
// Set conversion value updated handler (iOS only)
SingularSDK.SetConversionValueUpdatedHandler((conversionValue) =>
{
Debug.Log("Conversion value updated: " + conversionValue);
});
SetConversionValuesUpdatedHandler
SingularSDK.SetConversionValuesUpdatedHandler メソッド
SKAdNetwork 4.0+の変換値更新のコールバックハンドラを設定します。 このハンドラは変換値、粗変換値、ロックステータスを提供します。
シグネチャ
public static void SetConversionValuesUpdatedHandler(SingularConversionValuesUpdatedHandler handler)
使用例
// Set conversion values updated handler (iOS only)
SingularSDK.SetConversionValuesUpdatedHandler((conversionValue, coarse, lockWindow) =>
{
Debug.Log($"CV: {conversionValue}, Coarse: {coarse}, Lock: {lockWindow}");
});
SetCustomUserId
SingularSDK.SetCustomUserIdメソッド
すべての追跡イベントに関連付けるカスタムユーザー ID を設定します。これにより、Singular のデータを独自のユーザー識別システムに結びつけることができます。
シグネチャ
public static void SetCustomUserId(string customUserId)
使用例
// Set custom user ID
SingularSDK.SetCustomUserId("user_123456");
SetDeviceCustomUserId
SingularSDK.SetDeviceCustomUserId メソッド
デバイスレベルのカスタムユーザーIDを設定します。これは通常のカスタムユーザー ID とは異なり、デバイスレベルでアプリセッションをまたいで持続します。
シグネチャ
public static void SetDeviceCustomUserId(string customUserId)
使用例
// Set device-level custom user ID
SingularSDK.SetDeviceCustomUserId("device_user_789");
SetFCMDeviceToken
SingularSDK.SetFCMDeviceTokenメソッド
プッシュ通知のトラッキングとアンインストール検出のためのFCM(Firebase Cloud Messaging)デバイストークンを設定します。 Android のみ。
シグネチャ
public static void SetFCMDeviceToken(string fcmDeviceToken)
使用例
// Set FCM token (Android only)
void OnFCMTokenReceived(string token)
{
SingularSDK.SetFCMDeviceToken(token);
}
性別の設定
SingularSDK.SetGenderメソッド
人口統計トラッキングのためにユーザーの性別を設定します。男性の場合は "m"、女性の場合は "f" を受け付けます。
シグネチャ
public static void SetGender(string gender)
使用例
// Set user gender (iOS only)
SingularSDK.SetGender("f");
SetGlobalProperty
SingularSDK.SetGlobalPropertyメソッド
すべてのイベントで送信されるグローバルプロパティを設定します。グローバルプロパティは、クリアまたは変更されるまで、複数のイベントにわたって持続するキーと値のペアです。
シグネチャ
public static bool SetGlobalProperty(string key, string value, bool overrideExisting)
使用例
// 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 メソッド
トラッキング用のデバイスIMEIを設定します。これは、IMEI追跡が許可され、優先される地域で有用です。 Androidのみ。
シグネチャ
public static void SetIMEI(string imei)
使用例
// Set device IMEI (Android only)
SingularSDK.SetIMEI("123456789012345");
SetLimitAdvertisingIdentifiers
SingularSDK.SetLimitAdvertisingIdentifiersメソッド
限定広告識別子モードを有効にします。これは、SDKがトラッキングのためにデバイス識別子を収集し使用する方法に影響します。
シグネチャ
public static void SetLimitAdvertisingIdentifiers(bool isEnabled)
使用例
// Enable limited advertising identifiers mode
SingularSDK.SetLimitAdvertisingIdentifiers(true);
SetSingularDeviceAttributionCallbackHandler
SingularSDK.SetSingularDeviceAttributionCallbackHandler メソッド
デバイス属性データを受信するコールバックハンドラを設定します。このハンドラは、アトリビューションデータが利用可能になったときに呼び出され、キャンペーンとソース情報にアクセスできるようになります。
-
以下のハンドラ コードで C# スクリプト
AttributionCallbackを作成します。 -
階層に Emtpy オブジェクトを作成し、SingularSDKObject の下に配置します。
-
空のオブジェクトにスクリプトコンポーネントを追加し、
AttributionCallbackハンドラスクリプトを関連付けます。
署名
public static void SetSingularDeviceAttributionCallbackHandler(
SingularDeviceAttributionCallbackHandler handler)
使用例
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 メソッド
シンギュラーリンク(ディープリンク)のコールバックハンドラを設定します。このハンドラは、ディープリンクが解決されたときに呼び出され、リンクパラメータとパススルーデータを提供します。
-
以下のハンドラ コードで C# スクリプト
DeepLinkManagerを作成します。 -
階層に Emtpy オブジェクトを作成し、SingularSDKObject の下に配置します。
-
空のオブジェクトにスクリプトコンポーネントを追加し、
DeepLinkManagerハンドラスクリプトを関連付けます。
署名
public static void SetSingularLinkHandler(SingularLinkHandler linkHandler)
使用例
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 メソッド
Singular Device ID (SDID) を受け取るコールバックハンドラを設定します。このハンドラは、SDKの初期化後にSDIDが使用可能になったときに呼び出されます。
-
以下のハンドラコードで C# スクリプト
SDIDManagerを作成します。 -
階層に Emtpy オブジェクトを作成し、SingularSDKO オブジェクトの下に配置します。
-
Empty オブジェクトにスクリプトコンポーネントを追加し、
SDIDManagerハンドラスクリプトを関連付けます。
署名
public static void SetSingularSdidAccessorHandler(SingularSdidAccessorHandler handler)
使用例
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 メソッド
SKAdNetwork アトリビューション用にアプリを登録します。このメソッドは、iOS 14.5+ SKAdNetwork サポートのアプリライフサイクルの初期に呼び出す必要があります。
シグネチャ
public static void SkanRegisterAppForAdNetworkAttribution()
使用例
// Register for SKAdNetwork attribution (iOS only)
SingularSDK.SkanRegisterAppForAdNetworkAttribution();
SkanUpdateConversionValue
SingularSDK.SkanUpdateConversionValueメソッド
SKAdNetworkの変換値を手動で更新する。このメソッドは、変換値の手動管理が有効になっている場合に使用されます。
シグネチャ
public static bool SkanUpdateConversionValue(int conversionValue)
public static bool SkanUpdateConversionValue(int conversionValue, int coarse, bool lockWindow)
使用例
// 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メソッド
すべてのトラッキングとデータ収集を停止します。トラッキングが停止されると、SDKはトラッキングが再開されるまでいかなるイベントも送信せず、いかなるデータも収集しません。
シグネチャー
public static void StopAllTracking()
使用例
// Stop all tracking
SingularSDK.StopAllTracking();
トラッキングオプトイン
SingularSDK.TrackingOptInメソッド
ユーザーがトラッキングをオプトインしたことを示します。このメソッドは、ユーザがデータ収集とトラッキングに明示的に同意したときに呼び出されるべきです。
シグネチャ
public static void TrackingOptIn()
使用例
// User opted in to tracking
SingularSDK.TrackingOptIn();
TrackingUnder13
SingularSDK.TrackingUnder13 メソッド
ユーザーが 13 歳未満であることを示します。これは COPPA (Children's Online Privacy Protection Act) 規制に準拠するためのデータ収集に影響します。
署名
public static void TrackingUnder13()
使用例
// User is under 13 years old
SingularSDK.TrackingUnder13();
UnsetCustomUserId
SingularSDK.UnsetCustomUserId メソッド
以前に設定されたカスタムユーザー ID を削除します。このメソッドを呼び出すと、新しいカスタムユーザーIDが設定されるまで、イベントはカスタムユーザーIDに関連付けられなくなります。
シグネチャ
public static void UnsetCustomUserId()
使用例
// Remove custom user ID (e.g., on logout)
SingularSDK.UnsetCustomUserId();
UnsetGlobalProperty
SingularSDK.UnsetGlobalProperty メソッド
特定のグローバルプロパティをキーで削除します。これにより、そのプロパティは以降のイベントで送信されなくなります。
シグネチャ
public static void UnsetGlobalProperty(string key)
使用例
// Remove a specific global property
SingularSDK.UnsetGlobalProperty("user_level");