iOS

Overview

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:

  • Utilize Google Analytics for Firebase SDK to set default consent values.
  • Employ the setConsent method programmatically to update these values based on in-app user consent.

For more information, see Consent mode on websites and mobile apps.

Consent Types and Impact

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.

Prerequisites

By default, the Google basic consent feature is disabled within the portal. Enable it manually to activate.

Configure Google Consent Mode

  1. Log in to the InMobi CMP portal.
  2. Navigate to your Property settings:
    • For new Apps: Under the Properties tab, click PROTECT AN APP for your sites, and enter all the necessary information. For more information, see Protect An App.
    • For existing Apps: Under the Properties tab and from the list of properties, click the edit icon for the desired site and enter all the information required on the Edit a App page.
  3. In the ENABLE GOOGLE BASIC CONSENT field, select Yes, and a popup window appears.

  4. Select the target location in the WHICH USERS SHOULD BE ASKED FOR CONSENT field.
  5. Select the purpose(s) and default value(s).
  6. Click SAVE PROPERTY.

GBC Implementation

Configure Default Consent Value

To configure Google Consent Mode, follow the instructions below:

  1. To set the default consent state, open your app's Info.plist file since no consent mode values are pre-configured by default.
  2. Add the consent mode key-value pairs. The key describes the consent type, and the value indicates the consent state. You can set the value for the following as true (consent granted) or false (consent denied):
    • GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE
    • GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE
    • GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA
    • GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS
  3. Save your changes and update the consent values similarly as shown below:
    <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/>
    

Update Parameter

  1. Include the gbcDelegate parameter in the startChoice method to facilitate the retrieval of GBC callbacks.

    Swift

    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) 
    }
    
    

    Objective-C

    -(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]; 
    }
    
    
  2. The Google basic consent feature may be included in the GDPR or CCPA popup or displayed independently. Use the showGoogleBasicConsent(delegate:) API to present the standalone popup.

    Swift

    func showGoogleConsent() { 
      // Show Google basic consent 
      ChoiceCmp.shared.showGoogleBasicConsent(delegate: self) 
    }
    
    

    Objective-C

    -(void) showGoogleConsent { 
      // Show Google basic consent 
      [[ChoiceCmp shared] showGoogleBasicConsentWithDelegate: self]; 
    }
    
    
  3. Ensure the appropriate delegate is assigned for the class.

    Swift

    import InMobiCMP 
     
    @UIApplicationMain 
    class AppDelegate: UIResponder, UIApplicationDelegate, ChoiceCmpDelegate, CCPADelegate, GoogleBasicConsentDelegate { 
      … 
    }
    
    

    Objective-C

    #import "AppDelegate.h" 
    @import InMobiCMP; 
     
    @interface AppDelegate ()<ChoiceCmpDelegate,CCPADelegate, GoogleBasicConsentDelegate> 
     
    @end
    
    
  4. Implement didReceiveGoogleBasicConsentChange(consents:) callback function.

    Swift

    func didReceiveGoogleBasicConsentChange(consents: GoogleBasicConsents) { 
      print(AdStorage value: \(consents.adStorage)") 
      print("AdUserData value: \(consents.adUserData)") 
      print("AdPersonalization value: \(consents.adPersonalization)") 
      print("AnalyticsStorage value: \(consents.analyticsStorage)") 
    }
    
    

    Objective-C

    -(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); 
    }
    
    
  5. Update consent using the above callback: The example below demonstrates the functionality of the setConsent method, illustrating the value update for Analytics, Ad storage, Ad user data, and Ad personalization to either granted or denied status. To update the Consent Type, retrieve the consent values from the 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. 

    Note

    You must use the setConsent method to set the consent provided by the callback API as InMobi CMP doesn't automatically set it.

    Swift

    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 
            ]) 
        }
    
    

    Objective-C

    - (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.

On This Page

Last Updated on: 28 Mar, 2024