Unityプラグイン V6 実装ガイド - APIリファレンス

概要:AppsFlyerSDKに含まれる、クラスとメソッドの技術的な説明を記載しています。 

 関連記事

Unityプラグインとアプリの実装の全体像については、以下の記事も必ず確認してください:

Android / iOSのAPI

initSDK

説明

Dev KeyとAppIDでプラグインを初期化してください。Dev Keyはすべてのアプリに必要です。AppIDはiOSでのみ必要になります。アプリがAndroidのみである場合には、AppIDはnullで渡してください。ゲームオブジェクトには、IAppsFlyerConversionData interfaceが含まれています。

メソッドのシグネチャ

void initSDK(string devKey, string appID, MonoBehaviour gameObject)

AppsFlyer.initSDK("dev_key","app_id"); // without deeplinking
            AppsFlyer.initSDK("dev_key","app_id", this); // with deeplinking

startSDK

説明

このAPIが呼び出されると、SDKが起動され、セッションがすぐに送信され、すべてのバックグラウンドからフォアグラウンドへの遷移においてセッションが記録されます。

メソッドのシグネチャ

void startSDK()

AppsFlyer.startSDK();

sendEvent

説明

アプリ内イベントの計測は、イベント名とパラメータと一緒にsendEventを呼び出すことで実行されます。

メソッドのシグネチャ

void sendEvent(string eventName, Dictionary<string, string> eventValues)

Dictionary<string, string> 
            eventValues = new Dictionary<string, string>();
            eventValues.Add(AFInAppEvents.CURRENCY, "USD");
            eventValues.Add(AFInAppEvents.REVENUE, "0.99");
eventValues.Add("af_quantity", "1");
            AppsFlyer.sendEvent(AFInAppEvents.PURCHASE, eventValues);

stopSDK

説明

極稀に、規約やプライバシー遵守のためにすべてのSDKの機能をシャットダウンしなければならない場合がありますが、その場合にはstopSDKのAPIを使用してください。このAPIが呼び出されると、SDKはAppsFlyerのサーバーとの通信を停止し、機能しなくなります。

メソッドのシグネチャ

void stopSDK(bool isSDKStopped)

AppsFlyer.stopSDK(true);

isSDKStopped

説明

stopSDK(boolean) APIがtrueにセットされているかどうかを返します。

メソッドのシグネチャ

bool isSDKStopped()

if (!AppsFlyer.isSDKStopped())
{

}

getSdkVersion

説明

AppsFlyer SDKのバージョンを取得します。

メソッドのシグネチャ

string getSdkVersion()

string version = AppsFlyer.getSdkVersion();

setIsDebug

説明

デバッグログを有効にします。

メソッドのシグネチャ

void setIsDebug(bool shouldEnable)

AppsFlyer.setIsDebug(true);

setCustomerUserID

説明

カスタマーユーザーID(CUID)を設定します。

メソッドのシグネチャ

void setCustomerUserId(string id)

AppsFlyer.setCustomerUserId("custom_user_id");

setAppInviteOneLink

説明

ユーザー招待用のカスタム計測リンクの作成に使用される、OneLinkテンプレートIDを設定します。

メソッドのシグネチャ

setAppInviteOneLinkID(string oneLinkId)

AppsFlyer.setAppInviteOneLinkID("abcd");

setAdditionalData

説明

外部のパートナープラットフォームに送信するデータを追加します。

メソッドのシグネチャ

setAdditionalData(Dictionary<string, string> customData)

Dictionary<string, string> customData = new Dictionary<string, string>();
customData.Add("custom1", "someData");
AppsFlyer.setAdditionalData(customData);

setResolveDeepLinkURLs

説明

クリックドメインからのOneLinkを解決します。詳細は、変換されたディープリンクURLの解決方法 を参照してください。

メソッドのシグネチャ

setResolveDeepLinkURLs(params string[] urls)

AppsFlyer.setResolveDeepLinkURLs("example.com", "click.example.com");

setOneLinkCustomDomain

説明

広告主はこのメソッドを利用して、カスタムしたOneLinkドメイン(Branded OneLink)を設定できます。

メソッドのシグネチャ

void setOneLinkCustomDomain(params string[] domains)

AppsFlyer.setOneLinkCustomDomain("test.domain", "test2.domain");

setcurrencyCode

説明

収益を持つイベントに使用します。ISO通貨コードを使用します。

メソッドのシグネチャ

public void setCurrencyCode(String currencyCode);

