Skip to content

Commit 1c1cc20

Browse files
zhu-xiaoweixiaoweii
andauthored
fix: add items key for objc (#45)
Co-authored-by: xiaoweii <xiaoweii@amazom.com>
1 parent 648f658 commit 1c1cc20

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

Sources/Clickstream/ClickstreamObjc.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,36 @@ import Foundation
107107
return result
108108
}
109109
}
110+
111+
/// ClickstreamAnalytics preset item keys for objective-c
112+
/// In addition to the item attributes defined below, you can add up to 10 custom attributes to an item.
113+
@objcMembers public class ClickstreamItemKey: NSObject {
114+
/// The id of the item
115+
public static let ITEM_ID = "id"
116+
/// The name of the item
117+
public static let ITEM_NAME = "name"
118+
/// The location id of the item
119+
public static let LOCATION_ID = "location_id"
120+
/// The brand of the item
121+
public static let ITEM_BRAND = "brand"
122+
/// The currency of the item
123+
public static let CURRENCY = "currency"
124+
/// The price of the item
125+
public static let PRICE = "price"
126+
/// The quantity of the item
127+
public static let QUANTITY = "quantity"
128+
/// The creative name of the item
129+
public static let CREATIVE_NAME = "creative_name"
130+
/// The creative slot of the item
131+
public static let CREATIVE_SLOT = "creative_slot"
132+
/// The category of the item
133+
public static let ITEM_CATEGORY = "item_category"
134+
/// The category2 of the item
135+
public static let ITEM_CATEGORY2 = "item_category2"
136+
/// The category3 of the item
137+
public static let ITEM_CATEGORY3 = "item_category3"
138+
/// The category4 of the item
139+
public static let ITEM_CATEGORY4 = "item_category4"
140+
/// The category5 of the item
141+
public static let ITEM_CATEGORY5 = "item_category5"
142+
}

Tests/ClickstreamTests/IntegrationTest.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,11 @@ class IntegrationTest: XCTestCase {
308308

309309
func testRecordEventWithItemForObjc() throws {
310310
let item: NSDictionary = [
311-
"id": 123,
312-
"name": "Nature",
313-
"category": "book",
314-
"price": 99.9
311+
ClickstreamItemKey.ITEM_ID: 123,
312+
ClickstreamItemKey.ITEM_NAME: "Nature",
313+
ClickstreamItemKey.ITEM_CATEGORY: "book",
314+
ClickstreamItemKey.PRICE: 99.9,
315+
"event_category": "recommended"
315316
]
316317
ClickstreamObjc.recordEvent("testEvent",
317318
["id": 123],
@@ -323,7 +324,8 @@ class IntegrationTest: XCTestCase {
323324
let eventItem = items[0]
324325
XCTAssertEqual(123, eventItem["id"] as! Int)
325326
XCTAssertEqual("Nature", eventItem["name"] as! String)
326-
XCTAssertEqual("book", eventItem["category"] as! String)
327+
XCTAssertEqual("book", eventItem["item_category"] as! String)
328+
XCTAssertEqual("recommended", eventItem["event_category"] as! String)
327329
XCTAssertEqual(99.9, eventItem["price"] as! Double)
328330
}
329331

0 commit comments

Comments
 (0)