SDK टूल के लिए Google डेवलपर गाइड देखें:
Google के सहमति मोड के लिए SDK टूल की सुविधाएं
SDK टूल की सभी ज़रूरी शर्तों और उसे लागू करने के बारे में जानने के लिए, इस दस्तावेज़ की शुरुआत में दी गई गाइड देखें. अगर आपने निजता और मैसेजिंग के लिए सहमति मोड की सुविधा चालू की है, तो यहां बताई गई अन्य सुविधाएं भी लागू की जा सकती हैं.
सहमति मोड: बेसिक मोड के साथ काम करना
ज़रूरी SDK टूल लागू करने, निजता और मैसेजिंग में Google सहमति मोड चालू करने, और सहमति मोड के बेसिक वर्शन को लागू करने का फ़ैसला लेने के बाद, इन निर्देशों का पालन करें.
बुनियादी मोड लागू करने के लिए:
- Analytics से डेटा इकट्ठा करने की सुविधा को कुछ समय के लिए बंद करें (Android, iOS).
- Google Analytics की सुविधा को अनब्लॉक करने के लिए, Analytics कलेक्शन (Android, iOS) को फिर से चालू करें.
दूसरे चरण के लिए, किसी कानूनी विशेषज्ञ से सलाह लें. इससे, आपको Analytics की सुविधाओं को फिर से चालू करने की ज़रूरी शर्तें तय करने में मदद मिलेगी.
उदाहरण के लिए, उपयोगकर्ता के सहमति देने के बाद, loadAndShowConsentFormIfRequired
के कॉलबैक में Google Analytics की सुविधा को फिर से चालू करके, Google Analytics की सुविधा को फिर से चालू किया जा सकता है (एपीआई रेफ़रंस:
Android,
iOS).
इसके अलावा, उपयोगकर्ता के सहमति मोड के विकल्पों के आधार पर, Analytics से डेटा इकट्ठा करने की सुविधा को फिर से चालू करना है या नहीं, यह तय करने के लिए UMP_consentModeValues
लोकल स्टोरेज की कुंजी पढ़ें. वैल्यू, चार अंकों की स्ट्रिंग होनी चाहिए.
- पहला अंक, ad_storage के मकसद की वैल्यू दिखाता है
- दूसरा अंक, ad_user_data के मकसद की वैल्यू दिखाता है
- तीसरा अंक, दिलचस्पी के मुताबिक विज्ञापन दिखाने के मकसद की वैल्यू दिखाता है
- चौथा अंक, analytics_storage के मकसद की वैल्यू दिखाता है
नीचे दी गई टेबल में, हर अंक के लिए संभावित वैल्यू के बारे में बताया गया है:
मान | मतलब |
---|---|
0 |
फ़िलहाल, कोई वैल्यू उपलब्ध नहीं है. |
1 |
उपयोगकर्ता GRANTED इस मकसद से. |
2 |
उपयोगकर्ता DENIED इस मकसद से. |
3 |
सहमति मोड, इस उपयोगकर्ता के लिए लागू नहीं होता. |
4 |
सहमति मोड को इस काम के लिए कॉन्फ़िगर नहीं किया गया है. |
नीचे दिया गया उदाहरण, UMP_consentModeValues
को पार्स करता है. अगर सभी मकसद GRANTED
हैं या लागू नहीं हैं, तो Google Analytics को चालू करता है. अगर ऐसा नहीं है, तो Analytics कलेक्शन को बंद करता है:
Java
// Helper function that sets Analytics collection based on the value of the
// UMP_consentModeValues local storage key.
private void maybeReEnableAnalyticsCollection() {
String consentModeValues = sharedPreferences.getString("UMP_consentModeValues", null);
if (shouldReEnableAnalyticsCollection(consentModeValues)) {
firebaseAnalytics.setAnalyticsCollectionEnabled(true);
} else {
firebaseAnalytics.setAnalyticsCollectionEnabled(false);
}
}
// Helper function to determine whether Analytics collection should be enabled. Returns true
// if all consent mode values are either granted, not applicable, or not configured.
private boolean shouldReEnableAnalyticsCollection(String consentModeValues) {
if (consentModeValues.isEmpty()) {
return false;
}
for (int i = 0; i < consentModeValues.length(); i++) {
char consentModeValue = consentModeValues.charAt(i);
switch (consentModeValue) {
case '0':
// Consent mode data not ready yet.
return false;
case 1:
// Consent mode is granted for this purpose.
break;
case '2':
// Consent is denied for this consent mode purpose.
return false;
case '3':
// Consent does not apply for this purpose at this time.
break;
case '4':
// Consent mode is not configured for this purpose.
break;
default:
// Unexpected value encountered.
return false;
}
}
// If all checks pass, re-enable Analytics collection.
return true;
}
Kotlin
// Helper function that may re-enable Analytics collection based on the value of the
// UMP_consentModeValues local storage key.
private fun maybeReEnableAnalyticsCollection() {
val consentModeValues = sharedPreferences.getString("UMP_consentModeValues", null)
if (shouldReEnableAnalyticsCollection(consentModeValues)) {
firebaseAnalytics.setAnalyticsCollectionEnabled(true)
}
}
// Helper function to determine whether Analytics collection should be re-enabled. Returns true
// if all consent mode values are either granted, not applicable, or not configured.
private fun shouldReEnableAnalyticsCollection(consentModeValues: String?): Boolean {
if (consentModeValues.isNullOrEmpty()) {
return false
}
for (consentModeValue in consentModeValues) {
when (consentModeValue) {
'0' -> {
// Consent mode data not ready yet.
return false
}
'1' -> {
// Consent mode is granted for this purpose.
}
'2' -> {
// Consent is denied for this consent mode purpose.
return false
}
'3' -> {
// Consent does not apply for this purpose at this time.
}
'4' -> {
// Consent mode is not configured for this purpose.
}
else -> {
// Unexpected value encountered.
return false
}
}
}
// If all checks pass, can re-enable Analytics collection.
return true
}
Swift
// Helper function that may re-enable Analytics collection based on the value of the
// UMP_consentModeValues local storage key.
private func maybeReEnableAnalyticsCollection() {
let consentModeValues = userDefaults.string(forKey: "UMP_consentModeValues")
if shouldReEnableAnalyticsCollection(consentModeValues) {
Analytics.setAnalyticsCollectionEnabled(true)
}
}
// Helper function to determine whether Analytics collection should be re-enabled. Returns true
// if all consent mode values are either granted, not applicable, or not configured.
private func shouldReEnableAnalyticsCollection(_ consentModeValues: String?) -> Bool {
guard let consentModeValues = consentModeValues, !consentModeValues.isEmpty else {
return false
}
for consentModeValue in consentModeValues {
switch consentModeValue {
case "0":
// Consent mode data not ready yet.
return false
case "1":
// Consent mode is granted for this purpose.
break
case "2":
// Consent is denied for this consent mode purpose.
return false
case "3":
// Consent does not apply for this purpose at this time.
break
case "4":
// Consent mode is not configured for this purpose.
break
default:
// Unexpected value encountered.
return false
}
}
// If all checks pass, can re-enable Analytics collection.
return true
}
Objective-C
// Helper function that may re-enable Analytics collection based on the value of the
// UMP_consentModeValues local storage key.
- (void)maybeReEnableAnalyticsCollection {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *consentModeValues = [defaults stringForKey:@"UMP_consentModeValues"];
if ([self shouldReEnableAnalyticsCollection:consentModeValues]) {
[FIRAnalytics setAnalyticsCollectionEnabled:YES];
}
}
// Helper function to determine whether Analytics collection should be re-enabled. Returns true
// if all consent mode values are either granted, not applicable, or not configured.
- (BOOL)shouldReEnableAnalyticsCollection:(NSString *)consentModeValues {
if (!consentModeValues || [consentModeValues length] == 0) {
return NO;
}
for (NSUInteger i = 0; i < [consentModeValues length]; i++) {
unichar consentModeValue = [consentModeValues characterAtIndex:i];
switch (consentModeValue) {
case '0':
// Consent mode data not ready yet.
return NO;
case '1':
// Consent mode is granted for this purpose.
break;
case '2':
// Consent is denied for this consent mode purpose.
return NO;
case '3':
// Consent does not apply for this purpose at this time.
break;
case '4':
// Consent mode is not configured for this purpose.
break;
default:
// Unexpected value encountered.
return NO;
}
}
// If all checks pass, can re-enable Analytics collection.
return YES;
}
maybeReEnableAnalyticsCollection
को कॉल करें, जब:
- सहमति की जानकारी अपडेट हो जाती है
- सहमति ली जाती है.