Wiki

Clone wiki

AATKit iOS / Proposal / CH2

Consent Handling

  1. Getting Started
  2. AATKit Initialisation
  3. Consent Handling
  4. Formats
  5. Targeting
  6. Advanced

Consent Handling

AATKit has 3 types of consent to choose from: AATManagedConsent, AATSimpleConsent or AATVendorConsent

With the introduction of IAB TCF2.0, AddApptr will no longer act as a CMP. Instead, we provide wrappers allowing for easily integrating third-party CMPs. The AATManagedConsent provides the following methods:

  • Init: - (instancetype)initWithDelegate:(nullable NSObject<AATManagedConsentDelegate>*)delegate cmp:(AATCMPProviderObj <AATCMP>*)cmp;, where:
    • cmp - The instance of CMP to be used, currently either AATCMPGoogle or AATCMPOgury.
    • delegate - The delegate that will be notified about CMP events. Must not be null.
  • - (void)showIfNeeded:(UIViewController *)viewController; - Presents the consent screen ONLY if it is required by the used CMP (for example if no user consent has been set yet). It is advised to always call this method when the first app controller is presented.
  • - (void)editConsent:(UIViewController *)viewController; - Presents the consent screen, allowing the user to change consent settings.
  • - (void)reload; - Tells the CMP to reload. Does not need to be used unless some error occurs. You can call this method for example after receiving ManagedConsentDelegate.managedConsentCMPFailedToLoad(ManagedConsent, String) callback.

If you use AATManagedConsent, you should make your class conform to the AATManagedConsentDelegate. If there is no IAB consent string in the NSUserDefaults, -cmpNeedsUI will be called, which will probably happen if the app launches for the first time.

Code example (Swift)

var consent: AATManagedConsent?
extension AppDelegate: AATManagedConsentDelegate {
    func cmpNeedsUI(_ managedConsent: AATManagedConsent) {
        // Get your rootViewController
        self.consent.showIfNeeded(vc)
    }

    func managedConsentCMPFinished(with state: AATManagedConsentState) {
      // The user finished his action with CMP with the state as the user chosen state
    }

    func managedConsentCMPFailed(toLoad managedConsent: AATManagedConsent, error string: String) {
        // CMP failed to loadwith the error message. You may want to to call managedConsent.reload()
    }

    func managedConsentCMPFailed(toShow managedConsent: AATManagedConsent, error string: String) {
        // CMP failed to show with the error message
    }
}
the AATManagedConsentState can be one of the following enum cases:
typedef NS_ENUM(NSInteger, AATManagedConsentState) {
    AATManagedConsentStateUnknown,
    AATManagedConsentStateWithheld,
    AATManagedConsentStateCustom,
    AATManagedConsentStateObtained
};

CMP implementations

Google CMP

For now, we provide two CMP implementations: * Requires appId to be added to Info.plist file, like

<key>GADApplicationIdentifier</key>
<string>YOUR-APP-ID</string>
Code example (Swift)
let cmp = AATCMPGoogle()
var consent: AATManagedConsent?
func configureAATKit() {
    let configuration = AATConfiguration()
    ...
    cmp = AATCMPGoogle()
    consent = AATManagedConsent(delegate: self, cmp: cmp)
    configuration.consent = consent

    AATKit.initialize(with: configuration)
    ...
    self.consent?.showIfNeeded(<YourCurrentController>)
}
Code example (Objective-C)
- (void)configureAATKit {
    AATConfiguration* configuration = [[AATConfiguration alloc] init];
    ...
    self.cmp = [[AATCMPGoogle alloc] init];
    self.consent = [[AATManagedConsent alloc] initWithDelegate:self cmp:self.cmp];
    configuration.consent = self.consent;
    ...
    [AATKit initializeWithConfiguration:configuration];
}

Ogury CMP

  • Requires the Ogury dependency to work by adding the following to your Podfile:

pod 'AATKit/OguryCMP'
* Requires Ogury Asset Key as an initializer parameter Code example (Swift)
func configureAATKit() {
    let configuration = AATConfiguration()
    ...
    cmp = AATCMPOgury(assetKey: "YourAssetKey")
    guard let cmp = cmp else {
        // Shouldn't be nil
    }
    consent = AATManagedConsent(delegate: self, cmp: cmp)
    configuration.consent = consent
    ...

    self.consent?.showIfNeeded(<YourCurrentController>)

}
Code example (Objective-C)
- (void)configureAATKit {
    AATConfiguration* configuration = [[AATConfiguration alloc] init];
    ...

    self.cmp = [[AATCMPOgury alloc] initWithAssetKey:"YourAssetKey"];
    self.consent = [[AATManagedConsent alloc] initWithDelegate:self cmp:self.cmp];
    configuration.consent = self.consent;
    ...
    [AATKit initializeWithConfiguration:configuration];
}

