Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for multiple instance #458

Merged
merged 6 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@ iOSInjectionProject/
relative_or_absolute_path_to_cache_location
compile_commands.json
GoogleService-Info.plist
RudderConfig.plist
configuration.json
RudderConfig*.plist
configuration.json
RudderTests/**/*.plist
4 changes: 4 additions & 0 deletions Examples/RudderConfig/SampleRudderConfig.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>MOCK_DATA_PLANE_URL</key>
<string></string>
<key>MOCK_CONTROL_PLANE_URL</key>
<string></string>
<key>WRITE_KEY</key>
<string></string>
<key>PROD_DATA_PLANE_URL</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
06EABC8F24665E480043D720 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 06EABC8E24665E480043D720 /* Assets.xcassets */; };
06EABC9224665E480043D720 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 06EABC9024665E480043D720 /* LaunchScreen.storyboard */; };
1BBDBFA2CA1F65262723A637 /* Pods_SampleSwift_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 72016B33854F923C48E9084A /* Pods_SampleSwift_iOS.framework */; };
ED333EC62B2358B4003EB0B3 /* RudderConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = ED333EC32B2358B4003EB0B3 /* RudderConfig.plist */; };
ED333EC62B2358B4003EB0B3 /* RudderConfig_1.plist in Resources */ = {isa = PBXBuildFile; fileRef = ED333EC32B2358B4003EB0B3 /* RudderConfig_1.plist */; };
ED333EC72B2358B4003EB0B3 /* SampleRudderConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = ED333EC42B2358B4003EB0B3 /* SampleRudderConfig.plist */; };
ED333EC82B2358B4003EB0B3 /* RudderConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED333EC52B2358B4003EB0B3 /* RudderConfig.swift */; };
ED333ECA2B235D8E003EB0B3 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = ED333EC92B235D8E003EB0B3 /* GoogleService-Info.plist */; };
ED4EACA127F5718100207AF1 /* RSCustomDestination.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED4EACA027F5718100207AF1 /* RSCustomDestination.swift */; };
EDC1BBC82B0B2E7D00211F24 /* Configuration.json in Resources */ = {isa = PBXBuildFile; fileRef = EDC1BBC72B0B2E7D00211F24 /* Configuration.json */; };
EDEDC1382B6A336D0082C7E2 /* RudderConfig_2.plist in Resources */ = {isa = PBXBuildFile; fileRef = EDEDC1372B6A336D0082C7E2 /* RudderConfig_2.plist */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -34,12 +35,13 @@
6AF9E4CE2308F413BD375A80 /* Pods-SampleSwift-iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SampleSwift-iOS.debug.xcconfig"; path = "Target Support Files/Pods-SampleSwift-iOS/Pods-SampleSwift-iOS.debug.xcconfig"; sourceTree = "<group>"; };
72016B33854F923C48E9084A /* Pods_SampleSwift_iOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SampleSwift_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
80FF9E334811B6015D51C152 /* Pods-SampleSwift-iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SampleSwift-iOS.release.xcconfig"; path = "Target Support Files/Pods-SampleSwift-iOS/Pods-SampleSwift-iOS.release.xcconfig"; sourceTree = "<group>"; };
ED333EC32B2358B4003EB0B3 /* RudderConfig.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = RudderConfig.plist; sourceTree = "<group>"; };
ED333EC32B2358B4003EB0B3 /* RudderConfig_1.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = RudderConfig_1.plist; sourceTree = "<group>"; };
ED333EC42B2358B4003EB0B3 /* SampleRudderConfig.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = SampleRudderConfig.plist; sourceTree = "<group>"; };
ED333EC52B2358B4003EB0B3 /* RudderConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RudderConfig.swift; sourceTree = "<group>"; };
ED333EC92B235D8E003EB0B3 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
ED4EACA027F5718100207AF1 /* RSCustomDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RSCustomDestination.swift; sourceTree = "<group>"; };
EDC1BBC72B0B2E7D00211F24 /* Configuration.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = Configuration.json; sourceTree = "<group>"; };
EDEDC1372B6A336D0082C7E2 /* RudderConfig_2.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = RudderConfig_2.plist; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -111,7 +113,8 @@
ED333EC22B2358B4003EB0B3 /* RudderConfig */ = {
isa = PBXGroup;
children = (
ED333EC32B2358B4003EB0B3 /* RudderConfig.plist */,
ED333EC32B2358B4003EB0B3 /* RudderConfig_1.plist */,
EDEDC1372B6A336D0082C7E2 /* RudderConfig_2.plist */,
ED333EC52B2358B4003EB0B3 /* RudderConfig.swift */,
ED333EC42B2358B4003EB0B3 /* SampleRudderConfig.plist */,
);
Expand Down Expand Up @@ -182,7 +185,8 @@
ED333EC72B2358B4003EB0B3 /* SampleRudderConfig.plist in Resources */,
06EABC9224665E480043D720 /* LaunchScreen.storyboard in Resources */,
06EABC8F24665E480043D720 /* Assets.xcassets in Resources */,
ED333EC62B2358B4003EB0B3 /* RudderConfig.plist in Resources */,
EDEDC1382B6A336D0082C7E2 /* RudderConfig_2.plist in Resources */,
ED333EC62B2358B4003EB0B3 /* RudderConfig_1.plist in Resources */,
EDC1BBC82B0B2E7D00211F24 /* Configuration.json in Resources */,
06EABC8D24665E470043D720 /* Main.storyboard in Resources */,
ED333ECA2B235D8E003EB0B3 /* GoogleService-Info.plist in Resources */,
Expand Down
66 changes: 46 additions & 20 deletions Examples/SampleSwift-iOS/SampleSwift-iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,58 @@ import Network
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var client: RSClient!
var client1: RSClient!
var client2: RSClient!

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

guard let path = Bundle.main.path(forResource: "RudderConfig", ofType: "plist"),
let data = try? Data(contentsOf: URL(fileURLWithPath: path)),
let rudderConfig = try? PropertyListDecoder().decode(RudderConfig.self, from: data) else {
return true
}

print(NSHomeDirectory())

if let config: Config = Config(writeKey: rudderConfig.WRITE_KEY, dataPlaneURL: rudderConfig.DEV_DATA_PLANE_URL)?
.controlPlaneURL(rudderConfig.DEV_CONTROL_PLANE_URL)
// .dataResidencyServer(.EU)
// .controlPlaneURL("https://e2e6fd4f-c24c-43d6-8ca3-11a11e7cc7d5.mock.pstmn.io") // disabled
// .controlPlaneURL("https://98e2b8de-9984-471b-a705-b1bcf3f9f6ba.mock.pstmn.io") // enabled
.loglevel(.verbose)
.trackLifecycleEvents(true)
.recordScreenViews(true)
// .sleepTimeOut(10)
.gzipEnabled(false) {

client = RSClient(config: config)
if let path = Bundle.main.path(forResource: "RudderConfig_1", ofType: "plist"),
let data = try? Data(contentsOf: URL(fileURLWithPath: path)),
let rudderConfig = try? PropertyListDecoder().decode(RudderConfig.self, from: data)
{
if let config: Configuration = Configuration(
writeKey: rudderConfig.WRITE_KEY,
dataPlaneURL: rudderConfig.DEV_DATA_PLANE_URL
)?
.controlPlaneURL(rudderConfig.DEV_CONTROL_PLANE_URL)
// .controlPlaneURL("https://e2e6fd4f-c24c-43d6-8ca3-11a11e7cc7d5.mock.pstmn.io") // disabled
// .controlPlaneURL("https://98e2b8de-9984-471b-a705-b1bcf3f9f6ba.mock.pstmn.io") // enabled
.logLevel(.verbose)
.trackLifecycleEvents(true)
.recordScreenViews(true)
.sleepTimeOut(5)
.gzipEnabled(false)
.flushQueueSize(0)
{
client1 = RSClient.initialize(with: config)
}
}

if let path = Bundle.main.path(forResource: "RudderConfig_2", ofType: "plist"),
let data = try? Data(contentsOf: URL(fileURLWithPath: path)),
let rudderConfig = try? PropertyListDecoder().decode(RudderConfig.self, from: data)
{
if let config: Configuration = Configuration(
writeKey: rudderConfig.WRITE_KEY,
dataPlaneURL: rudderConfig.DEV_DATA_PLANE_URL
)?
.controlPlaneURL(rudderConfig.DEV_CONTROL_PLANE_URL)
// .controlPlaneURL("https://e2e6fd4f-c24c-43d6-8ca3-11a11e7cc7d5.mock.pstmn.io") // disabled
// .controlPlaneURL("https://98e2b8de-9984-471b-a705-b1bcf3f9f6ba.mock.pstmn.io") // enabled
.logLevel(.verbose)
.trackLifecycleEvents(false)
.recordScreenViews(false)
.sleepTimeOut(5)
.gzipEnabled(false)
.flushQueueSize(0)
{
client2 = RSClient.initialize(with: config, instanceName: "")
}
}



return true
}

Expand Down
71 changes: 38 additions & 33 deletions Examples/SampleSwift-iOS/SampleSwift-iOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ struct Task {
class ViewController: UIViewController {

@IBOutlet weak var tableView: UITableView!
var client: RSClient!
var client1: RSClient!
var client2: RSClient!

let taskList: [Task] = [
Task(name: "Identify with traits"),
Expand Down Expand Up @@ -67,7 +68,8 @@ class ViewController: UIViewController {
tableView.dataSource = self
tableView.delegate = self

client = (UIApplication.shared.delegate as? AppDelegate)!.client
client1 = (UIApplication.shared.delegate as? AppDelegate)!.client1
client2 = (UIApplication.shared.delegate as? AppDelegate)!.client2
}
}

Expand All @@ -87,7 +89,7 @@ extension ViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.row {
case 0:
client.identify("test_user_id", traits: [
client1.identify("test_user_id", traits: [
"integerValue": 42,
"stringValue": "Hello, World!",
"boolValue": true,
Expand All @@ -98,10 +100,10 @@ extension ViewController: UITableViewDataSource, UITableViewDelegate {
"dateValue": Date()
])
case 1:
client.identify("test_user_id")
client1.identify("test_user_id")

case 2:
client.track("single_track_call", properties: [
client1.track("single_track_call", properties: [
"integerValue": 42,
"stringValue": "Hello, World!",
"boolValue": true,
Expand All @@ -112,37 +114,38 @@ extension ViewController: UITableViewDataSource, UITableViewDelegate {
"dateValue": Date()
])
case 3:
client.track("single_track_call")
client1.track("single_track_call")
client2.track("single_track_call")
case 4:
client.alias("new_user_id")
client1.alias("new_user_id")
case 5:
client.screen("ViewController", properties: ["key_1": "value_1"])
client1.screen("ViewController", properties: ["key_1": "value_1"])
case 6:
client.screen("ViewController")
client1.screen("ViewController")
case 7:
client.group("test_group_id", traits: ["key_1": "value_1"])
client1.group("test_group_id", traits: ["key_1": "value_1"])
case 8:
client.group("test_group_id")
client1.group("test_group_id")
case 9:
client.setAnonymousId("anonymous_id_1")
client1.setAnonymousId("anonymous_id_1")
case 10:
client.setDeviceToken("device_token_1")
client1.setDeviceToken("device_token_1")
case 11:
client.setAdvertisingId("advertising_id_1")
client1.setAdvertisingId("advertising_id_1")
case 12:
client.setOptOutStatus(false)
client1.setOptOutStatus(false)
case 13:
client.setOptOutStatus(true)
client1.setOptOutStatus(true)
case 14:
client.reset(and: false)
client1.reset(and: false)
case 15:
client.flush()
client1.flush()
case 16:
client.setAnonymousId("anonymous_id_2")
client1.setAnonymousId("anonymous_id_2")
case 17:
client.setDeviceToken("device_token_2")
client1.setDeviceToken("device_token_2")
case 18:
client.setAdvertisingId("advertising_id_2")
client1.setAdvertisingId("advertising_id_2")
case 19:
let option = Option()

Expand All @@ -151,7 +154,7 @@ extension ViewController: UITableViewDataSource, UITableViewDelegate {
option.putIntegration("key-7", isEnabled: true)
option.putIntegration("key-8", isEnabled: false)

client.setOption(option)
client1.setOption(option)
case 20:
let option = IdentifyOption()
option.putExternalId("value-1", to: "key-1")
Expand All @@ -166,9 +169,11 @@ extension ViewController: UITableViewDataSource, UITableViewDelegate {
option.putCustomContext(["Key-02": "value-1"], for: "key-10")
option.putCustomContext(["Key-03": "value-1"], for: "key-11")
option.putCustomContext(["Key-04": "value-1"], for: "key-12")
client.identify("test_user_id", option: option)
client1.identify("test_user_id", option: option)
case 21:
let option = MessageOption()
.putCustomContext([:], for: "")
.putIntegration("", isEnabled: true)

option.putIntegration("key-5", isEnabled: false)
option.putIntegration("key-6", isEnabled: true)
Expand All @@ -177,19 +182,19 @@ extension ViewController: UITableViewDataSource, UITableViewDelegate {

option.putCustomContext(["Key-01": "value-1"], for: "key-9")
option.putCustomContext(["Key-02": "value-2"], for: "key-10")
client.track("single_track_call", option: option)
client1.track("single_track_call", option: option)
case 22:
client.startSession()
client1.startSession()
case 23:
client.endSession()
client1.endSession()
case 24:
client.startSession(1234567890)
client1.startSession(1234567890)
case 25:
if let context = client.context, let dictionaryValue = context.dictionaryValue {
if let context = client1.context, let dictionaryValue = context.dictionaryValue {
print(dictionaryValue)
}
case 26:
client.track("allow_list_track", properties: [
client1.track("allow_list_track", properties: [
"integerValue": 42,
"stringValue": "Hello, World!",
"boolValue": true,
Expand All @@ -200,7 +205,7 @@ extension ViewController: UITableViewDataSource, UITableViewDelegate {
"dateValue": Date()
])
case 27:
client.track("deny_list_track", properties: [
client1.track("deny_list_track", properties: [
"integerValue": 42,
"stringValue": "Hello, World!",
"boolValue": true,
Expand All @@ -211,12 +216,12 @@ extension ViewController: UITableViewDataSource, UITableViewDelegate {
"dateValue": Date()
])
case 28:
client.track("Order Done", properties: getProperties())
client1.track("Order Done", properties: getProperties())
case 29:
client.track("Order Completed", properties: getProperties())
client1.track("Order Completed", properties: getProperties())
case 30:
for i in 1...50 {
client.track("Track \(i)", properties: ["time": Date().timeIntervalSince1970])
client1.track("Track \(i)", properties: ["time": Date().timeIntervalSince1970])
}
/*
case 4:
Expand Down
Loading
Loading