Skip to content

rudderlabs/rudder-interceptors-ios

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Customer Data Platform for Developers

Website · Documentation · Community Slack


Consent Management for RudderStack iOS SDK

The RudderOneTrust iOS SDK supports OneTrust consent management from Rudder version 1.10.0.

The RudderStack iOS SDK lets you specify the user's consent during initialization. This readme lists the necessary steps to develop a consent interceptor for the iOS SDK and use it to initialize the SDK once the user gives their consent.

Developing a consent interceptor

Objective C

  1. Create a CustomConsentFilter.h file by extending RSConsentFilter, as shown:
#import <Foundation/Foundation.h>
#import <Rudder/Rudder.h>

NS_ASSUME_NONNULL_BEGIN

@interface CustomConsentFilter : NSObject<RSConsentFilter>

@end

NS_ASSUME_NONNULL_END
  1. Create a CustomConsentFilter.m file, as shown:
#import "CustomConsentFilter.h"

@implementation CustomConsentFilter

- (NSDictionary <NSString *, NSNumber *> * __nullable)filterConsentedDestinations:(NSArray <RSServerDestination *> *)destinations {
    NSDictionary <NSString *, NSNumber *> *filteredConsentedDestinations;
    // Do someting
    return filteredConsentedDestinations;
}

@end

Swift

  1. Create a CustomConsentFilter file by extending RSConsentFilter, as shown:
@objc
open class OneTrustInterceptor: NSObject, RSConsentFilter {
    @objc
    public override init() {
        super.init()
    }

    public func filterConsentedDestinations(_ destinations: [RSServerDestination]) -> [String: NSNumber]? {
        let filteredConsentedDestinations: [String: NSNumber]
        // Do something
        return filteredConsentedDestinations
    }
}

Registering interceptor with iOS SDK

You can register CustomConsentFilter with the iOS SDK during the initialization, as shown:

Objective C

RSConfigBuilder *builder = [[RSConfigBuilder alloc] init];
[builder withLoglevel:RSLogLevelDebug];
[builder withDataPlaneUrl:DATA_PLANE_URL];
[builder withConsentFilter:[[CustomConsentFilter alloc] init]];

[RSClient getInstance:WRITE_KEY config:builder.build];

Swift

let builder: RSConfigBuilder = RSConfigBuilder()
    .withLoglevel(RSLogLevelDebug)
    .withDataPlaneUrl(DATA_PLANE_URL)
    .withConsentFilter(CustomConsentFilter())

RSClient.getInstance(rudderConfig.WRITE_KEY, config: builder.build())

Installing OneTrust consent

  1. Install RudderOneTrustConsentFilter by adding the following line to your Podfile:
pod 'RudderOneTrustConsentFilter', '~> 1.1.0'
  1. Import the SDK, as shown:

Objective C

@import RudderOneTrustConsentFilter;

Swift

import RudderOneTrustConsentFilter
  1. Finally, add the imports to your AppDelegate file under the didFinishLaunchingWithOptions method:

Objective C

@interface AppDelegate ()<OTEventListener>

@end

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[OTPublishersHeadlessSDK shared] startSDKWithStorageLocation:STORAGE_LOCATION domainIdentifier:DOMAIN_IDENTIFIER languageCode:@"en" params:nil loadOffline:NO completionHandler:^(OTResponse *response) {
        if (response.status) {
        
        }
    }];
    
    [[OTPublishersHeadlessSDK shared] addEventListener:self];
}

- (void)initializeRudderSDK {
    RSConfigBuilder *builder = [[RSConfigBuilder alloc] init];
    [builder withLoglevel:RSLogLevelDebug];
    [builder withDataPlaneUrl:DATA_PLANE_URL];
    [builder withConsentFilter:[[RudderOneTrustConsentFilter alloc] init]];

    [RSClient getInstance:rudderConfig.WRITE_KEY config:builder.build];
}

- (void)onPreferenceCenterConfirmChoices {
    [self initializeRudderSDK];
}

Swift

class AppDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        OTPublishersHeadlessSDK.shared.startSDK(
            storageLocation: STORAGE_LOCATION,
            domainIdentifier: DOMAIN_IDENTIFIER,
            languageCode: "en"
        ) { response in
            if response.status {
        
            }
        }
        
        OTPublishersHeadlessSDK.shared.addEventListener(self)
    }
    
    func initializeRudderSDK() {
        let builder: RSConfigBuilder = RSConfigBuilder()
            .withLoglevel(RSLogLevelDebug)
            .withDataPlaneUrl(DATA_PLANE_URL)
            .withConsentFilter(RudderOneTrustConsentFilter())

        RSClient.getInstance(rudderConfig.WRITE_KEY, config: builder.build())
    }
}

extension AppDelegate: OTEventListener {
    func onPreferenceCenterConfirmChoices() {
        initializeRudderSDK()
    }
}
Important: It is recommended to load the SDK only if the user provides their consent.

License

This feature is released under the MIT License.