Google Analytics introduces Consent Mode v2, providing a streamlined approach to adjust your SDK's behavior based on user consent status. This feature lets you easily indicate whether consent has been granted for Analytics and Ads cookies. To implement Consent Mode v2 for your apps, follow these straightforward steps:
For more information, see Consent mode on websites and mobile apps.
Consent Types | Consent Mode V2 | InMobi CMP (Web) | Description |
---|---|---|---|
ad_storage |
Mandatory | Supported | Enables storage for advertising, like web cookies or app device identifiers. |
analytics_storage |
Mandatory | Supported | Enables storage for analytics, e.g., visit duration cookies or app device identifiers. |
ad_user_data |
Mandatory | Supported | Consent is required to send user data to Google for online advertising. |
ad_personalization |
Mandatory | Supported | Consents to personalized advertising. |
By default, the Google basic consent feature is disabled within the portal. Enable it manually to activate.
To configure Google Consent Mode, follow the instructions below:
Info.plist
file since no consent mode values are pre-configured by default.
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE</key> <true/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE</key> <true/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA</key> <true/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS</key> <true/>
gbcDelegate
parameter in the startChoice
method to facilitate the retrieval of GBC callbacks.
func startChoice() {
// Use the ChoiceStyle class to set the light and dark themes
let style = ChoiceStyle(preferredThemeMode: .auto, lightThemeStyleSheet: "LightStyleSheet", darkThemeStyleSheet: "DarkStyleSheet")
// Initialise InMobi CMP
ChoiceCmp.shared.startChoice(pcode: "<YOUR PCODE>", delegate: self, gbcDelegate: self, style: style)
}
-(void) startChoice {
// Use the ChoiceStyle class to set the light and dark themes
ChoiceStyle *style = [[ChoiceStyle alloc] initWithPreferredThemeMode: CMPUserInterfaceStyleAuto lightThemeStyleSheet: @"LightStyleSheet" darkThemeStyleSheet:@"DarkStyleSheet"];
// Initialise InMobi CMP
[[ChoiceCmp shared] startChoiceWithPcode:@"<YOUR PCODE>" delegate: self ccpaDelegate: self gbcDelegate: self shouldDisplayIDFA:true style: style];
}
showGoogleBasicConsent(delegate:)
API to present the standalone popup.
func showGoogleConsent() {
// Show Google basic consent
ChoiceCmp.shared.showGoogleBasicConsent(delegate: self)
}
-(void) showGoogleConsent {
// Show Google basic consent
[[ChoiceCmp shared] showGoogleBasicConsentWithDelegate: self];
}
import InMobiCMP
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, ChoiceCmpDelegate, CCPADelegate, GoogleBasicConsentDelegate {
…
}
#import "AppDelegate.h"
@import InMobiCMP;
@interface AppDelegate ()<ChoiceCmpDelegate,CCPADelegate, GoogleBasicConsentDelegate>
@end
didReceiveGoogleBasicConsentChange(consents:)
callback function.
func didReceiveGoogleBasicConsentChange(consents: GoogleBasicConsents) {
print(AdStorage value: \(consents.adStorage)")
print("AdUserData value: \(consents.adUserData)")
print("AdPersonalization value: \(consents.adPersonalization)")
print("AnalyticsStorage value: \(consents.analyticsStorage)")
}
-(void) didReceiveGoogleBasicConsentChangeWithConsents:(GoogleBasicConsents * _Nonnull)consents {
NSLog(@"Ad storage value: %ld", consents.adStorage);
NSLog(@"Ad user data value: %ld", consents.adUserData);
NSLog(@"Ad personalization value: %ld", consents.adPersonalization);
NSLog(@"Analytics storage value: %ld", consents.analyticsStorage);
}
didReceiveGoogleBasicConsentChange(consents: )
callback and set the consent using the setConsent
method of Google’s Analytics API. The callback will be initiated only when you enable Google consent in the portal, and the user gives consent. You will be unable to initiate it during the consecutive app launches.
You must use the setConsent
method to set the consent provided by the callback API as InMobi CMP doesn't automatically set it.
func didReceiveGoogleBasicConsentChange(consents: GoogleBasicConsents) {
Analytics.setConsent([
.analyticsStorage: consents.analyticsStorage == .granted ? .granted : .denied,
.adStorage: consents.adStorage == .granted ? .granted : .denied,
.adUserData: consents.adUserData == .granted ? .granted : .denied,
.adPersonalization: consents.adPersonalization == .granted ? .granted : .denied
])
}
- (void)didReceiveGoogleBasicConsentChangeWithConsents:(GoogleBasicConsents * _Nonnull)consents {
[FIRAnalytics setConsent:@{
FIRConsentTypeAnalyticsStorage :
[consents analyticsStorage] == GoogleBasicConsentValueGranted ? FIRConsentStatusGranted : FIRConsentStatusDenied,
FIRConsentTypeAdStorage :
[consents adStorage] == GoogleBasicConsentValueGranted ? FIRConsentStatusGranted : FIRConsentStatusDenied,
FIRConsentTypeAdUserData :
[consents adUserData] == GoogleBasicConsentValueGranted ? FIRConsentStatusGranted : FIRConsentStatusDenied,
FIRConsentTypeAdPersonalization :
[consents adPersonalization] == GoogleBasicConsentValueGranted ? FIRConsentStatusGranted : FIRConsentStatusDenied,
}];
}
The value set by the setConsent
method persists across app executions and overrides the default values configured through the Info.plist
file. The value remains in that state until you call the setConsent
method again, even if a user closes and reopens the app.
By installing this SDK update, you agree that your Children Privacy Compliance setting remains accurate or that you will update that setting, whenever there is a change in your app's audience. You may update the app's Children Privacy Compliance settings at https://publisher.inmobi.com/my-inventory/app-and-placements.