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 add global attributes when using Objc api #64

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ ClickstreamAnalytics.recordEvent(ClickstreamAnalytics.EventName.SCREEN_VIEW, [
import Clickstream

let globalAttribute: ClickstreamAttribute = [
"channel": "apple",
ClickstreamAnalytics.Attr.APP_INSTALL_CHANNEL: "apple",
"class": 6,
"level": 5.1,
"isOpenNotification": true,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Clickstream/ClickstreamObjc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ import Foundation
ClickstreamAnalytics.enable()
}

private static func getAttributes(_ attributes: NSDictionary) -> ClickstreamAttribute {
static func getAttributes(_ attributes: NSDictionary) -> ClickstreamAttribute {
var result: ClickstreamAttribute = [:]
for case let (key as String, value) in attributes {
if value is String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ extension UserDefaults: UserDefaultsBehaviour {
self.globalAttributes = globalAttributes
return self
}

public func withInitialGlobalAttributesObjc(_ globalAttributes: NSDictionary) -> ClickstreamConfiguration {
self.globalAttributes = ClickstreamObjc.getAttributes(globalAttributes)
return self
}
}

struct ClickstreamContextStorage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AnalyticsClientTest: XCTestCase {
override func setUp() async throws {
UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!)
let contextConfiguration = ClickstreamConfiguration.getDefaultConfiguration()
.withAppId(testAppId)
.withAppId(testAppId + UUID().uuidString)
.withEndpoint(testEndpoint)
.withSendEventInterval(10_000)
.withTrackAppExceptionEvents(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AutoRecordEventClientTest: XCTestCase {
activityTracker = MockActivityTracker()

let contextConfiguration = ClickstreamConfiguration.getDefaultConfiguration()
.withAppId(testAppId)
.withAppId(testAppId + UUID().uuidString)
.withEndpoint(testEndpoint)
.withSendEventInterval(10_000)
.withTrackAppExceptionEvents(true)
Expand Down
2 changes: 1 addition & 1 deletion Tests/ClickstreamTests/Clickstream/EventRecorderTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class EventRecorderTest: XCTestCase {
return HttpResponse.ok(.text("request success"))
}
try! server.start()
let appId = testAppId + String(describing: Date().millisecondsSince1970)
let appId = testAppId + UUID().uuidString

let contextConfiguration = ClickstreamConfiguration.getDefaultConfiguration()
.withAppId(appId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SessionClientTests: XCTestCase {
mockNetworkMonitor = MockNetworkMonitor()

let contextConfiguration = ClickstreamConfiguration.getDefaultConfiguration()
.withAppId(testAppId)
.withAppId(testAppId + UUID().uuidString)
.withEndpoint(testEndpoint)
.withSendEventInterval(10_000)
.withTrackAppExceptionEvents(false)
Expand Down
4 changes: 2 additions & 2 deletions Tests/ClickstreamTests/ClickstreamPluginTestBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ClickstreamPluginTestBase: XCTestCase {
analyticsPlugin = AWSClickstreamPlugin()

let contextConfiguration = ClickstreamConfiguration.getDefaultConfiguration()
.withAppId(testAppId)
.withAppId(testAppId + UUID().uuidString)
.withEndpoint(testEndpoint)
.withSendEventInterval(10_000)
.withTrackAppExceptionEvents(false)
Expand All @@ -34,7 +34,7 @@ class ClickstreamPluginTestBase: XCTestCase {
let eventRecorder = try EventRecorder(clickstream: clickstream)
let analyticsClient = try AnalyticsClient(clickstream: clickstream,
eventRecorder: eventRecorder,
sessionClient: sessionClient )
sessionClient: sessionClient)
analyticsPlugin.analyticsClient = analyticsClient
clickstream.analyticsClient = analyticsClient
clickstream.networkMonitor = mockNetworkMonitor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ClickstreamDBUtiltest: XCTestCase {

override func setUp() {
do {
let appId = testAppId + String(describing: Date().millisecondsSince1970)
let appId = testAppId + UUID().uuidString
dbAdapter = try BaseDBAdapter(prefixPath: EventRecorder.Constants.dbPathPrefix,
databaseName: appId)
dbUtil = ClickstreamDBUtil(dbAdapter: dbAdapter)
Expand Down
4 changes: 2 additions & 2 deletions Tests/ClickstreamTests/IntegrationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class IntegrationTest: XCTestCase {
}
try! server.start()
await Amplify.reset()
let appId = "testAppId" + String(describing: Date().millisecondsSince1970)
let appId = "testAppId" + UUID().uuidString
let configure = ClickstreamConfiguration.getDefaultConfiguration()
.withAppId(appId)
.withEndpoint("http://localhost:8080/collect")
Expand Down Expand Up @@ -117,7 +117,7 @@ class IntegrationTest: XCTestCase {
ClickstreamAnalytics.recordEvent("testEvent")
Thread.sleep(forTimeInterval: 0.1)
ClickstreamAnalytics.flushEvents()
Thread.sleep(forTimeInterval: 0.2)
Thread.sleep(forTimeInterval: 0.5)
let eventCount = try eventRecorder.dbUtil.getEventCount()
XCTAssertEqual(0, eventCount)
}
Expand Down
16 changes: 15 additions & 1 deletion Tests/ClickstreamTests/SDKInitialTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,28 @@ class SDKInitialTest: XCTestCase {
.withTrackUserEngagementEvents(false)
.withAuthCookie("testAuthCookie")
.withInitialGlobalAttributes([
"channel": "AppStore",
ClickstreamAnalytics.Attr.APP_INSTALL_CHANNEL: "AppStore",
"level": 5.1,
"class": 5,
"isOpenNotification": true
])
try ClickstreamAnalytics.initSDK(configure)
}

func testInitSDKWithGlobalAttributeForObjc() throws {
let globalAttribute: NSDictionary = [
ClickstreamAnalytics.Attr.APP_INSTALL_CHANNEL: "SMS",
"Successful": true,
"Score": 90.1,
"level": 5
]
let configure = ClickstreamConfiguration()
.withAppId("testAppId")
.withEndpoint("https://example.com/collect")
.withInitialGlobalAttributesObjc(globalAttribute)
try ClickstreamAnalytics.initSDK(configure)
}

func testInitSDKOverrideAllAmplifyConfiguration() throws {
let configure = ClickstreamConfiguration()
.withAppId("testAppId1")
Expand Down
Loading