Skip to content

Commit

Permalink
onetrust cloud mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabmaiti committed Feb 15, 2023
1 parent 9b4cba4 commit eaa69c4
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
06EABC9224665E480043D720 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 06EABC9024665E480043D720 /* LaunchScreen.storyboard */; };
D55B72537AC03E9A3F7524FA /* Pods_RudderSampleAppSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95FE82D63F0324B1B29DBA09 /* Pods_RudderSampleAppSwift.framework */; };
ED00467228A64DE50007206F /* SessionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED00467128A64DE50007206F /* SessionViewController.swift */; };
EDEAEBC7299CB30200D537C3 /* CustomFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDEAEBC6299CB30200D537C3 /* CustomFilter.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -29,6 +30,7 @@
95FE82D63F0324B1B29DBA09 /* Pods_RudderSampleAppSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RudderSampleAppSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E32C35F6B909BB22A7F0553E /* Pods-RudderSampleAppSwift.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RudderSampleAppSwift.release.xcconfig"; path = "Target Support Files/Pods-RudderSampleAppSwift/Pods-RudderSampleAppSwift.release.xcconfig"; sourceTree = "<group>"; };
ED00467128A64DE50007206F /* SessionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionViewController.swift; sourceTree = "<group>"; };
EDEAEBC6299CB30200D537C3 /* CustomFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomFilter.swift; sourceTree = "<group>"; };
FD4DAD4049ABA2A60254AD71 /* Pods-RudderSampleAppSwift.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RudderSampleAppSwift.debug.xcconfig"; path = "Target Support Files/Pods-RudderSampleAppSwift/Pods-RudderSampleAppSwift.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -73,6 +75,7 @@
06EABC8E24665E480043D720 /* Assets.xcassets */,
06EABC9024665E480043D720 /* LaunchScreen.storyboard */,
06EABC9324665E480043D720 /* Info.plist */,
EDEAEBC6299CB30200D537C3 /* CustomFilter.swift */,
);
path = RudderSampleAppSwift;
sourceTree = "<group>";
Expand Down Expand Up @@ -214,6 +217,7 @@
ED00467228A64DE50007206F /* SessionViewController.swift in Sources */,
06EABC8624665E470043D720 /* AppDelegate.swift in Sources */,
06EABC8824665E470043D720 /* SceneDelegate.swift in Sources */,
EDEAEBC7299CB30200D537C3 /* CustomFilter.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
.withRecordScreenViews(false)
.withSleepTimeOut(4)
.withSessionTimeoutMillis(30000)
// .withConsentFilter(CustomFilter())
RSClient.getInstance("1wvsoF3Kx2SczQNlx1dvcqW9ODW", config: builder.build())


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// CustomFilter.swift
// RudderSampleAppSwift
//
// Created by Pallab Maiti on 15/02/23.
// Copyright © 2023 RudderStack. All rights reserved.
//

import Foundation
import Rudder

class CustomFilter: RSConsentFilter {
func filterConsentedDestinations(_ destinations: [RSServerDestination]) -> [String : NSNumber]? {
return [:]
}

func getConsentCategoriesDict() -> [String : NSNumber]? {
return [:]
}
}
3 changes: 3 additions & 0 deletions Sources/Classes/Public/RSClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ NS_ASSUME_NONNULL_BEGIN
@protocol RSIntegrationFactory;
@protocol RSIntegration;
@class RSConfig;
@class RSMessage;
@class RSContext;
@class RSMessageBuilder;

@interface RSClient : NSObject
+ (instancetype) getInstance;
Expand Down
5 changes: 4 additions & 1 deletion Sources/Classes/Public/RSConsentFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

NS_ASSUME_NONNULL_BEGIN

@class RSServerDestination;
//@class RSServerDestination;

@protocol RSConsentFilter

- (NSDictionary <NSString *, NSNumber *> * __nullable)filterConsentedDestinations:(NSArray <RSServerDestination *> *)destinations;

@optional
- (NSDictionary <NSString *, NSNumber *> * __nullable)getConsentCategoriesDict;

@end

NS_ASSUME_NONNULL_END
6 changes: 5 additions & 1 deletion Sources/Classes/Public/RSConsentFilterHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
#import <Foundation/Foundation.h>
#import "RSServerConfigSource.h"
#import "RSConsentFilter.h"
#import "RSIntegrationFactory.h"
#import "RSMessage.h"

NS_ASSUME_NONNULL_BEGIN

@class RSMessage;
@class RSServerConfigSource;

@interface RSConsentFilterHandler : NSObject {
RSServerConfigSource *serverConfig;
NSDictionary <NSString *, NSNumber *> *consentedIntegrationsDict;
NSArray <NSString *> *deniedConsentIds;
}

+ (instancetype)initiate:(id<RSConsentFilter>)consentFilter withServerConfig:(RSServerConfigSource *)serverConfig;
Expand Down
6 changes: 6 additions & 0 deletions Sources/Classes/Public/RSConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ extern NSString* const EVENT_NAME;
extern NSString *const WRITE_KEY_ERROR;
extern NSString *const DATA_PLANE_URL_ERROR;
extern NSString *const DATA_PLANE_URL_FLUSH_ERROR;

extern int const RSATTNotDetermined;
extern int const RSATTRestricted;
extern int const RSATTDenied;
extern int const RSATTAuthorize;

@end

NS_ASSUME_NONNULL_END
55 changes: 28 additions & 27 deletions Sources/Classes/Public/RSContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,43 @@ NS_ASSUME_NONNULL_BEGIN

@interface RSContext : NSObject <NSCopying> {
RSPreferenceManager *preferenceManager;
NSDictionary<NSString *, NSArray<NSString *> *> * _Nullable consentManagement;
}

extern int const RSATTNotDetermined;
extern int const RSATTRestricted;
extern int const RSATTDenied;
extern int const RSATTAuthorize;

@property (nonatomic, readwrite) RSApp* app;
@property (nonatomic, readwrite) NSMutableDictionary<NSString*, NSObject*>* traits;
@property (nonatomic, readwrite) RSLibraryInfo* library;
@property (nonatomic, readwrite) RSOSInfo* os;
@property (nonatomic, readwrite) RSScreenInfo* screen;
@property (nonatomic, readwrite) NSString* userAgent;
@property (nonatomic, readwrite) NSString* locale;
@property (nonatomic, readwrite) RSDeviceInfo* device;
@property (nonatomic, readwrite) RSNetwork* network;
@property (nonatomic, readwrite) NSString* timezone;
@property (nonatomic, readwrite) NSNumber * _Nullable sessionId;
@property (nonatomic, readwrite) NSMutableDictionary<NSString*, NSObject*> *traits;
@property (nonatomic, readwrite) RSApp *app;
@property (nonatomic, readwrite) RSLibraryInfo *library;
@property (nonatomic, readwrite) RSOSInfo *os;
@property (nonatomic, readwrite) RSScreenInfo *screen;
@property (nonatomic, readwrite) NSString *userAgent;
@property (nonatomic, readwrite) NSString *locale;
@property (nonatomic, readwrite) RSDeviceInfo *device;
@property (nonatomic, readwrite) RSNetwork *network;
@property (nonatomic, readwrite) NSString *timezone;
@property (nonatomic, readwrite) NSNumber *_Nullable sessionId;
@property (nonatomic, readwrite) BOOL sessionStart;
@property (nonatomic, readwrite) NSMutableArray<NSMutableDictionary<NSString*, NSObject*>*>* externalIds;
@property (nonatomic, readwrite) NSMutableArray<NSMutableDictionary<NSString*, NSObject*>*> *externalIds;


+ (dispatch_queue_t) getQueue;
- (NSDictionary<NSString* , NSObject *>*) dict;
- (void) resetTraits;
- (void) updateTraits: (RSTraits* _Nullable) traits;
- (void) persistTraits;
- (void) updateTraitsDict: (NSMutableDictionary<NSString*, NSObject*>*) traitsDict;
- (void) updateTraitsAnonymousId;
- (void) putDeviceToken: (NSString*) deviceToken;
- (void) putAdvertisementId: (NSString *_Nonnull) idfa;
- (void) putAppTrackingConsent: (int) att;
- (void) updateExternalIds: (NSMutableArray* __nullable) externalIds;
- (void) resetExternalIds;
- (void) persistExternalIds;
- (void) setSessionData:(RSUserSession *) userSession;
+ (dispatch_queue_t)getQueue;
- (NSDictionary<NSString *, NSObject *>*)dict;
- (void)resetTraits;
- (void)updateTraits:(RSTraits *_Nullable) traits;
- (void)persistTraits;
- (void)updateTraitsDict:(NSMutableDictionary<NSString*, NSObject*>*)traitsDict;
- (void)updateTraitsAnonymousId;
- (void)putDeviceToken:(NSString*)deviceToken;
- (void)putAdvertisementId:(NSString *_Nonnull)idfa;
- (void)putAppTrackingConsent:(int)att;
- (void)updateExternalIds:(NSMutableArray *__nullable)externalIds;
- (void)resetExternalIds;
- (void)persistExternalIds;
- (void)setSessionData:(RSUserSession *)userSession;
- (void)setConsentData:(NSArray <NSString *> *)deniedConsentIds;

@end

Expand Down
2 changes: 2 additions & 0 deletions Sources/Classes/Public/RSIntegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

NS_ASSUME_NONNULL_BEGIN

@class RSMessage;

@protocol RSIntegration<NSObject>

- (void) dump: (RSMessage*) message;
Expand Down
14 changes: 8 additions & 6 deletions Sources/Classes/Public/RSMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

NS_ASSUME_NONNULL_BEGIN

@class RSContext;

@interface RSMessage : NSObject

@property (atomic, readwrite) NSString* messageId;
Expand All @@ -34,12 +36,12 @@ NS_ASSUME_NONNULL_BEGIN
@property (atomic, readwrite) NSString* destinationProps;
@property (atomic, readwrite) RSOption* option;

- (NSDictionary<NSString*, NSObject*>*) dict;
- (void) updateContext: (RSContext*) context;
- (void) updateTraits: (RSTraits*) traits;
- (void) updateTraitsDict:(NSMutableDictionary<NSString *,NSObject *>*)traits;
- (void) setRudderOption: (RSOption*) option;
- (void) setSessionData:(RSUserSession *) userSession;
- (NSDictionary<NSString*, NSObject*>*)dict;
- (void)updateContext:(RSContext*)context;
- (void)updateTraits:(RSTraits*)traits;
- (void)updateTraitsDict:(NSMutableDictionary<NSString *,NSObject *>*)traits;
- (void)setRudderOption:(RSOption*)option;
- (void)setSessionData:(RSUserSession *)userSession;

@end

Expand Down
1 change: 1 addition & 0 deletions Sources/Classes/Public/RSServerConfigSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import <Foundation/Foundation.h>
#import "RSConfig.h"
#import "RSServerDestination.h"
#import "RSEnums.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down
37 changes: 23 additions & 14 deletions Sources/Classes/RSConsentFilterHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,31 @@ - (instancetype)init:(id<RSConsentFilter>)_consentFilter withServerConfig:(RSSer
}
self->serverConfig = _serverConfig;
[self updateConsentedIntegrationsDict:_consentFilter];
[self updateDeniedConsentIds:_consentFilter];
}
return self;
}

- (void)updateConsentedIntegrationsDict:(id<RSConsentFilter>)consentFilter {
- (void)updateConsentedIntegrationsDict:(id<RSConsentFilter>)_consentFilter {
dispatch_sync(queue, ^{
consentedIntegrationsDict = [consentFilter filterConsentedDestinations:serverConfig.destinations];
consentedIntegrationsDict = [_consentFilter filterConsentedDestinations:serverConfig.destinations];
});
}

- (void)updateDeniedConsentIds:(id<RSConsentFilter>)_consentFilter {
dispatch_sync(queue, ^{
id consentFilter = _consentFilter;
if ([consentFilter respondsToSelector:@selector(getConsentCategoriesDict)]) {
NSMutableArray <NSString *> *_deniedConsentIds = [[NSMutableArray alloc] init];
[[_consentFilter getConsentCategoriesDict] enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSNumber * _Nonnull obj, BOOL * _Nonnull stop) {
if (![obj boolValue]) {
[_deniedConsentIds addObject:key];
}
}];
if (_deniedConsentIds != nil && [_deniedConsentIds count] > 0) {
deniedConsentIds = _deniedConsentIds;
}
}
});
}

Expand All @@ -59,20 +77,11 @@ - (void)updateConsentedIntegrationsDict:(id<RSConsentFilter>)consentFilter {
}

- (RSMessage *)applyConsents:(RSMessage *)message {
if (message.integrations == nil || consentedIntegrationsDict == nil) {
if (deniedConsentIds == nil || [deniedConsentIds count] == 0 || message.context == nil) {
return message;
}
__block RSMessage *updatedMessage = message;
__block NSMutableDictionary <NSString *, NSObject *> *consentedMessageIntegrationsDict = [[NSMutableDictionary alloc] initWithDictionary:message.integrations];
dispatch_sync(queue, ^{
[consentedIntegrationsDict enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSNumber * _Nonnull obj, BOOL * _Nonnull stop) {
if (![obj boolValue]) {
[consentedMessageIntegrationsDict setObject:[NSNumber numberWithBool:false] forKey:key];
}
}];
updatedMessage.integrations = consentedMessageIntegrationsDict;
});
return updatedMessage;
[message.context setConsentData:deniedConsentIds];
return message;
}

@end
6 changes: 6 additions & 0 deletions Sources/Classes/RSConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ @implementation RSConstants
NSString *const WRITE_KEY_ERROR = @"Invalid writeKey: Provided writeKey is empty";
NSString *const DATA_PLANE_URL_ERROR = @"Invalid dataPlaneUrl: The dataPlaneUrl is not provided or given dataPlaneUrl is not valid\n**Note: dataPlaneUrl or dataResidencyServer(for Enterprise Users only) is mandatory from version 1.11.0**";
NSString *const DATA_PLANE_URL_FLUSH_ERROR = @"Invalid dataPlaneUrl: The dataPlaneUrl is not provided or given dataPlaneUrl is not valid. Ignoring flush call. \n**Note: dataPlaneUrl or dataResidencyServer(for Enterprise Users only) is mandatory from version 1.11.0**";

int const RSATTNotDetermined = 0;
int const RSATTRestricted = 1;
int const RSATTDenied = 2;
int const RSATTAuthorize = 3;

@end
19 changes: 11 additions & 8 deletions Sources/Classes/RSContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@
#import "RSUtils.h"
#import "RSLogger.h"
#import "RSClient.h"
#import "RSConstants.h"

@implementation RSContext

int const RSATTNotDetermined = 0;
int const RSATTRestricted = 1;
int const RSATTDenied = 2;
int const RSATTAuthorize = 3;


static dispatch_queue_t queue;

- (instancetype)init
{
- (instancetype)init {
self = [super init];
if (self) {

Expand Down Expand Up @@ -225,6 +219,12 @@ - (void) setSessionData:(RSUserSession *) userSession {
});
}

- (void)setConsentData:(NSArray <NSString *> *)deniedConsentIds {
dispatch_async(queue, ^{
self->consentManagement = @{@"deniedConsentIds": deniedConsentIds};
});
}

- (NSDictionary<NSString *,NSObject *> *)dict {
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
dispatch_sync(queue, ^{
Expand Down Expand Up @@ -252,6 +252,9 @@ - (void) setSessionData:(RSUserSession *) userSession {
[tempDict setObject:@YES forKey:@"sessionStart"];
}
}
if (consentManagement != nil) {
[tempDict setObject:consentManagement forKey:@"consentManagement"];
}
});
return [tempDict copy];
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Classes/RSDeviceInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "RSDeviceInfo.h"
#import "RSContext.h"
#import <UIKit/UIKit.h>
#import "RSConstants.h"
#if TARGET_OS_WATCH
#import <WatchKit/WKInterfaceDevice.h>
#endif
Expand Down
6 changes: 4 additions & 2 deletions Sources/Classes/RSMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ - (instancetype)init

- (void)updateContext:(RSContext *)context {
if (context != nil) {
self.context = context;
_context = context;
}
}

Expand All @@ -95,6 +95,8 @@ - (void)setRudderOption:(RSOption *)option {
}

- (void) setSessionData: (RSUserSession*) userSession {
[_context setSessionData:userSession];
if (_context != nil) {
[_context setSessionData:userSession];
}
}
@end
Loading

0 comments on commit eaa69c4

Please sign in to comment.