AppsFlyer.setCurrencyCode("GBP");

recordLocation

説明

ユーザーの位置情報をマニュアルで記録します。

メソッドのシグネチャ

void recordLocation(double latitude, double longitude)

AppsFlyer.recordLocation(40.7128,74.0060);

anonymizeUser

説明

ユーザーのインストール、イベント、セッションの計測を明示的に匿名化するには、初期化中にこのAPIを使用してください。匿名化を停止するには、再度anonymizeUserを呼び出して、falseに設定してください。

メソッドのシグネチャ

void anonymizeUser(bool shouldAnonymizeUser)

AppsFlyer.anonymizeUser(true);

getAppsFlyerId

説明

新規インストール時のAppsFlyerIDを取得します。

メソッドのシグネチャ

string getAppsFlyerId()

string uid = AppsFlyer.getAppsFlyerId();

setMinTimeBetweenSessions

説明

デフォルトでは、2つのセッションがそれぞれ別の起動としてカウントされるには、2つのアプリ起動の間隔が少なくとも5秒以上会いている必要があります。このセッション計測の最小間隔を任意で設定したい場合には、値を設定してください。

メソッドのシグネチャ

void setMinTimeBetweenSessions(int seconds)

AppsFlyer.setMinTimeBetweenSessions(4);

setUserEmails

説明

ユーザーのEメールアドレスを設定し暗号化します。

メソッドのシグネチャ

void setUserEmails(EmailCryptType cryptMethod, params string[] emails)

AppsFlyer.setUserEmails(EmailCryptType.EmailCryptTypeSHA256, "test1@test1.com","test2@test2.com");

setHost

説明

カスタムホストを設定します。

メソッドのシグネチャ

void setHost(string hostPrefixName, string hostName)

AppsFlyer.setHost("hostPrefixName","hostName");

getConversionData

説明

コンバージョンデータリスナーを実装すると、新規インストール毎にリアルタイムにそのユーザーのアトリビューションデータにアクセスできるようになります。これにより、パーソナライズされたコンテンツを提供したり、アプリ内の特定のアクティビティに誘導したりして、ユーザーのアプリへのエンゲージメントを大きく高めることができます。

メソッドのシグネチャ

void getConversionData(string objectName);

AppsFlyer.getConversionData(gameObject.name);

attributeAndOpenStore

説明

クリックを計測してアプリストアのアプリページを起動します。

メソッドのシグネチャ

void attributeAndOpenStore
(string appID, string campaign,
Dictionary<string, string> userParams, MonoBehaviour gameObject)


Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("af_sub1", "val");
parameters.Add("custom_param", "val2");
AppsFlyer.attributeAndOpenStore("123456789","test campaign", parameters, this);            

recordCrossPromoteImpression

説明

インプレッションを紐づけるには、次のAPIコールを使用します。AppsFlyerの管理画面上に表示されているAppIDを使用してください。

メソッドのシグネチャ

void recordCrossPromoteImpression(string appID, string campaign);

Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("af_sub1", "val");
parameters.Add("custom_param", "val2");
AppsFlyer.recordCrossPromoteImpression("appID","campaign", parameters);

generateUserInviteLink

説明

LinkGeneratorのクラスは、クリックで追加情報を渡すことができるさまざまなセッターメソッドに従って、ユーザー招待のURLを作成します。

メソッドのシグネチャ

void generateUserInviteLink
(Dictionary<string, string> parameters, MonoBehaviour gameObject)

AppsFlyer.generateUserInviteLink(params,this);

onAppOpenAttribution

説明

アプリがディープリンク起動されたときに、ディープリンクのデータを取得します。

メソッドのシグネチャ

public void onAppOpenAttribution(string validateResult)

