Share GDPR consent with ironSource SDK when using Google’s CMP (7.6.0 and below)

This article is relevant to publishers using ironSource SDK 7.6.0 and below, when implementing GDPR consent from the Google UMP and CMPs that support Google’s Additional Consent  

When using SDK 7.7.0, please refer to this article.

1. Configure ironSource in Google’s Privacy & Messaging  for GDPR

Go to the Google AdMob platform  and add “ironSource Mobile” to the custom ad partners in your GDPR Privacy & messaging configuration. Learn more here.  

Once added, your app’s users will be able to provide consent for the ironSource SDK, as part of their GDPR consent process.  

2. How to share consent with ironSource SDK

Once you’ve completed step 1, you’ll need to share the consent collected by the Google CMP with the ironSource SDK before initialization. 

Here’s how: 

  1. Read the additional consent string ( IABTCF_AddtlConsent), as stored in NSUserDefaults (iOS) and SharedPreferences (Android).
    There will be three slices if the AC version is “2”, or two slices if it is “1”. Example for output:  1~1.3.45.2878, 2~1.3.45.2878~dv.
  2. If the string in the second slice contains the ironSource Mobile identifier 2878, report SetConsent as “true” to ironSource SDK. If the string doesn’t contain the identifier share the value False: See how to report it for Android | iOS | Unity.

    Please note that this will trigger LevelPlay to set the consent as “true” also for all the supported mediated third party networks. For more details on how consent should be set for the ironSource SDK, please review this article.

    Code samples 

    Android

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String myConsent = prefs.getString("IABTCF_AddtlConsent", "");
    if (!myConsent.equals("")) {
        String[] consentSlices = myConsent.split("~");
        String version = consentSlices[0];
        if (consentSlices.length >= 2) {
            if (version.equals("2") || version.equals("1")) {
                if (consentSlices[1].contains("2878")) {
                    IronSource.setConsent(true);
                } else {
                    IronSource.setConsent(false);
                }
            }
        } else {
            // The consent string is not recognizable.
            // The publishers have two options:
            // a) set consent to false and initialize
            // IronSource.setConsent(false);
            // b) Do not initialize IronSource SDK
        }
    } else {
        // The same condition as above
        // The consent string is not recognizable
    }
    

    iOS

    NSString *CMPString= [[NSUserDefaults standardUserDefaults] objectForKey:@"IABTCF_AddtlConsent"];
    if (CMPString != nil) {
        NSArray *CMPSlices = [CMPString componentsSeparatedByString:@"~"];
        int arrCnt = [CMPSlices count];
        NSString *versionNum = [CMPSlices firstObject];
        if (arrCnt >= 2) {
            if ([versionNum isEqual:@"2"] || [versionNum isEqual:@"1"]) {
                NSString *consented = CMPSlices[1];
                if ([consented rangeOfString:@"2878"].location == NSNotFound) {
                    [IronSource setConsent:false];
                } else {
                    [IronSource setConsent:true];
                }
            } 
        } else {
            // The consent string is not recognizable.
            // The publishers have two options:
            // a) set consent to false and initialize
            // IronSource.setConsent(false);
            // b) Do not initialize IronSource SDK
        }
    } else {
        // The same condition as above
        // The consent string is not recognizable
    }
    

    Unity

    string CMPString = PlayerPrefs.GetString("IABTCF_AddtlConsent");
    if (!string.IsNullOrEmpty(CMPString)) {
        string[] CMPSlices = CMPString.Split("~");
        if (CMPSlices.Length >= 2) {
            string version = CMPSlices[0];
            if (version == "2" || version == "1") {
                if (CMPSlices[1].Contains("2878"))
                {
                    IronSource.Agent.setConsent(true);
                }
                else
                {
                    IronSource.Agent.setConsent(false);
                }
            }
        } else {
            // The consent string is not recognizable.
            // The publishers have two options:
            // a) set consent to false and initialize
            // IronSource.setConsent(false);
            // b) Do not initialize IronSource SDK
        }
    } else {
        // The same condition as above
        // The consent string is not recognizable
    }