Skip to content

Commit

Permalink
feat: support add global attribute when using Objc api
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoweii committed Apr 11, 2024
1 parent 6242310 commit 2340cd9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
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
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

0 comments on commit 2340cd9

Please sign in to comment.