public void onAppOpenAttribution(string attributionData)
            { AppsFlyer.AFLog("onAppOpenAttribution", attributionData);
            Dictionary<string, object> attributionDataDictionary = AppsFlyer.CallbackStringToDictionary(attributionData);
            // add direct deeplink logic here }

onAppOpenAttributionFailure

説明

ディープリンクデータを取得する際のエラー情報を取得します。

メソッドのシグネチャ

public void onAppOpenAttributionFailure (string error)

public void onAppOpenAttributionFailure(string error)
            {AppsFlyer.AFLog("onAppOpenAttributionFailure", error); }

onConversionDataSuccess

説明

コンバージョンデータを取得するために使用されるメソッドです。ディファードディープリンクに役立ちます。 詳細はこちら

  • SDK v5 以降: onConversionDataSuccess
  • SDK v5未満: onConversionDataReceived 

メソッドのシグネチャ

public void onConversionDataSuccess(string conversionData)

public void onConversionDataSuccess(string conversionData)
            {
            AppsFlyer.AFLog("onConversionDataSuccess", conversionData);
            Dictionary<string, object> conversionDataDictionary = AppsFlyer.CallbackStringToDictionary(conversionData);
            // add deferred deeplink logic here
            }

onConversionDataFail

説明

インストールのコンバージョンデータを取得できない時のエラーを処理します。

メソッドのシグネチャ

public void onConversionDataFail(string error)

public void onConversionDataFail(string error)
            {
            AppsFlyer.AFLog("onConversionDataFail", error);
            }

onInviteLinkGenerated

説明

OneLink URLを作成するときのサクセスコールバックです。

メソッドのシグネチャ

public void onInviteLinkGenerated(string link)

public void onInviteLinkGenerated(string link)
            {
            }

onInviteLinkGeneratedFailure

説明

OneLink URLを作成するときのエラーコールバックです。

メソッドのシグネチャ

public void onInviteLinkGeneratedFailure(string error)

public void onInviteLinkGeneratedFailure(string error)
            {
            AppsFlyer.AFLog("onInviteLinkGeneratedFailure", error);
            }

didFinishValidateReceipt

説明

validateAndSendInAppPurchase APIのサクセスコールバックです。

Androidの場合:"Validate success"と返します。
iOSの場合:AppleのverifyReceipt APIから返された、JSONの文字列を返します。

メソッドのシグネチャ

public void didFinishValidateReceipt(string result)

public void didFinishValidateReceipt(string result)
            {
            }

didFinishValidateReceiptWithError

説明

購入検証のためのエラーコールバックです。

メソッドのシグネチャ

public void didFinishValidateReceiptWithError(string error)

public void didFinishValidateReceiptWithError(string error)
            {
            }

setPhoneNumber

説明

ユーザーの電話番号を設定するために使用します。

メソッドのシグネチャ

void setPhoneNumber(string phoneNumber)

AppsFlyer.setPhoneNumber("4166358181");

setSharingFilterForAllPartners (非推奨)

説明

広告主が すべての アドネットワーク/連携済みパートナーに対して データを共有しないようにするために使用します。 詳細はこちらを参照してください。

メソッドのシグネチャ

void setSharingFilterForAllPartners()

AppsFlyer.setSharingFilterForAllPartners();

setSharingFilter (非推奨)

説明

広告主が 特定の (ひとつもしくは複数の) アドネットワーク/連携済みパートナーに対して データを共有しないようにするために使用します。 詳細はこちら

メソッドのシグネチャ

void setSharingFilter(params string[] partners)

AppsFlyer.setSharingFilter
("googleadwords_int","snapchat_int","doubleclick_int");

setSharingFilterForPartners

説明

広告主が、一部の(1つ以上の)ネットワーク/連携パートナーを設定して、データの取得から除外するために使用されます。

メソッドのシグネチャ

void setSharingFilterForPartners(params string[] partners)

AppsFlyer.setSharingFilterForPartners("partner1_int"); // Single partner
AppsFlyer.setSharingFilterForPartners("partner1_int", "partner2_int");// Multiple partners
AppsFlyer.setSharingFilterForPartners("all"); // All partners
AppsFlyer.setSharingFilterForPartners(""); // Reset list (default)
AppsFlyer.setSharingFilterForPartners(); // Reset list (default)

Android向けAPI

updateServerUninstallToken

説明

アンインストール計測のために、Firebaseのデバイストークンを手動で渡します。

メソッドのシグネチャ

void updateServerUninstallToken(string token)

#if UNITY_ANDROID && !UNITY_EDITOR
            AppsFlyerAndroid.updateServerUninstallToken("token");
#endif

setImeiData

説明

IMEIをAppsFlyerに明示的に送信します。

メソッドのシグネチャ

void setImeiData(string imei)

#if UNITY_ANDROID && !UNITY_EDITOR
            AppsFlyerAndroid.setImeiData("imei");
#endif

setAndroidIdData

説明

Android IDをAppsFlyerに明示的に送信します。

メソッドのシグネチャ

void setAndroidIdData(string androidId)

#if UNITY_ANDROID && !UNITY_EDITOR
            AppsFlyerAndroid.setAndroidIdData("androidId");
#endif

waitForCustomerUserId

説明

この機能を使用すると、customerUserIDが設定されるまで、SDKは動作を開始しません。

メソッドのシグネチャ

void waitForCustomerUserId(bool wait)

#if UNITY_ANDROID && !UNITY_EDITOR
            AppsFlyerAndroid.waitForCustomerUserId(true);
#endif

setCustomerIdAndStartSDK

説明

関連するCustomer User IDをSDKに提供してからSDKを発火させて通常の計測を開始します。

メソッドのシグネチャ

void setCustomerIdAndStartSDK(string id)

#if UNITY_ANDROID && !UNITY_EDITOR
            AppsFlyerAndroid.setCustomerIdStartSDK("id");
#endif

getOutOfStore

説明

現在のAF_STOREの値を取得します。

メソッドのシグネチャ

string getOutOfStore()

#if UNITY_ANDROID && !UNITY_EDITOR
            string af_store = AppsFlyerAndroid.getOutOfStore();
#endif

setOutOfStore

説明

AF_STOREの値をマニュアルで設定します。

メソッドのシグネチャ

void setOutOfStore(string sourceName)

#if UNITY_ANDROID && !UNITY_EDITOR
            AppsFlyerAndroid.setOutOfStore("sourceName");
#endif

setCollectAndroidID

説明

Android IDの取得を無効化します。アプリがGooglePlay Servicesを搭載していない場合に、Android IDがSDKによって取得されます。ただし、Google Play Servicesを使用したアプリの場合には、Android IDの取得はGoogle Playのポリシーに違反するため、取得しないようにしてください。

メソッドのシグネチャ

void setCollectAndroidID(bool isCollect)

#if UNITY_ANDROID && !UNITY_EDITOR
            AppsFlyerAndroid.setCollectAndroidID(true);
#endif

setCollectIMEI

説明

IMEIの取得を無効化します。アプリがGooglePlay Servicesを搭載していない場合に、端末のIDEIがプラグインによって取得されます。ただし、Google Play Servicesを使用したアプリの場合には、IMEIの取得はGoogle Playのポリシーに違反するため、取得しないようにしてください。

メソッドのシグネチャ

void setCollectIMEI(bool isCollect)

#if UNITY_ANDROID && !UNITY_EDITOR
            AppsFlyerAndroid.setCollectIMEI(true);
#endif

setIsUpdate

説明

アプリがアップデートされたことをマニュアルで設定します。

メソッドのシグネチャ

void setIsUpdate(bool isUpdate)

#if UNITY_ANDROID && !UNITY_EDITOR
            AppsFlyerAndroid.setIsUpdate(true);
#endif

setPreinstallAttribution

説明

プリインストールを発生させた端末メーカーやメディアソース名を指定します。

メソッドのシグネチャ

void setPreinstallAttribution
(string mediaSource, string campaign, string siteId)

#if UNITY_ANDROID && !UNITY_EDITOR
            AppsFlyerAndroid.setPreinstallAttribution("mediaSource","campaign", "siteId");
            #endif

isPreInstalledApp

説明

端末メーカーによるプリインストール計測用のBoolean型のインジケーターです。

メソッドのシグネチャ

bool isPreInstalledApp()

#if UNITY_ANDROID && !UNITY_EDITOR
            if (AppsFlyerAndroid.isPreInstalledApp())
            {
            }
            #endif

 getAttributionId

説明

(存在する場合)Facebookのattribution IDを取得します。

メソッドのシグネチャ

string getAttributionId()

#if UNITY_ANDROID && !UNITY_EDITOR
            string attributionId = AppsFlyerAndroid.getAttributionId();
#endif

handlePushNotifications

説明

プッシュ通知を記録します。

メソッドのシグネチャ

void handlePushNotifications()

#if UNITY_ANDROID && !UNITY_EDITOR
            AppsFlyerAndroid.handlePushNotifications();
#endif

validateAndSendInAppPurchase

説明

アプリ内課金をサーバー検証するためのAPIです。検証が成功すると、関連するイベント値を持つaf_purchaseイベントが自動的に送信されます。

メソッドのシグネチャ

void validateAndSendInAppPurchase
(string publicKey, string signature, string purchaseData,
string price, string currency, Dictionary<string, string> additionalParameters,
MonoBehaviour gameObject)

#if UNITY_ANDROID && !UNITY_EDITOR
            AppsFlyerAndroid.validateAndSendInAppPurchase(
"publicKey", 
            "signature", 
            "purchaseData", 
            "price", 
            "currency", 
            null, 
            this);
            #endif

iOS向けのAPI

setShouldCollectDeviceName

説明

現在のデバイス名(" My iPhone など ")を収集するには、このフラグを true に設定してください。デフォルト設定は"false"です。 

メソッドのシグネチャ

void setShouldCollectDeviceName(bool shouldCollectDeviceName)

#if UNITY_IOS && !UNITY_EDITOR
            AppsFlyeriOS.setShouldCollectDeviceName(true);
#endif

setDisableCollectIAd

説明

Apple Search Adsの計測を無効化します。

メソッドのシグネチャ

void setDisableCollectIAd(bool disableCollectIAd)

#if UNITY_IOS && !UNITY_EDITOR
            AppsFlyeriOS.setDisableCollectIAd(true);
#endif

setUseReceiptValidationSandbox

説明

iOS(本番環境 or サンドボックス)でのアプリ内課金の検証をします。デフォルト設定は"false"です。

メソッドのシグネチャ

void setUseReceiptValidationSandbox(bool useReceiptValidationSandbox)

#if UNITY_IOS && !UNITY_EDITOR
            AppsFlyeriOS.setUseReceiptValidationSandbox(true);
#endif

setUseUninstallSandbox

説明

iOS(本番環境 or サンドボックス)でのアンインストール計測をテストするには、このフラグを設定してください。デフォルト設定は"false"です。

メソッドのシグネチャ

void setUseUninstallSandbox(bool useUninstallSandbox)

#if UNITY_IOS && !UNITY_EDITOR
            AppsFlyeriOS.setUseUninstallSandbox(true);
#endif

validateAndSendInAppPurchase

説明

アプリ内課金を送信して検証するには、ProcessPurChase メソッドからこのメソッドを呼び出します。

メソッドのシグネチャ

void validateAndSendInAppPurchase
(string productIdentifier, string price, string currency, string tranactionId,
Dictionary<string, string> additionalParameters, MonoBehaviour gameObject)

#if UNITY_IOS && !UNITY_EDITOR
            AppsFlyeriOS.validateAndSendInAppPurchase(
            "productIdentifier", 
            "price", 
            "currency", 
            "tranactionId", 
            null, 
            this);
            #endif

registerUninstall

説明

リモート通知に登録し、AppsFlyerにプッシュデバイストークンを提供します。

メソッドのシグネチャ

void registerUninstall(byte[] deviceToken)

private bool tokenSent;
            void Update()
            {
            #if UNITY_IOS && !UNITY_EDITOR
            if (!tokenSent)
            {
            byte[] token = UnityEngine.iOS.NotificationServices.deviceToken;
if (token != null)
            {
            AppsFlyeriOS.registerUninstall(token);
            tokenSent = true;
            }
            }
            #endif
            }

handleOpenUrl

説明

ディープリンクを手動で計測するために使用します。

メソッドのシグネチャ

void handleOpenUrl(string url, string sourceApplication, string annotation)

#if UNITY_IOS && !UNITY_EDITOR
            AppsFlyeriOS.handleOpenUrl(stringurl, string sourceApplication, string annotation);
            #endif

onOpenStoreLinkGenerated

説明

StoreKit コンポーネントを使用して、アプリのコンテキストを維持しながら、App Storeを開くことができます。詳細はこちらを参照してください。

メソッドのシグネチャ

public void onOpenStoreLinkGenerated(string link)

public void onOpenStoreLinkGenerated(string link)
            {
            }

disableSKAdNetwork

説明

SKAdNetworkの計測を無効にすることができます。"trueに設定することで無効化できます。

メソッドのシグネチャ

bools disableSKAdNetwork(int isDisabled)

#if UNITY_IOS && !UNITY_EDITOR
    AppsFlyeriOS.disableSKAdNetwork(true);
#endif

waitForATTUserAuthorizationWithTimeoutInterval

説明

ユーザーや端末を記録するためにIDFAなどのアプリ関連データにアクセスする前に、ポップアップで ユーザー認証を要求したい 場合に使用します。ユーザーがオプトインした場合、IDFA が SDKに渡されます。 Timeout Intervalにより、IDFAの取得をオプトインするまで一定の時間がユーザに対して付与され、このタイマーの期限が切れるとIDFAは取得されません。

メソッドのシグネチャ

void waitForATTUserAuthorizationWithTimeoutInterval(int timeoutInterval)

#if UNITY_IOS && !UNITY_EDITOR
    AppsFlyeriOS.waitForATTUserAuthorizationWithTimeoutInterval(60);
#endif