デバイスデータの取得ガイド

デバイスデータの取得ガイド

Singularでは、正確な属性情報を取得するために、すべてのAPIリクエストに特定のデバイス識別子を含める必要があります。これらの識別子には以下が含まれます:

  • Google PlayデバイスのGoogle Advertising ID (GAID) およびGoogle App Set ID (ASID)
  • Google Play以外のAmazonデバイス用のAmazon Advertising ID
  • 中国製Androidデバイス用のOpen Advertising ID (OAID)
  • 上記のいずれにも該当しない場合は、非Google Playデバイス用のAndroid ID(ANDI)を使用します。
  • iOSデバイス用の広告主識別子(IDFA)とベンダー識別子(IDFV)

Singularはまた、いくつかのモバイルデバイスのパラメータを必要とします:

  • ロケール(例:en_US)
  • デバイスのメーカー(例:Samsung)
  • デバイスモデル(例:iPhone 12、Samsung Galaxy S21)
  • ビルド(例:Build/13D15)

Singularはこれらの識別子を取得するためのコードスニペット例を提供しています。

デバイス情報クラスのサンプル

識別子

iOSに必要な識別子

  • IDFVは全てのS2Sリクエストで必須。
  • App Tracking Transparency Consentがユーザーによって提供された場合、IDFAが提供されるべきである。
  • ATT Authorization Statusも必要。
iOSデバイスデータの取得方法

広告主識別子(IDFA)の取得

広告主向け識別子(IDFA)は、広告主がユーザーのアクション(広告のクリックやアプリのインストールなど)を追跡し、特定のキャンペーンに関連付けるのに役立ち、正確な広告ターゲティングとキャンペーンの最適化を可能にします。

iOS 14.5以降、アプリがIDFAにアクセスする前に、ユーザーはApp Tracking Transparency(ATT)フレームワークを介してオプトインする必要があります。ユーザーがオプトインしない場合、IDFAは利用できず、トラッキング機能が制限されます。

ベンダー識別子(IDFV)の取得

IDFV(Identifier for Vendors)は、Appleがデバイスに割り当てる一意の識別子で、特定のベンダーまたはデベロッパーに固有のものです。特定のデバイス上の同じベンダーのすべてのアプリで一貫性が保たれるため、ベンダーはユーザーを個人的に特定することなく、そのアプリのエコシステム全体でユーザーの行動やインタラクションを追跡することができます。

  • IDFAへのアクセスを試みる前に、ATTプロンプトが表示され、処理されていることを確認してください。
  • ATTを使用している場合は、IDFAをキャプチャし、Singular APIリクエストで使用するためにサーバーに戻します。
  • IDFVをキャプチャし、Singular APIリクエストで使用するためにサーバーに戻す。

例ATT認証ステータスを要求して、コンソールログからIDFAとIDFVを取得する。

以下は、コンソールログでIDFA(広告主の識別子)とIDFV(ベンダーの識別子)の両方を取得するためのObjective-CとSwiftのコードスニペットです。このコードには、iOS 14.5からIDFAにアクセスするために必要なATT(App Tracking Transparency)パーミッションの処理が含まれています。

Objective-CSwift
#import <AdSupport/AdSupport.h>
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <UIKit/UIKit.h>

- (void)retrieveIdentifiers {
    // Request ATT authorization (iOS 14.5+)

    [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
        dispatch_async(dispatch_get_main_queue(), ^{
            switch (status) {
                case ATTrackingManagerAuthorizationStatusAuthorized: {
                    // ATT authorized, retrieve IDFA

                    NSUUID *idfa = [[ASIdentifierManager sharedManager] advertisingIdentifier];
                    NSLog(@"IDFA: %@", [idfa UUIDString]);
                    break;
                }
                case ATTrackingManagerAuthorizationStatusDenied:
                case ATTrackingManagerAuthorizationStatusRestricted:
                case ATTrackingManagerAuthorizationStatusNotDetermined:
                    // ATT not authorized or not determined

                    NSLog(@"Tracking not authorized or not determined.");
                    break;
                default:
                    NSLog(@"Unknown ATT status.");
                    break;
            }

            // Retrieve IDFV (always available)

            NSUUID *idfv = [[UIDevice currentDevice] identifierForVendor];
            if (idfv != nil) {
                NSLog(@"IDFV: %@", [idfv UUIDString]);
            } else {
                NSLog(@"Unable to retrieve IDFV.");
            }
        });
    }];
}

