שנתחיל?

בהתאם למדיניות Google בנושא הסכמת משתמשים באיחוד האירופי, עליכם להציג הודעות גילוי נאות מסוימות למשתמשים שנמצאים באזור הכלכלי האירופי (EEA) יחד עם בריטניה, ולקבל את הסכמתם לשימוש בקובצי cookie או באחסון מקומי אחר, היכן שהדבר נדרש על פי חוק, ולהשתמש במידע אישי (כגון AdID) כדי להציג מודעות. המדיניות הזו משקפת את הדרישות שמפורטות בהנחיה בנושא פרטיות ותקשורת אלקטרונית ובתקנה הכללית להגנה על מידע (GDPR) של האיחוד האירופי.

כדי לעזור לבעלי תוכן דיגיטלי לעמוד בהתחייבויות שלהם בהתאם למדיניות הזו, Google מציעה את User Messaging Platform (UMP) SDK. UMP SDK עודכן ועכשיו הוא תואם לסטנדרטים האחרונים של IAB. מעכשיו אפשר לטפל בנוחות בכל ההגדרות האלה AdMob בפרטיות ובהעברת הודעות.

דרישות מוקדמות

סוגים של הודעות למשתמשים

בדף סוגי הודעות של משתמשים רשימה מלאה של ההודעות הנתמכות. תוכלו למצוא הוראות ספציפיות להטמעה של כל סוג הודעה בסרגל הניווט הימני.

התקנה באמצעות Gradle

אם אתם משתמשים ב-Google Mobile Ads SDK בגרסה 19.8.0 ואילך, אפשר לדלג על השלב הזה של Gradle בהתקנה. אחרת, כוללים את ה-UMP SDK ב-build.gradle של האפליקציה באופן הבא:

dependencies {
    // This dependency is automatically included by Google Mobile Ads SDK 19.8.0
    // or higher.
    implementation 'com.google.android.ump:user-messaging-platform:2.0.0'
}

אחרי ביצוע השינויים ב-build.gradle של האפליקציה, חשוב לסנכרן את הפרויקט עם קובצי Gradle.

עדכון המניפסט

בשלב הבא, מוצאים את מזהה האפליקציה ומוסיפים אותו ל-AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.rewardedinterstitialexample">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <!-- Sample app ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

איך קובעים אם צריך להציג הודעה?

עליך לבקש עדכון של פרטי ההסכמה של המשתמשים בכל השקה של האפליקציה, באמצעות requestConsentInfoUpdate() לפני טעינת הטופס. כך נוכל לקבוע אם המשתמש צריך להביע הסכמה אם הוא לא עשה זאת עדיין או אם תוקף ההסכמה שלו פג.

השתמשו במידע שמאוחסן באובייקט consentInformationכשאתם מציגים את הטופס, לפי הצורך.

הנה דוגמה לבדיקת הסטטוס בהפעלת האפליקציה:

Java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.google.android.ump.ConsentForm;
import com.google.android.ump.ConsentInformation;
import com.google.android.ump.ConsentRequestParameters;
import com.google.android.ump.FormError;
import com.google.android.ump.UserMessagingPlatform;

public class MainActivity extends AppCompatActivity {
  private ConsentInformation consentInformation;
  private ConsentForm consentForm;

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

    // Set tag for under age of consent. false means users are not under
    // age.
    ConsentRequestParameters params = new ConsentRequestParameters
        .Builder()
        .setTagForUnderAgeOfConsent(false)
        .build();

    consentInformation = UserMessagingPlatform.getConsentInformation(this);
    consentInformation.requestConsentInfoUpdate(
        this,
        params,
        new ConsentInformation.OnConsentInfoUpdateSuccessListener() {
            @Override
            public void onConsentInfoUpdateSuccess() {
                // The consent information state was updated.
                // You are now ready to check if a form is available.
            }
        },
        new ConsentInformation.OnConsentInfoUpdateFailureListener() {
            @Override
            public void onConsentInfoUpdateFailure(FormError formError) {
                // Handle the error.
            }
        });
  }
}

Kotlin

package com.example.myapplication

import com.google.android.ump.ConsentForm
import com.google.android.ump.ConsentInformation
import com.google.android.ump.ConsentInformation.OnConsentInfoUpdateFailureListener
import com.google.android.ump.ConsentInformation.OnConsentInfoUpdateSuccessListener
import com.google.android.ump.ConsentRequestParameters
import com.google.android.ump.UserMessagingPlatform

