Skip to content

Commit

Permalink
GDPR fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Pallab Maiti committed Aug 2, 2022
1 parent a0c898a commit e963e5c
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 75 deletions.
14 changes: 8 additions & 6 deletions Examples/SampleSwift-iOS/SampleSwift-iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
/// Create a `Configuration.json` file on root directory. The JSON should be look like:
/// {
/// "WRITE_KEY": "WRITE_KEY_VALUE",
/// "DATA_PLANE_URL": "DATA_PLANE_URL_VALUE",
/// "DATA_PLANE_URL_LOCAL": "DATA_PLANE_URL_LOCAL_VALUE",
/// "DATA_PLANE_URL_PROD": "DATA_PLANE_URL_PROD_VALUE",
/// "CONTROL_PLANE_URL": "CONTROL_PLANE_URL_VALUE"
/// }

Expand All @@ -30,7 +31,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let configuration = try JSONDecoder().decode(Configuration.self, from: jsonData)

let config: RSConfig = RSConfig(writeKey: configuration.WRITE_KEY)
.dataPlaneURL(configuration.DATA_PLANE_URL)
.dataPlaneURL(configuration.DATA_PLANE_URL_LOCAL)
.loglevel(.verbose)
.trackLifecycleEvents(false)
.recordScreenViews(false)
Expand All @@ -39,7 +40,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
RSClient.sharedInstance().configure(with: config)
RSClient.sharedInstance().addDestination(CustomDestination())

