同意の実装

モバイルアプリで同意を実装する方法を説明します。

Adobe Experience Platform同意モバイル拡張機能を使用すると、Adobe Experience Platform Mobile SDKおよびEdge Network拡張機能を使用する際に、モバイルアプリから同意環境設定を収集できます。 同意拡張機能について詳しくは、ドキュメントを参照してください。

前提条件

  • SDK がインストールおよび設定された状態で、アプリケーションが正常に構築および実行されました。

学習目標

このレッスンでは、次の操作を行います。

  • ユーザーに同意を求めます。
  • ユーザーの応答に基づいて拡張機能を更新します。
  • 現在の同意状態を取得する方法を説明します。

同意を求める

最初からチュートリアルに従った場合、同意拡張機能のデフォルトの同意を、ユーザーが同意環境設定を指定する前に発生する 保留中 – キューのイベント に設定していることに注意してください。

データの収集を開始するには、ユーザーの同意を得る必要があります。 実際のアプリでは、お住まいの地域に合わせた同意のベストプラクティスを参照する必要があります。 このチュートリアルでは、アラートを付けて要求するだけで、ユーザーから同意を得ます。

iOS
  1. ユーザーに同意を求めるのは 1 回だけです。 Mobile SDKの同意を、Appleの App Tracking Transparency Framework を使用したトラッキングに必要な認証と組み合わせます。 このアプリでは、トラッキングを承認するユーザーが、イベントの収集に同意すると仮定します。

  2. Xcode プロジェクトナビゲーターで Luma/Luma/Utils/MobileSDK に移動します。

    このコードを updateConsent 関数に追加します。

    code language-swift
    // Update consent
    let collectConsent = ["collect": ["val": value]]
    let currentConsents = ["consents": collectConsent]
    Consent.update(with: currentConsents)
    MobileCore.updateConfigurationWith(configDict: currentConsents)
    
  3. Xcode のプロジェクトナビゲーターで、Luma/Luma/Views/General/DisclaimerView に移動します。 Xode のプロジェクトナビゲーターは、アプリケーションをインストールまたは再インストールし、アプリケーションを初めて起動した後に表示されるビューです。 Appleごとのトラッキングを認証するプロンプトが表示されます App Tracking Transparency Framework。 ユーザーが承認すると、同意も更新されます。

    ATTrackingManager.requestTrackingAuthorization { status in クロージャに次のコードを追加します。

    code language-swift
    // Add consent based on authorization
    if status == .authorized {
       // Set consent to yes
       MobileSDK.shared.updateConsent(value: "y")
    }
    else {
       // Set consent to yes
       MobileSDK.shared.updateConsent(value: "n")
    }
    
Android
  1. ユーザーに同意を求めるのは 1 回だけです。 このアプリでは、トラッキングを承認するユーザーが、イベントの収集に同意すると仮定します。

  2. Android Studio ナビゲーターで app/kotlin+java/com.adobe.luma.tutorial.android/models/MobileSDK に移動します。

    このコードを updateConsent(value: String) 関数に追加します。

    code language-kotlin
    // Update consent
    val collectConsent = mapOf("collect" to mapOf("val" to value))
    val currentConsents = mapOf("consents" to collectConsent)
    Consent.update(currentConsents)
    MobileCore.updateConfiguration(currentConsents)
    
  3. Android Studio ナビゲーターで app/kotlin+java/com.adobe.luma.tutorial.android/views/DisclaimerView.kt に移動します。

    DisclaimerView(navController: NavController)// Set content to yes の下の // Set content to no 関数に次のコードを追加します。

    code language-kotlin
    // Add consent based on authorization
    if (status) {
       showPersonalizationWarning = false
    
       // Set consent to yes
       MobileSDK.shared.updateTrackingStatus(TrackingStatus.AUTHORIZED)
       MobileSDK.shared.updateConsent("y")
    } else {
       Toast.makeText(
             context,
             "You will not receive offers and location tracking will be disabled.",
             Toast.LENGTH_LONG
       ).show()
       showPersonalizationWarning = true
    
       // Set consent to no
       MobileSDK.shared.updateTrackingStatus(TrackingStatus.DENIED)
       MobileSDK.shared.updateConsent("n")
    }
    

現在の同意状態を取得

同意モバイル拡張機能は、現在の同意値に基づいて、トラッキングを自動的に抑制/保留/許可します。 現在の同意状態に自分でアクセスすることもできます。

iOS
  1. Xcode のプロジェクトナビゲーターで Luma/Luma/Utils/MobileSDK に移動します。

    getConsents 関数に次のコードを追加します。

    code language-swift
    // Get consents
    Consent.getConsents { consents, error in
       guard error == nil, let consents = consents else { return }
       guard let jsonData = try? JSONSerialization.data(withJSONObject: consents, options: .prettyPrinted) else { return }
       guard let jsonStr = String(data: jsonData, encoding: .utf8) else { return }
       Logger.aepMobileSDK.info("Consent getConsents: \(jsonStr)")
    }
    
  2. Xcode のプロジェクトナビゲーターで、Luma/Luma/Views/General/HomeView に移動します。

    .task 修飾子に次のコードを追加します。

    code language-swift
    // Ask status of consents
    MobileSDK.shared.getConsents()
    

上記の例では、同意ステータスを Xcode のコンソールに記録するだけです。 実際のシナリオでは、ユーザーに表示するメニューやオプションを変更する場合に使用します。

Android
  1. Android Studio ナビゲーターで app/kotlin+java/com.adobe.luma.tutorial.android/models/MobileSDK に移動します。

    getConsents() 関数に次のコードを追加します。

    code language-kotlin
    // Get consents
    Consent.getConsents { callback ->
       if (callback != null) {
             val jsonStr = JSONObject(callback).toString(4)
             Log.i("MobileSDK", "Consent getConsents: $jsonStr")
       }
    }
    
  2. Android Studio ナビゲーターで app/kotlin+java/com.adobe.luma.tutorial.android/views/HomeView.kt に移動します。

    LaunchedEffect(unit) に次のコードを追加します。

    code language-kotlin
    // Ask status of consents
    MobileSDK.shared.getConsents()
    

上記の例では、同意ステータスをAndroid Studio のコンソールに記録するだけです。 実際のシナリオでは、ユーザーに表示するメニューやオプションを変更する場合に使用します。

Assurance での検証

  1. デバイスまたはシミュレーターからアプリケーションを削除して、トラッキングと同意を適切にリセットおよび初期化します。

  2. シミュレーターやデバイスをAssuranceに接続するには、 設定手順セクションを確認してください。

  3. アプリを ホーム 画面から 製品 画面に移動し、ホーム 画面に戻ると、Assurance UI に 同意応答を取得 イベントが表示されます。

    同意を検証 {modal="regular"}

SUCCESS
これで、Adobe Experience Platform Mobile SDKを使用して、インストール(または再インストール)後、最初にユーザーに同意を求めるプロンプトをアプリで表示できるようになりました。
Adobe Experience Platform Mobile SDKの学習にご協力いただき、ありがとうございます。 ご不明な点がある場合や、一般的なフィードバックをお寄せになる場合、または今後のコンテンツに関するご提案がある場合は、この Experience League Community Discussion の投稿でお知らせください

次のトピック:ライフサイクル・データの収集

recommendation-more-help
9fed61f5-c338-47ad-8005-0b89a5f4af8b