// Call the method to retrieve identifiers

[self retrieveIdentifiers];
  • IDFA:iOS 14.5+からATT許可が必要。ユーザーの同意がない場合、IDFAはすべてのゼロを返します。
  • IDFV: 常に利用可能であり、Singular API Requestsで常に提供されるべきである。

必須Android識別子(Google Playデバイス)

  • ASIDは、すべてのS2Sリクエストで必須です。
  • AIFA(GAID)は、利用可能な場合に提供されるべきである。
Android 端末データの取得方法 (Google Play)

Google広告識別子(GAID)の取得

Google Advertising Identifier(GAID)は、単数形ではAIFA、またはAndroid Advertising ID(AAID)とも呼ばれ、Android端末に割り当てられる一意のユーザーリセット可能な識別子です。これにより、広告主やアプリ開発者は、アプリ全体のユーザーアクション(広告のクリックやアプリのインストールなど)を追跡して特定のキャンペーンに関連付けることができ、ユーザーのプライバシーを維持しながら、正確な広告ターゲティングとキャンペーンの最適化が可能になります。

JavaKotlin
依存関係

build.gradleファイルにGoogle Play Servicesに必要な依存関係が追加されていることを確認してください:

dependencies {
    implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
}

 

アプリのビルドがAndroid 12/APIレベル31以上をターゲットにしている場合は、AndroidManifest.xml 、Google Advertising IDにアクセスするためのパーミッションを追加してください:

<uses-permission android:name="com.google.android.gms.permission.AD_ID" />

 

使用方法

このメソッドを使用するには、アクティビティまたはアプリケーションクラスから呼び出すだけです:

AdIdUtils.getGoogleAdId(getApplicationContext());

 

Google広告ID(GAID)を取得するJavaコード
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import com.google.android.gms.ads.identifier.AdvertisingIdClient.Info;

public class AdIdUtils {

    // Method to retrieve the Google Advertising ID (GAID)

    public static void getGoogleAdId(Context context) {
        // Running the task in a background thread

        AsyncTask.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    // Retrieve the Advertising ID info

                    Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(context);
                    
                    // Get the GAID (Google Advertising ID)

                    String adId = adInfo.getId();
                    
                    // Check if "Limit Ad Tracking" is enabled by the user

                    boolean isLimitAdTrackingEnabled = adInfo.isLimitAdTrackingEnabled();
                    
                    // Log the results

                    Log.d("GoogleAdID", "Advertising ID: " + adId);
                    Log.d("GoogleAdID", "Limit Ad Tracking Enabled: " + isLimitAdTrackingEnabled);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}

アプリセットID(ASID)の取得

Android App Set IDは、開発者がプライバシーに配慮した方法で自身のアプリ全体のユーザーを追跡する方法を提供します。特に分析や不正防止に役立ちますが、パーソナライズ広告や計測などの広告目的には使用できません。

JavaKotlin
依存関係

build.gradleファイルにGoogle Play Servicesに必要な依存関係が追加されていることを確認してください:

dependencies {
    implementation 'com.google.android.gms:play-services-appset:16.1.0'
}

 

使用方法

この関数を使用するには、アクティビティまたはアプリケーションクラスからこの関数を呼び出します:

AppSetIdUtils.getAppSetId(getApplicationContext());

 

アプリセットIDを取得するJavaコード
import android.content.Context;
import android.util.Log;
import com.google.android.gms.appset.AppSet;
import com.google.android.gms.appset.AppSetIdClient;
import com.google.android.gms.appset.AppSetIdInfo;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;

public class AppSetIdUtils {

    // Method to retrieve the App Set ID

    public static void getAppSetId(Context context) {
        // Get the AppSetIdClient instance

        AppSetIdClient client = AppSet.getClient(context);

        // Retrieve the App Set ID information asynchronously

        Task<AppSetIdInfo> task = client.getAppSetIdInfo();

        task.addOnSuccessListener(new OnSuccessListener<AppSetIdInfo>() {
            @Override
            public void onSuccess(AppSetIdInfo info) {
                // Get the App Set ID and its scope

                String appSetId = info.getId();
                int scope = info.getScope();

                // Log the results

                Log.d("AppSetID", "App Set ID: " + appSetId);
                Log.d("AppSetID", "Scope: " + (scope == AppSetIdInfo.SCOPE_DEVELOPER ? "Developer" : "App"));
            }
        }).addOnFailureListener(e -> {
            // Handle any errors that occur during retrieval

            Log.e("AppSetID", "Failed to retrieve App Set ID", e);
        });
    }
}

必要なAndroid識別子(Google Play以外のデバイス)

ASIDまたはAIFAがない場合:

