An open API service indexing awesome lists of open source software.

https://github.com/rudderlabs/rudder-interceptors-ios

Consent interceptor for the RudderStack iOS SDK
https://github.com/rudderlabs/rudder-interceptors-ios

ios rudderstack

Last synced: about 1 month ago
JSON representation

Consent interceptor for the RudderStack iOS SDK

Awesome Lists containing this project

README

          





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](https://www.rudderstack.com/docs/sources/event-streams/sdks/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:

```objectivec
#import
#import

NS_ASSUME_NONNULL_BEGIN

@interface CustomConsentFilter : NSObject

@end

NS_ASSUME_NONNULL_END
```

2. Create a `CustomConsentFilter.m` file, as shown:

```objectivec
#import "CustomConsentFilter.h"

@implementation CustomConsentFilter

- (NSDictionary * __nullable)filterConsentedDestinations:(NSArray *)destinations {
NSDictionary *filteredConsentedDestinations;
// Do someting
return filteredConsentedDestinations;
}

@end
```

### Swift

1. Create a `CustomConsentFilter` file by extending `RSConsentFilter`, as shown:

```swift
@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

```objectivec
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

```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`:

```ruby
pod 'RudderOneTrustConsentFilter', '~> 1.1.0'
```

2. Import the SDK, as shown:

#### Objective C

```objectivec
@import RudderOneTrustConsentFilter;
```

#### Swift

```swift
import RudderOneTrustConsentFilter
```

3. Finally, add the imports to your `AppDelegate` file under the `didFinishLaunchingWithOptions` method:

#### Objective C

```objectivec
@interface AppDelegate ()

@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

```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**](https://opensource.org/licenses/MIT).