Google User Messaging Platform (UMP) SDK הוא כלי לניהול פרטיות והודעות שיעזור לכם לנהל את העדפות הפרטיות של המשתמשים. מידע נוסף זמין במאמר בנושא הכלי 'פרטיות והודעות'.
יצירת סוג הודעה
יוצרים הודעות למשתמשים באמצעות אחד מסוגי ההודעות למשתמשים שזמינים בכרטיסייה פרטיות והודעות בחשבון Ad Manager. UMP SDK מנסה להציג הודעה בנושא פרטיות שנוצרה ממזהה האפליקציה ב-Ad Manager שהוגדר בפרויקט.
פרטים נוספים מופיעים במאמר בנושא פרטיות והודעות.
קבלת מידע על הסכמת המשתמש
צריך לבקש עדכון של פרטי ההסכמה של המשתמש בכל הפעלה של האפליקציה באמצעות Update()
. הבקשה הזו בודקת את הדברים הבאים:
- האם נדרשת הסכמה. לדוגמה, נדרשת הסכמה בפעם הראשונה, או שההחלטה הקודמת לגבי הסכמה פגה.
- האם נדרשת נקודת כניסה לאפשרויות הפרטיות. חלק מההודעות בנושא פרטיות מחייבות את האפליקציות לאפשר למשתמשים לשנות את אפשרויות הפרטיות שלהם בכל שלב.
void Start()
{
// Create a ConsentRequestParameters object.
ConsentRequestParameters request = new ConsentRequestParameters();
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
void OnConsentInfoUpdated(FormError consentError)
{
// If the error is null, the consent information state was updated.
if (consentError != null)
{
// Handle the error.
UnityEngine.Debug.LogError(consentError);
return;
}
}
טעינה והצגה של טופס הודעת הפרטיות
אחרי שמתקבל מצב ההסכמה העדכני ביותר, צריך להתקשר אל
LoadAndShowConsentFormIfRequired()
כדי לטעון את הטפסים שנדרשים לאיסוף הסכמה מהמשתמשים. אחרי הטעינה, הטפסים מוצגים מיד.
void Start()
{
// Create a ConsentRequestParameters object.
ConsentRequestParameters request = new ConsentRequestParameters();
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
void OnConsentInfoUpdated(FormError consentError)
{
if (consentError != null)
{
// Handle the error.
UnityEngine.Debug.LogError(consentError);
return;
}
// If the error is null, the consent information state was updated.
// You are now ready to check if a form is available.
ConsentForm.LoadAndShowConsentFormIfRequired((FormError formError) =>
{
if (formError != null)
{
// Consent gathering failed.
UnityEngine.Debug.LogError(consentError);
return;
}
// Consent has been gathered.
});
}
אפשרויות פרטיות
חלק מהטפסים של ההודעות בנושא פרטיות מוצגים מנקודת כניסה לאפשרויות הפרטיות שמוצגת על ידי בעל התוכן הדיגיטלי, ומאפשרים למשתמשים לנהל את אפשרויות הפרטיות שלהם בכל שלב. מידע נוסף על ההודעה שתוצג למשתמשים בנקודת הכניסה לאפשרויות הפרטיות זמין במאמר הסוגים הזמינים של הודעות למשתמשים.
כדי להטמיע נקודת כניסה לאפשרויות הפרטיות, צריך לבצע את השלבים הבאים:
- אחרי שמתקשרים אל
Update()
, בודקים אתPrivacyOptionsRequirementStatus
כדי לדעת אם נדרשת נקודת כניסה לאפשרויות הפרטיות. - אם נדרש, מוסיפים לאפליקציה רכיב בממשק המשתמש שגלוי למשתמשים ושאפשר לקיים איתו אינטראקציה, כדי שישמש כנקודת כניסה לאפשרויות הפרטיות. אם לא נדרשת נקודת כניסה להגדרות הפרטיות, צריך להגדיר את רכיב ממשק המשתמש כך שלא יהיה גלוי ולא ניתן יהיה לקיים איתו אינטראקציה.
- מציגים את טופס אפשרויות הפרטיות באמצעות
ShowPrivacyOptionsForm()
.
בדוגמה הבאה של קוד אפשר לראות את השלבים האלה:
[SerializeField, Tooltip("Button to show the privacy options form.")]
private Button _privacyButton;
private void Start()
{
// Enable the privacy settings button.
if (_privacyButton != null)
{
_privacyButton.onClick.AddListener(UpdatePrivacyButton);
// Disable the privacy settings button by default.
_privacyButton.interactable = false;
}
}
/// <summary>
/// Shows the privacy options form to the user.
/// </summary>
public void ShowPrivacyOptionsForm()
{
Debug.Log("Showing privacy options form.");
ConsentForm.ShowPrivacyOptionsForm((FormError showError) =>
{
if (showError != null)
{
Debug.LogError("Error showing privacy options form with error: " + showError.Message);
}
// Enable the privacy settings button.
UpdatePrivacyButton();
});
}
/// <summary>
/// Updates the privacy buttons visual state based on the consent information.
/// </summary>
void UpdatePrivacyButton()
{
if (_privacyButton != null)
{
_privacyButton.interactable =
ConsentInformation.PrivacyOptionsRequirementStatus ==
PrivacyOptionsRequirementStatus.Required;
}
}
בקשת מודעות עם הסכמת משתמשים
לפני ששולחים בקשות להצגת מודעות, משתמשים ב-
CanRequestAds()
כדי לבדוק אם קיבלתם הסכמה מהמשתמש:
אלה המקומות שבהם אפשר לבדוק אם אפשר לבקש הצגת מודעות בזמן איסוף הסכמה:
- אחרי ש-UMP SDK אוסף הסכמה בסשן הנוכחי.
- מיד אחרי שמתקשרים אל
Update()
. יכול להיות ש-UMP SDK קיבל הסכמה בסשן הקודם באפליקציה.
אם מתרחשת שגיאה במהלך תהליך איסוף ההסכמה, צריך לבדוק אם אפשר לשלוח בקשות להצגת מודעות. UMP SDK משתמש בסטטוס ההסכמה מהסשן הקודם באפליקציה.
void Start()
{
// Create a ConsentRequestParameters object.
ConsentRequestParameters request = new ConsentRequestParameters();
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
void OnConsentInfoUpdated(FormError consentError)
{
if (consentError != null)
{
// Handle the error.
UnityEngine.Debug.LogError(consentError);
return;
}
// If the error is null, the consent information state was updated.
// You are now ready to check if a form is available.
ConsentForm.LoadAndShowConsentFormIfRequired((FormError formError) =>
{
if (formError != null)
{
// Consent gathering failed.
UnityEngine.Debug.LogError(consentError);
return;
}
// Consent has been gathered.
if (ConsentInformation.CanRequestAds())
{
MobileAds.Initialize((InitializationStatus initstatus) =>
{
// TODO: Request an ad.
});
}
});
}
בדיקה
אם אתם רוצים לבדוק את השילוב באפליקציה במהלך הפיתוח, אתם יכולים לבצע את השלבים הבאים כדי לרשום את מכשיר הבדיקה באופן אוטומטי. חשוב להסיר את הקוד שמגדיר את מזהי מכשירי הבדיקה האלה לפני שמשחררים את האפליקציה.
- התקשרו אל
Update()
. בודקים את פלט היומן ומחפשים הודעה שדומה לדוגמה הבאה, שבה מוצג מזהה המכשיר והסבר איך להוסיף אותו כמכשיר בדיקה:
Android
Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
iOS
<UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[2077ef9a63d2b398840261c8221a0c9b]
מעתיקים את מזהה מכשיר הבדיקה ללוח.
משנים את הקוד כדי לקרוא ל-
DebugGeography.TestDeviceHashedIds
ולהעביר רשימה של מזהי מכשירי הבדיקה.void Start() { var debugSettings = new ConsentDebugSettings { TestDeviceHashedIds = new List<string> { "TEST-DEVICE-HASHED-ID" } }; // Create a ConsentRequestParameters object. ConsentRequestParameters request = new ConsentRequestParameters { ConsentDebugSettings = debugSettings, }; // Check the current consent information status. ConsentInformation.Update(request, OnConsentInfoUpdated); }
אילוץ של מיקום גיאוגרפי
באמצעות UMP SDK אפשר לבדוק את אופן הפעולה של האפליקציה במקרה שבו המכשיר נמצא באזורים שונים, כמו EEA או בריטניה, באמצעות DebugGeography
. הערה: הגדרות ניפוי הבאגים פועלות רק במכשירי בדיקה.
void Start()
{
var debugSettings = new ConsentDebugSettings
{
// Geography appears as in EEA for debug devices.
DebugGeography = DebugGeography.EEA,
TestDeviceHashedIds = new List<string>
{
"TEST-DEVICE-HASHED-ID"
}
};
// Create a ConsentRequestParameters object.
ConsentRequestParameters request = new ConsentRequestParameters
{
ConsentDebugSettings = debugSettings,
};
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
איפוס מצב ההסכמה
כשבודקים את האפליקציה באמצעות ה-UMP SDK, יכול להיות שיהיה שימושי לאפס את מצב ה-SDK כדי לדמות את חוויית ההתקנה הראשונית של המשתמש.
ה-SDK מספק את ה-method Reset()
כדי לעשות את זה.
ConsentInformation.Reset();
דוגמאות ב-GitHub
דוגמה מלאה לשילוב של UMP SDK שמוסבר בדף הזה זמינה ב-HelloWorld.