To set if the user has given or withheld consent for the collection and use of personal data (used for non-IAB partners), use AATSimpleConsent default initializer and pass any value of the AATConsent enum

  • AATConsentObtained if the user has given the consent
  • AATConsentWithheld if the user has declined
  • AATConsentUnknown if the user has not set a preference

If AATSimpleConsent is used, it will automatically read the IAB Consent String stored (by third-party CMP) in UserDefaults (if available).

Code example (Swift)

func configureAATKit() {
    let configuration = AATConfiguration()
    ...
    let consent = AATSimpleConsent(nonIABConsent: .obtained)
    configuration.consent = consent
    ...
    AATKit.initialize(with: configuration)
}
Code example (Objective-C)

- (void)configureAATKit {
    AATConfiguration* configuration = [[AATConfiguration alloc] init];
    ...
    AATSimpleConsent *consent = [[AATSimpleConsent alloc] initWithNonIABConsent:AATConsentObtained];
    configuration.consent = consent;
    ...
    [AATKit initializeWithConfiguration:configuration];
}

For publishers not using the ManagedConsent, we have introduced another type of Consent for GDPR-compliance. It can be considered a more advanced version of SimpleConsent, allowing to pass network-specific consent status. To use it, you need to implement the AATVendorConsentDelegate and initialize AATKitConfiguration's consent with a AATVendorConsent instance. It will also automatically read the IAB TCF2.0 Consent String stored (by third-party CMP) in NSUserDefaults (if available). This means that the value returned by getConsentForAddApptr will only be checked if there is no IAB TCF2.0 consent stored.

Code example (Swift)

func configureAATKit() {
    let configuration = AATConfiguration()
    ...
    let consent = AATVendorConsent(vendorConsentDelegate: self)
    configuration.consent = consent
    ...
    AATKit.initialize(with: configuration)
}
// MARK: AATVendorConsentDelegate
func getConsentFor(_ network: AATKitAdNetwork) -> AATConsent {
    //decide for each ad network
    return .obtained
}

func getConsentForAddApptr() -> AATConsent {
    return .obtained
}
Code example (Objective-C)

- (void)configureAATKit {
    AATConfiguration* configuration = [[AATConfiguration alloc] init];
    ...
    AATVendorConsent *consent = [[AATVendorConsent alloc] initWithVendorConsentDelegate:self];
    configuration.consent = consent;
    ...
    [AATKit initializeWithConfiguration:configuration];
}

#pragma mark - AATVendorConsentDelegate
- (AATConsent)getConsentForAddApptr {
    //decide for each ad network
    return AATConsentObtained;
}

- (AATConsent)getConsentForNetwork:(AATKitAdNetwork)network {
    return AATConsentObtained;
}

To make sure AATKit and all the networks use updated consent configuration,It is necessary to reconfigure AATKit every time consent is changed by the user (CMP is closed).

Code example (Objective-C)

AATRuntimeConfiguration* aatRuntimeConfiguration = [[AATRuntimeConfiguration alloc] init];
AATVendorConsent *consent = [[AATVendorConsent alloc] initWithVendorConsentDelegate:self];
aatRuntimeConfiguration.consent = consent;
[AATKit reconfigureUsingConfiguration: aatRuntimeConfiguration];
Code example (Swift)
let aatRuntimeConfiguration = AATRuntimeConfiguration()
let consent = AATVendorConsent(vendorConsentDelegate: self)
aatRuntimeConfiguration.consent = consent
AATKit.reconfigure(using: aatRuntimeConfiguration)

  • AATKit skips rules for AdNetworks in case that the user didn't give consent for that AdNetwork.
  • AATKit skips rules for AdNetworks if the user didn't allow the app for tracking
  • This feature is disabled by default and to enable it: Code example (Swift)

func configureAATKit() {
    let configuration = AATConfiguration()
    ...
    configuration.enableShouldSkipRules(true)
    ...
    AATKit.initialize(with: configuration)
}
Code example (Objective-C)

- (void)configureAATKit {
    AATConfiguration* configuration = [[AATConfiguration alloc] init];
    ...
    [configuration enableShouldSkipRules:YES];
    ...
    [AATKit initializeWithConfiguration:configuration];
}

SampleApp

back (Home)

Updated