class MainActivity : AppCompatActivity() {
  private lateinit var consentInformation: ConsentInformation
  private lateinit var consentForm: ConsentForm

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    // Set tag for under age of consent. false means users are not under
    // age.
    val params = ConsentRequestParameters
        .Builder()
        .setTagForUnderAgeOfConsent(false)
        .build()

    consentInformation = UserMessagingPlatform.getConsentInformation(this)
    consentInformation.requestConsentInfoUpdate(
        this,
        params,
        OnConsentInfoUpdateSuccessListener {
          // The consent information state was updated.
          // You are now ready to check if a form is available.
        },
        OnConsentInfoUpdateFailureListener {
          // Handle the error.
        })
  }
}

טעינת טופס, אם יש כזה

לפני הצגת טופס, עליך לבדוק אם יש טופס זמין. אם הטופס לא זמין, יכול להיות שהמשתמש הפעיל מעקב מוגבל אחרי מודעות או שתייגתם את המשתמש מתחת לגיל ההסכמה.

כדי לבדוק את הזמינות של טופס מסוים, השתמשוthe isConsentFormAvailable() method on the ConsentInformation instance ביצירת הטופס הקודמת.

לאחר מכן מוסיפים שיטת wrapper לטעינת הטופס:

Java

...
    consentInformation.requestConsentInfoUpdate(
        this,
        params,
        new ConsentInformation.OnConsentInfoUpdateSuccessListener() {
          @Override
          public void onConsentInfoUpdateSuccess() {
            // The consent information state was updated.
            // You are now ready to check if a form is available.
            if (consentInformation.isConsentFormAvailable()) {
              loadForm();
            }
          }
        },
        new ConsentInformation.OnConsentInfoUpdateFailureListener() {
          @Override
          public void onConsentInfoUpdateFailure(FormError formError) {
            // Handle the error.
          }
    });
  }

  public void loadForm() {

  }
}

Kotlin

...
    consentInformation.requestConsentInfoUpdate(
        this,
        params,
        OnConsentInfoUpdateSuccessListener {
          // The consent information state was updated.
          // You are now ready to check if a form is available.
          if (consentInformation.isConsentFormAvailable) {
            loadForm()
          }
        },
        OnConsentInfoUpdateFailureListener {
          // Handle the error.
        })
  }

  fun loadForm() {

  }
}

כדי לטעון את הטופס, יש להשתמש ב the static loadConsentForm() method on the UserMessagingPlatform class.

Java

public void loadForm() {
  // Loads a consent form. Must be called on the main thread.
  UserMessagingPlatform.loadConsentForm(
      this,
      new UserMessagingPlatform.OnConsentFormLoadSuccessListener() {
        @Override
        public void onConsentFormLoadSuccess(ConsentForm consentForm) {
          MainActivity.this.consentForm = consentForm;
        }
      },
      new UserMessagingPlatform.OnConsentFormLoadFailureListener() {
        @Override
        public void onConsentFormLoadFailure(FormError formError) {
          // Handle the error.
        }
      }
  );
}

Kotlin

fun loadForm() {
  // Loads a consent form. Must be called on the main thread.
  UserMessagingPlatform.loadConsentForm(
      this,
      UserMessagingPlatform.OnConsentFormLoadSuccessListener {
        this.consentForm = consentForm
      },
      UserMessagingPlatform.OnConsentFormLoadFailureListener {
        // Handle the error.
      }
  )
}

צריך להציג את הטופס אם צריך

אחרי שקובעים את הזמינות וטוענים אותה, משתמשים ב-methodshow() במכונהConsentForm כדי להציג את הטופס.

משתמשים באובייקטconsentInformation הקודם כדי לבדוק את השיטהconsent status ולעדכן את השיטהloadForm() :

Java

public void loadForm() {
  // Loads a consent form. Must be called on the main thread.
  UserMessagingPlatform.loadConsentForm(
      this,
      new UserMessagingPlatform.OnConsentFormLoadSuccessListener() {
        @Override
        public void onConsentFormLoadSuccess(ConsentForm consentForm) {
          MainActivity.this.consentForm = consentForm;
          if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.REQUIRED) {
            consentForm.show(
                MainActivity.this,
                new ConsentForm.OnConsentFormDismissedListener() {
                  @Override
                  public void onConsentFormDismissed(@Nullable FormError formError) {
                    if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.OBTAINED) {
                      // App can start requesting ads.
                    }

                    // Handle dismissal by reloading form.
                    loadForm();
                  }
            });
          }
        }
      },
      new UserMessagingPlatform.OnConsentFormLoadFailureListener() {
        @Override
        public void onConsentFormLoadFailure(FormError formError) {
          // Handle Error.
        }
      }
  );
}