  • AMID(Amazon識別子)を提供する必要があります。Amazonデバイスのみ。
Amazon Advertising ID(非Google Play)の取得方法

アマゾンID(AMID)の取得

AndroidアプリでAmazon Advertising IDを取得するには、Settings.Secureクラスを使ってIDを取得し、ユーザーの広告トラッキング設定を確認します。以下は、Amazonのドキュメントが提供する情報に基づいた、クリーンでシンプルなコード例です:

Advertising IDが利用できない可能性のあるシナリオ(例えば、Fire OS以外のデバイスやFire OSの古いバージョンなど)にも対応できるようにしてください。

この識別子を広告や分析の目的で使用する場合は、ユーザーのLimit Ad Tracking preferenceを常に尊重してください。このコードは、Amazonのガイドラインに従って、Fire OS 5.1以降を実行しているAmazon Fireデバイスで動作するはずです。

JavaKotlin
使用方法

ContentResolver.ContentResolverを渡すことで、アクティビティやサービスからこのメソッドを呼び出すことができます:

// Example usage in an Activity

AdvertisingIdHelper.getAmazonAdvertisingId(getContentResolver());

 

Amazon Advertising ID (AMID)を取得するJavaコード
import android.content.ContentResolver;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.util.Log;

public class AdvertisingIdHelper {

    public static void getAmazonAdvertisingId(ContentResolver contentResolver) {
        String advertisingID = "";
        boolean limitAdTracking = false;

        try {
            // Get user's ad tracking preference

            limitAdTracking = (Settings.Secure.getInt(contentResolver, "limit_ad_tracking") == 0) ? false : true;

            // Get the Amazon Advertising ID

            advertisingID = Settings.Secure.getString(contentResolver, "advertising_id");

            // Log the values for demonstration purposes

            Log.d("AdvertisingID", "Amazon Advertising ID: " + advertisingID);
            Log.d("LimitAdTracking", "Limit Ad Tracking: " + limitAdTracking);

        } catch (SettingNotFoundException e) {
            // Handle case where settings are not available (e.g., non-Fire OS devices)

            Log.e("AdvertisingID", "Advertising ID not supported on this device", e);
        }
    }
}
  • OAID(Open Advertising Identifier)を提供する必要があります。中国国内の端末
オープン広告IDの取得方法(Google Play以外)

オープン広告ID(OAID)の取得について

Open Advertising Identifier(OAID)は、Android端末、特に中国で製造された端末の広告目的で使用される一意の匿名識別子です。中国市場など、Google Playサービスが利用できない、またはサポートされていないデバイスのために、Googleの広告ID(GAID)の代替としてMobile Security Alliance(MSA)によって導入されました。

OAIDは主に、Google Playサービスが制限されている環境における広告のアトリビューションやユーザー追跡のために使用され、広告主や開発者は匿名性を維持しながらユーザーの行動を追跡することができます。

OAIDは、ファーウェイやシャオミなどのブランドを含む、ほとんどの中国製アンドロイド端末で利用できる。MSA SDKまたはHuawei Mobile Services(HMS)を使用してアクセスできます。

JavaKotlin
依存関係

build.gradle ファイルに MSA SDK に必要な依存関係が含まれていることを確認してください。

dependencies {
    implementation 'com.bun.msa.sdk:msa:1.0.26'  // Example version; check for the latest one

}

 

OAIDを取得するJavaコード
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import com.bun.msa.sdk.DeviceId;
import com.bun.msa.sdk.DeviceIdSupplier;
import com.bun.msa.sdk.IIdentifierListener;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "OAIDExample";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Initialize and request OAID