let option = RSOption()
/*let option = RSOption()
option.putExternalId("key-1", withId: "value-1")
option.putExternalId("key-2", withId: "value-2")
option.putExternalId("key-3", withId: "value-3")
Expand Down Expand Up @@ -69,7 +70,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}


/*RSClient.sharedInstance().track("sample_track_1")
RSClient.sharedInstance().track("sample_track_1")
RSClient.sharedInstance().setDeviceToken("device_token_1")
RSClient.sharedInstance().identify("user_id_1", traits: ["name": "Pallab", "email": "[email protected]", "age": 79])
RSClient.sharedInstance().setDeviceToken("device_token_2")
Expand Down Expand Up @@ -123,7 +124,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

struct Configuration: Codable {
let DATA_PLANE_URL: String
let CONTROL_PLANE_URL: String
let WRITE_KEY: String
let DATA_PLANE_URL_LOCAL: String
let DATA_PLANE_URL_PROD: String
let CONTROL_PLANE_URL: String
}
36 changes: 34 additions & 2 deletions Examples/SampleSwift-iOS/SampleSwift-iOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ class ViewController: UIViewController {
Task(name: "Screen without properties"),
Task(name: "Screen with properties"),
Task(name: "Multiple Track, Screen, Alias, Group, Identify"),
Task(name: "Multiple Track, Screen, Alias, Group, Identify, Device Token, AnonymousId, AdvertisingId, AppTracking Consent")]
Task(name: "Multiple Track, Screen, Alias, Group, Identify, Device Token, AnonymousId, AdvertisingId, AppTracking Consent"),
Task(name: "Opt In"),
Task(name: "Opt Out"),
Task(name: "Set AnonymousId"),
Task(name: "Set Device Token"),
Task(name: "Set AdvertisingId"),
Task(name: "Set Option")]

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -233,7 +239,33 @@ extension ViewController: UITableViewDataSource, UITableViewDelegate {
}
}
}

case 11:
RSClient.sharedInstance().setOptOutStatus(false)
case 12:
RSClient.sharedInstance().setOptOutStatus(true)
case 13:
RSClient.sharedInstance().setAnonymousId("anonymous_id_1")
case 14:
RSClient.sharedInstance().setDeviceToken("device_token_1")
case 15:
RSClient.sharedInstance().setAdvertisingId("advertising_id_1")
case 16:
let option = RSOption()
option.putExternalId("key-1", withId: "value-1")
option.putExternalId("key-2", withId: "value-2")
option.putExternalId("key-3", withId: "value-3")
option.putExternalId("key-4", withId: "value-4")

option.putIntegration("key-5", isEnabled: true)
option.putIntegration("key-6", isEnabled: true)
option.putIntegration("key-7", isEnabled: true)
option.putIntegration("key-8", isEnabled: false)

option.putCustomContext(["Key-01": "value-1"], withKey: "key-9")
option.putCustomContext(["Key-02": "value-1"], withKey: "key-10")
option.putCustomContext(["Key-03": "value-1"], withKey: "key-11")
option.putCustomContext(["Key-04": "value-1"], withKey: "key-12")
RSClient.sharedInstance().setOption(option)
default:
break
}
Expand Down
4 changes: 0 additions & 4 deletions Rudder.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
ED157C4B27CFE86100F22202 /* RSAppTrackingConsent.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED157C4A27CFE86100F22202 /* RSAppTrackingConsent.swift */; };
ED157C4D27D0A63A00F22202 /* RSiOSScreenViewEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED157C4C27D0A63A00F22202 /* RSiOSScreenViewEvents.swift */; };
ED157C4F27D0AC0E00F22202 /* RSwatchOSScreenViewEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED157C4E27D0AC0E00F22202 /* RSwatchOSScreenViewEvents.swift */; };
ED157C5427D0CA6900F22202 /* RSGDPRPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED157C5327D0CA6900F22202 /* RSGDPRPlugin.swift */; };
ED157C5627D0FCDC00F22202 /* RSmacOSScreenViewEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED157C5527D0FCDC00F22202 /* RSmacOSScreenViewEvents.swift */; };
ED157C5827D0FFA400F22202 /* RSLifeCycle.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED157C5727D0FFA400F22202 /* RSLifeCycle.swift */; };
ED157C5A27D1010D00F22202 /* RSPushNotifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED157C5927D1010D00F22202 /* RSPushNotifications.swift */; };
Expand Down Expand Up @@ -98,7 +97,6 @@
ED157C4A27CFE86100F22202 /* RSAppTrackingConsent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RSAppTrackingConsent.swift; sourceTree = "<group>"; };
ED157C4C27D0A63A00F22202 /* RSiOSScreenViewEvents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RSiOSScreenViewEvents.swift; sourceTree = "<group>"; };
ED157C4E27D0AC0E00F22202 /* RSwatchOSScreenViewEvents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RSwatchOSScreenViewEvents.swift; sourceTree = "<group>"; };
ED157C5327D0CA6900F22202 /* RSGDPRPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RSGDPRPlugin.swift; sourceTree = "<group>"; };
ED157C5527D0FCDC00F22202 /* RSmacOSScreenViewEvents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RSmacOSScreenViewEvents.swift; sourceTree = "<group>"; };
ED157C5727D0FFA400F22202 /* RSLifeCycle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RSLifeCycle.swift; sourceTree = "<group>"; };
ED157C5927D1010D00F22202 /* RSPushNotifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RSPushNotifications.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -230,7 +228,6 @@
isa = PBXGroup;
children = (
ED3D227C27A3F0C100EC8366 /* RSContextPlugin.swift */,
ED157C5327D0CA6900F22202 /* RSGDPRPlugin.swift */,
ED157C4427CFD99700F22202 /* RSIntegrationPlugin.swift */,
ED3D227827A3F0C100EC8366 /* RSLoggerPlugin.swift */,
ED3D227A27A3F0C100EC8366 /* RSReplayQueuePlugin.swift */,
Expand Down Expand Up @@ -677,7 +674,6 @@
EDA7EF9C2739119600E73142 /* RSDestination.swift in Sources */,
ED3D229C27A3F0C100EC8366 /* RSiOSDelegation.swift in Sources */,
ED3D229A27A3F0C100EC8366 /* RSwatchOSLifecycleMonitor.swift in Sources */,
ED157C5427D0CA6900F22202 /* RSGDPRPlugin.swift in Sources */,
EDA7EF8A2739119600E73142 /* RSUtils.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
50 changes: 0 additions & 50 deletions Sources/Classes/Client/Plugins/RSGDPRPlugin.swift

This file was deleted.

1 change: 0 additions & 1 deletion Sources/Classes/Client/RSClient+Plugins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ extension RSClient {

add(plugin: RSIntegrationPlugin())
add(plugin: RudderDestinationPlugin())
add(plugin: RSGDPRPlugin())

if let platformPlugins = platformPlugins() {
for plugin in platformPlugins {
Expand Down
85 changes: 80 additions & 5 deletions Sources/Classes/Client/RSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ open class RSClient: NSObject {

extension RSClient {
internal func _track(_ eventName: String, properties: TrackProperties? = nil, option: RSOption? = nil) {
if let optOutStatus: Bool = userDefaults.read(.optStatus), optOutStatus == true {
log(message: "User has been Opted out, hence dropping the event", logLevel: .debug)
return
}
guard eventName.isNotEmpty else {
log(message: "eventName can not be empty", logLevel: .warning)
return
Expand All @@ -238,6 +242,10 @@ extension RSClient {
}

internal func _screen(_ screenName: String, category: String? = nil, properties: ScreenProperties? = nil, option: RSOption? = nil) {
if let optOutStatus: Bool = userDefaults.read(.optStatus), optOutStatus == true {
log(message: "User has been Opted out, hence dropping the event", logLevel: .debug)
return
}
guard screenName.isNotEmpty else {
log(message: "screenName can not be empty", logLevel: .warning)
return
Expand All @@ -253,6 +261,10 @@ extension RSClient {
}

internal func _group(_ groupId: String, traits: [String: String]? = nil, option: RSOption? = nil) {
if let optOutStatus: Bool = userDefaults.read(.optStatus), optOutStatus == true {
log(message: "User has been Opted out, hence dropping the event", logLevel: .debug)
return
}
guard groupId.isNotEmpty else {
log(message: "groupId can not be empty", logLevel: .warning)
return
Expand All @@ -263,6 +275,10 @@ extension RSClient {
}

internal func _alias(_ newId: String, option: RSOption? = nil) {
if let optOutStatus: Bool = userDefaults.read(.optStatus), optOutStatus == true {
log(message: "User has been Opted out, hence dropping the event", logLevel: .debug)
return
}
guard newId.isNotEmpty else {
log(message: "newId can not be empty", logLevel: .warning)
return
Expand All @@ -280,6 +296,10 @@ extension RSClient {
}

internal func _identify(_ userId: String, traits: IdentifyTraits? = nil, option: RSOption? = nil) {
if let optOutStatus: Bool = userDefaults.read(.optStatus), optOutStatus == true {
log(message: "User has been Opted out, hence dropping the event", logLevel: .debug)
return
}
guard userId.isNotEmpty else {
log(message: "userId can not be empty", logLevel: .warning)
return
Expand All @@ -305,6 +325,10 @@ extension RSClient {
*/
@objc
public var anonymousId: String? {
if let optOutStatus: Bool = userDefaults.read(.optStatus), optOutStatus == true {
log(message: "User has been Opted out", logLevel: .debug)
return nil
}
return userDefaults.read(.anonymousId)
}