Kotlin

fun loadForm() {
  // Loads a consent form. Must be called on the main thread.
  UserMessagingPlatform.loadConsentForm(
      this,
      UserMessagingPlatform.OnConsentFormLoadSuccessListener {
        this.consentForm = consentForm
        if (consentInformation.consentStatus == ConsentInformation.ConsentStatus.REQUIRED) {
          consentForm.show(
              this,
              ConsentForm.OnConsentFormDismissedListener {
                if (consentInformation.consentStatus == ConsentInformation.ConsentStatus.OBTAINED) {
                  // App can start requesting ads.
                }

                // Handle dismissal by reloading form.
                loadForm()
              }
          )
        }
      },
      UserMessagingPlatform.OnConsentFormLoadFailureListener {
        // Handle the error.
      }
  )
}

אם אתם צריכים לבצע פעולה כלשהי אחרי שהמשתמש בחר או סגר את הטופס, תוכלו לשלב את הלוגיקה הזו ב-handler של ההשלמה או בקריאה החוזרת (callback) של הטופס.

בדיקה

אילוץ מיקום גיאוגרפי

באמצעות UMP SDK תוכלו לבדוק את התנהגות האפליקציה כאילו המכשיר נמצא ב-EEA או בבריטניה באמצעות the setDebugGeography method on ConsentDebugSettings.Builder.

כדי להשתמש בפונקציונליות של ניפוי באגים, צריך לספק את המזהה המגובב של מכשיר הבדיקה בהגדרות של ניפוי הבאגים באפליקציה. אם מפעילים את ההגדרהrequestConsentInfoUpdate() בלי להגדיר את הערך הזה, האפליקציה מתעדת את גיבוב ה-ID הנדרש בזמן ההפעלה.

Java

ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(this)
    .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
    .addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
    .build();

ConsentRequestParameters params = new ConsentRequestParameters
    .Builder()
    .setConsentDebugSettings(debugSettings)
    .build();

consentInformation = UserMessagingPlatform.getConsentInformation(this);
consentInformation.requestConsentInfoUpdate(this,
    params,
    new ConsentInformation.OnConsentInfoUpdateSuccessListener() {
      @Override
      public void onConsentInfoUpdateSuccess() {
        // The consent information state was updated.
        // You are now ready to check if a form is available.
      }
    },
    new ConsentInformation.OnConsentInfoUpdateFailureListener() {
      @Override
      public void onConsentInfoUpdateFailure(FormError formError) {
        // Handle the error.
      }
});

Kotlin

val debugSettings = ConsentDebugSettings.Builder(this)
    .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
    .addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
    .build()

val params = ConsentRequestParameters
    .Builder()
    .setConsentDebugSettings(debugSettings)
    .build()

consentInformation = UserMessagingPlatform.getConsentInformation(this)
    consentInformation.requestConsentInfoUpdate(
        this,
        params,
        OnConsentInfoUpdateSuccessListener {
          // The consent information state was updated.
          // You are now ready to check if a form is available.
        },
        OnConsentInfoUpdateFailureListener {
          // Handle the error.
        })
}

ב- DebugGeography, אפשר לאלץ את המיקומים הגיאוגרפיים לאחת מהאפשרויות הבאות:

DebugGeography תיאור
DEBUG_GEOGRAPHY_DISABLED האפשרות 'מיקום גיאוגרפי של ניפוי באגים' מושבתת.
DEBUG_GEOGRAPHY_EEA המיקום הגיאוגרפי כפי שהוא מופיע ב-EEA עבור מכשירי ניפוי באגים.
DEBUG_GEOGRAPHY_NOT_EEA המיקום הגיאוגרפי לא מופיע ב-EEA עבור מכשירי ניפוי באגים.

הערה: ההגדרות של ניפוי הבאגים פועלות רק במכשירי בדיקה. אין צורך להוסיף אמולטורים לרשימת מזהי המכשירים כי הם כבר מופעלים לבדיקה כברירת מחדל.

כשבודקים את האפליקציה באמצעות UMP SDK, כדאי לאפס את מצב ה-SDK כדי לדמות את חוויית ההתקנה הראשונה של המשתמש. לשם כך, ה-SDK מספק reset() את השיטה.

Java

consentInformation.reset();

Kotlin

consentInformation.reset()

אתם צריכים גם לקרוא ל- reset() אם תחליטו להסיר לגמרי את ה-UMP SDK מהפרויקט.