        getOAID();
    }

    private void getOAID() {
        try {
            // Create a DeviceId instance and request OAID asynchronously

            DeviceId deviceId = new DeviceId(this);
            deviceId.getDeviceIds(new IIdentifierListener() {
                @Override
                public void onSupport(boolean isSupport, DeviceIdSupplier supplier) {
                    if (isSupport && supplier != null) {
                        // Retrieve OAID from supplier

                        String oaid = supplier.getOAID();
                        Log.d(TAG, "OAID: " + oaid);
                    } else {
                        Log.e(TAG, "OAID not supported on this device");
                    }
                }
            });
        } catch (Exception e) {
            Log.e(TAG, "Error retrieving OAID", e);
        }
    }
}
  • 他のデバイス識別子が存在しない場合は、ANDI(Android ID)を提供することができます。
Android IDの取得方法(Google Play以外)

Android ID(ANDI)の取得

Android IDは、デバイスの最初のセットアップ時にAndroidオペレーティングシステムによって生成される一意の64ビット識別子です。Android IDはデバイスの寿命を通じて永続するように設計されていますが、ファクトリーリセットなどの特定の条件下ではリセットすることができます。

Android IDは各デバイスに固有で、Android 8.0(Oreo)からはアプリごと、ユーザーごとにスコープされるようになった。つまり、同じデバイス上の異なるアプリは、同じ署名キーを共有しない限り、異なるAndroid IDを受け取ることになります。

Android IDは、デバイスがファクトリーリセットされない限り、またはOTA(Over-the-Air)アップデート後にアプリがアンインストールされ再インストールされない限り、一定に保たれます。

JavaKotlin
使用方法

AndroidアプリでAndroid IDを取得するには、以下のコード・スニペットを使用します:

import android.provider.Settings;
import android.content.Context;

String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);

必須ウェブ識別子

  • SDIDは全てのS2Sリクエストに必要です。
Singular Web SDKデバイスID(SDID)の取得方法

Singular Web SDK デバイスID(SDID)の取得

説明

依存関係

Singular Web SDKが実装されている必要があります。

使用方法

このメソッドを使用するには、Singular SDKが初期化された後、ウェブサイトのコードからこのメソッドを呼び出します:

window.singularSdk.getSingularDeviceId()

必要なモバイルデバイスパラム

  • Locale、Device Make、Device Model、Buildは全てのS2Sリクエストに必要です。
Locale、Device Make、Device Model、Buildの取得方法

Locale、Device Make、Model、Buildの取得

Objective-CSwiftJavaKotlin
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <sys/sysctl.h>

// Retrieve the Locale

NSString *retrieveLocale() {
    NSString *locale = [[NSLocale currentLocale] localeIdentifier];
    NSLog(@"Locale: %@", locale);
    return locale;
}

// Retrieve the Manufacturer

NSString *retrieveManufacturer() {
    // Set the Device Make to Apple    

    return @"Apple";
}

                            
// Retrieve the Device Model

NSString *deviceModel() {
    size_t bufferSize = 64;
    char model[bufferSize];
    int status = sysctlbyname("hw.machine", model, &bufferSize, NULL, 0);
    
    if (status == 0) {
        NSString *deviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
        NSLog(@"Device Model: %@", deviceModel);
        return deviceModel;
    } else {
        NSLog(@"Unable to retrieve device model.");
        return nil;
    }
}

// Retrieve the Build Version

NSString *buildVersion() {
    size_t bufferSize = 64;
    char build[bufferSize];
    int status = sysctlbyname("kern.osversion", build, &bufferSize, NULL, 0);
    
    if (status == 0) {
        NSString *buildVersion = [NSString stringWithCString:build encoding:NSUTF8StringEncoding];
        NSLog(@"Build Version: %@", buildVersion);
        return buildVersion;
    } else {
        NSLog(@"Unable to retrieve build version.");
        return nil;
    }
}

// Example usage

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // Retrieve Locale

        NSString *locale = retrieveLocale();

        // Retrieve Device Make

        NSString *make = retrieveManufacturer();
              
        // Retrieve Device Model

        NSString *model = deviceModel();
        
        // Retrieve Build Version

        NSString *build = buildVersion();
        
        // Log results

        if (locale) {
            NSLog(@"Locale: %@", locale);
        }
        
        if (make) {
            NSLog(@"Device Make: %@", make);
        }
              
        if (model) {
            NSLog(@"Device Model: %@", model);
        }
        
        if (build) {
            NSLog(@"Build Version: %@", build);
        }
    }
    return 0;
}