The Customer Data Platform for Developers
Website · Documentation · Community Slack
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.
- Create a
CustomConsentFilter.h
file by extendingRSConsentFilter
, as shown:
#import <Foundation/Foundation.h>
#import <Rudder/Rudder.h>
NS_ASSUME_NONNULL_BEGIN
@interface CustomConsentFilter : NSObject<RSConsentFilter>
@end
NS_ASSUME_NONNULL_END
- 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
- Create a
CustomConsentFilter
file by extendingRSConsentFilter
, 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
}
}
You can register CustomConsentFilter
with the iOS SDK during the initialization, as shown:
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];
let builder: RSConfigBuilder = RSConfigBuilder()
.withLoglevel(RSLogLevelDebug)
.withDataPlaneUrl(DATA_PLANE_URL)
.withConsentFilter(CustomConsentFilter())
RSClient.getInstance(rudderConfig.WRITE_KEY, config: builder.build())
- Install
RudderOneTrustConsentFilter
by adding the following line to yourPodfile
:
pod 'RudderOneTrustConsentFilter', '~> 1.1.0'
- Import the SDK, as shown:
@import RudderOneTrustConsentFilter;
import RudderOneTrustConsentFilter
- Finally, add the imports to your
AppDelegate
file under thedidFinishLaunchingWithOptions
method:
@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];
}
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. |
---|
This feature is released under the MIT License.