Expand All @@ -313,6 +337,10 @@ extension RSClient {
*/
@objc
public var userId: String? {
if let optOutStatus: Bool = userDefaults.read(.optStatus), optOutStatus == true {
log(message: "User has been Opted out", logLevel: .debug)
return nil
}
return userDefaults.read(.userId)
}

Expand All @@ -321,6 +349,10 @@ extension RSClient {
*/
@objc
public var context: MessageContext? {
if let optOutStatus: Bool = userDefaults.read(.optStatus), optOutStatus == true {
log(message: "User has been Opted out", logLevel: .debug)
return nil
}
let context: JSON? = userDefaults.read(.context)
return context?.dictionaryValue
}
Expand All @@ -330,6 +362,10 @@ extension RSClient {
*/
@objc
public var traits: MessageTraits? {
if let optOutStatus: Bool = userDefaults.read(.optStatus), optOutStatus == true {
log(message: "User has been Opted out", logLevel: .debug)
return nil
}
let traits: MessageTraits? = userDefaults.read(.traits)
return traits
}
Expand Down Expand Up @@ -373,6 +409,10 @@ extension RSClient {
*/
@objc
public var configuration: RSConfig? {
if let optOutStatus: Bool = userDefaults.read(.optStatus), optOutStatus == true {
log(message: "User has been Opted out", logLevel: .debug)
return nil
}
return config
}
}
Expand Down Expand Up @@ -430,11 +470,15 @@ extension RSClient {
- anonymousId: Unique identifier of every event
# Example #
```
client.setAnonymousId("sample_anonymous_id")
RSClient.sharedInstance().setAnonymousId("sample_anonymous_id")
```
*/
@objc
public func setAnonymousId(_ anonymousId: String) {
if let optOutStatus: Bool = userDefaults.read(.optStatus), optOutStatus == true {
log(message: "User has been Opted out", logLevel: .debug)
return
}
guard anonymousId.isNotEmpty else {
log(message: "anonymousId can not be empty", logLevel: .warning)
return
Expand All @@ -451,11 +495,15 @@ extension RSClient {
let defaultOption = RSOption()
defaultOption.putIntegration("Amplitude", isEnabled: true)

client.setOption(defaultOption)
RSClient.sharedInstance().setOption(defaultOption)
```
*/
@objc
public func setOption(_ option: RSOption) {
if let optOutStatus: Bool = userDefaults.read(.optStatus), optOutStatus == true {
log(message: "User has been Opted out", logLevel: .debug)
return
}
RSSessionStorage.shared.write(.option, value: option)
}

Expand All @@ -465,11 +513,15 @@ extension RSClient {
- token: Token of the device
# Example #
```
client.setDeviceToken("sample_device_token")
RSClient.sharedInstance().setDeviceToken("sample_device_token")
```
*/
@objc
public func setDeviceToken(_ token: String) {
if let optOutStatus: Bool = userDefaults.read(.optStatus), optOutStatus == true {
log(message: "User has been Opted out", logLevel: .debug)
return
}
guard token.isNotEmpty else {
log(message: "token can not be empty", logLevel: .warning)
return
Expand All @@ -483,11 +535,15 @@ extension RSClient {
- advertisingId: IDFA value
# Example #
```
client.setAdvertisingId("sample_advertising_id")
RSClient.sharedInstance().setAdvertisingId("sample_advertising_id")
```
*/
@objc
public func setAdvertisingId(_ advertisingId: String) {
if let optOutStatus: Bool = userDefaults.read(.optStatus), optOutStatus == true {
log(message: "User has been Opted out", logLevel: .debug)
return
}
guard advertisingId.isNotEmpty else {
log(message: "advertisingId can not be empty", logLevel: .warning)
return
Expand All @@ -503,11 +559,30 @@ extension RSClient {
- appTrackingConsent: App tracking consent
# Example #
```
client.setAppTrackingConsent(.authorize)
RSClient.sharedInstance().setAppTrackingConsent(.authorize)
```
*/
@objc
public func setAppTrackingConsent(_ appTrackingConsent: RSAppTrackingConsent) {
if let optOutStatus: Bool = userDefaults.read(.optStatus), optOutStatus == true {
log(message: "User has been Opted out", logLevel: .debug)
return
}
RSSessionStorage.shared.write(.appTrackingConsent, value: appTrackingConsent)
}

/**
API for enable or disable tracking user activities.
- Parameters:
- status: Enable or disable tracking
# Example #
```
RSClient.sharedInstance().setOptOutStatus(false)
```
*/
@objc
public func setOptOutStatus(_ status: Bool) {
userDefaults.write(.optStatus, value: status)
log(message: "User has been Opted \(status ? "out" : "in")", logLevel: .debug)
}
}
Loading

0 comments on commit e963e5c

Please sign in to comment.