From 1c1cc207842f1b759d22175e1641d203f7a45320 Mon Sep 17 00:00:00 2001 From: Xiaowei Zhu <33129495+zhu-xiaowei@users.noreply.github.com> Date: Mon, 18 Dec 2023 16:05:07 +0800 Subject: [PATCH] fix: add items key for objc (#45) Co-authored-by: xiaoweii --- Sources/Clickstream/ClickstreamObjc.swift | 33 ++++++++++++++++++++ Tests/ClickstreamTests/IntegrationTest.swift | 12 ++++--- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/Sources/Clickstream/ClickstreamObjc.swift b/Sources/Clickstream/ClickstreamObjc.swift index 5f10dbb..26d5f2b 100644 --- a/Sources/Clickstream/ClickstreamObjc.swift +++ b/Sources/Clickstream/ClickstreamObjc.swift @@ -107,3 +107,36 @@ import Foundation return result } } + +/// ClickstreamAnalytics preset item keys for objective-c +/// In addition to the item attributes defined below, you can add up to 10 custom attributes to an item. +@objcMembers public class ClickstreamItemKey: NSObject { + /// The id of the item + public static let ITEM_ID = "id" + /// The name of the item + public static let ITEM_NAME = "name" + /// The location id of the item + public static let LOCATION_ID = "location_id" + /// The brand of the item + public static let ITEM_BRAND = "brand" + /// The currency of the item + public static let CURRENCY = "currency" + /// The price of the item + public static let PRICE = "price" + /// The quantity of the item + public static let QUANTITY = "quantity" + /// The creative name of the item + public static let CREATIVE_NAME = "creative_name" + /// The creative slot of the item + public static let CREATIVE_SLOT = "creative_slot" + /// The category of the item + public static let ITEM_CATEGORY = "item_category" + /// The category2 of the item + public static let ITEM_CATEGORY2 = "item_category2" + /// The category3 of the item + public static let ITEM_CATEGORY3 = "item_category3" + /// The category4 of the item + public static let ITEM_CATEGORY4 = "item_category4" + /// The category5 of the item + public static let ITEM_CATEGORY5 = "item_category5" +} diff --git a/Tests/ClickstreamTests/IntegrationTest.swift b/Tests/ClickstreamTests/IntegrationTest.swift index 1c14367..df55ffc 100644 --- a/Tests/ClickstreamTests/IntegrationTest.swift +++ b/Tests/ClickstreamTests/IntegrationTest.swift @@ -308,10 +308,11 @@ class IntegrationTest: XCTestCase { func testRecordEventWithItemForObjc() throws { let item: NSDictionary = [ - "id": 123, - "name": "Nature", - "category": "book", - "price": 99.9 + ClickstreamItemKey.ITEM_ID: 123, + ClickstreamItemKey.ITEM_NAME: "Nature", + ClickstreamItemKey.ITEM_CATEGORY: "book", + ClickstreamItemKey.PRICE: 99.9, + "event_category": "recommended" ] ClickstreamObjc.recordEvent("testEvent", ["id": 123], @@ -323,7 +324,8 @@ class IntegrationTest: XCTestCase { let eventItem = items[0] XCTAssertEqual(123, eventItem["id"] as! Int) XCTAssertEqual("Nature", eventItem["name"] as! String) - XCTAssertEqual("book", eventItem["category"] as! String) + XCTAssertEqual("book", eventItem["item_category"] as! String) + XCTAssertEqual("recommended", eventItem["event_category"] as! String) XCTAssertEqual(99.9, eventItem["price"] as! Double) }