diff --git a/Example/Example/ProductViewController.m b/Example/Example/ProductViewController.m index e6e2ef9..32cefa9 100644 --- a/Example/Example/ProductViewController.m +++ b/Example/Example/ProductViewController.m @@ -13,18 +13,14 @@ @interface ProductViewController () @end @implementation ProductViewController - -- (void)viewDidLoad { - [super viewDidLoad]; +- (void)viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; ATTNItem* item = [self buildItem]; ATTNProductViewEvent* productView = [[ATTNProductViewEvent alloc] initWithItems:@[ item ]]; + productView.deeplink = @"https://mydeeplink.com/products/32432423"; [[ATTNEventTracker sharedInstance] recordEvent:productView]; -} - -- (void)viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; [self showToast:@"Product View event sent" duration:2]; } @@ -42,7 +38,7 @@ - (IBAction)addToCartButtonPressed:(id)sender { - (IBAction)addToCartWithDeeplinkButtonPressed:(id)sender { ATTNItem* item = [self buildItem]; ATTNAddToCartEvent* addToCart = [[ATTNAddToCartEvent alloc] initWithItems:@[ item ]]; - addToCart.deeplink = @"https://www.clientapp.com/flow=payment"; + addToCart.deeplink = @"https://mydeeplink.com/products/32432423"; [[ATTNEventTracker sharedInstance] recordEvent:addToCart]; [self showToast: [NSString stringWithFormat:@"Add To Cart event sent with requestURL(pd): '%@'", addToCart.deeplink] duration:4]; diff --git a/Sources/API/ATTNEventRequest.swift b/Sources/API/ATTNEventRequest.swift index 17b33a7..4abc5b1 100644 --- a/Sources/API/ATTNEventRequest.swift +++ b/Sources/API/ATTNEventRequest.swift @@ -11,6 +11,7 @@ import Foundation final class ATTNEventRequest { var metadata: [String: Any] let eventNameAbbreviation: String + var deeplink: String? init(metadata: [String: Any], eventNameAbbreviation: String) { self.metadata = metadata diff --git a/Sources/Helpers/Extension/ATTNAddToCartEvent+Extension.swift b/Sources/Helpers/Extension/ATTNAddToCartEvent+Extension.swift index 0ae0a89..bf32d18 100644 --- a/Sources/Helpers/Extension/ATTNAddToCartEvent+Extension.swift +++ b/Sources/Helpers/Extension/ATTNAddToCartEvent+Extension.swift @@ -20,11 +20,16 @@ extension ATTNAddToCartEvent: ATTNEventRequestProvider { var metadata = [String: Any]() item.addItem(toDictionary: &metadata, with: priceFormatter) + let eventRequest = ATTNEventRequest( + metadata: metadata, + eventNameAbbreviation: ATTNEventTypes.addToCart + ) + if let deeplink { - metadata["pd"] = deeplink + eventRequest.deeplink = deeplink } - eventRequests.append(.init(metadata: metadata, eventNameAbbreviation: ATTNEventTypes.addToCart)) + eventRequests.append(eventRequest) } return eventRequests diff --git a/Sources/Helpers/Extension/ATTNProductViewEvent+Extension.swift b/Sources/Helpers/Extension/ATTNProductViewEvent+Extension.swift index 30b9020..3ce0df7 100644 --- a/Sources/Helpers/Extension/ATTNProductViewEvent+Extension.swift +++ b/Sources/Helpers/Extension/ATTNProductViewEvent+Extension.swift @@ -20,11 +20,16 @@ extension ATTNProductViewEvent: ATTNEventRequestProvider { var metadata = [String: Any]() item.addItem(toDictionary: &metadata, with: priceFormatter) + let eventRequest = ATTNEventRequest( + metadata: metadata, + eventNameAbbreviation: ATTNEventTypes.productView + ) + if let deeplink { - metadata["pd"] = deeplink + eventRequest.deeplink = deeplink } - eventRequests.append(.init(metadata: metadata, eventNameAbbreviation: ATTNEventTypes.productView)) + eventRequests.append(eventRequest) } return eventRequests diff --git a/Sources/URLProviders/ATTNEventURLProvider.swift b/Sources/URLProviders/ATTNEventURLProvider.swift index d0dbd65..3072978 100644 --- a/Sources/URLProviders/ATTNEventURLProvider.swift +++ b/Sources/URLProviders/ATTNEventURLProvider.swift @@ -39,6 +39,10 @@ struct ATTNEventURLProvider: ATTNEventURLProviding { queryParams["m"] = try? ATTNJsonUtils.convertObjectToJson(combinedMetadata) ?? "{}" queryParams["t"] = eventRequest.eventNameAbbreviation + if let deeplink = eventRequest.deeplink { + queryParams["pd"] = deeplink + } + urlComponents.queryItems = queryParams.map { .init(name: $0.key, value: $0.value) } return urlComponents.url } diff --git a/Tests/TestCases/ATTNAddToCartEventTests.swift b/Tests/TestCases/ATTNAddToCartEventTests.swift index 80850f1..2d58e8d 100644 --- a/Tests/TestCases/ATTNAddToCartEventTests.swift +++ b/Tests/TestCases/ATTNAddToCartEventTests.swift @@ -13,7 +13,7 @@ final class ATTNAddToCartEventTests: XCTestCase { let item = ATTNTestEventUtils.buildItem() let addToCart = ATTNAddToCartEvent(items: [item]) XCTAssertFalse(addToCart.eventRequests.isEmpty) - XCTAssertNil(addToCart.eventRequests.first?.metadata["pd"]) + XCTAssertNil(addToCart.eventRequests.first?.deeplink) } func testAddCart_GivenData_ShouldBuildURLWithRequestURL() { @@ -21,7 +21,7 @@ final class ATTNAddToCartEventTests: XCTestCase { let addToCart = ATTNAddToCartEvent(items: [item]) addToCart.deeplink = "https://mydeeplink.com/products/32432423" XCTAssertFalse(addToCart.eventRequests.isEmpty) - let requestURL = addToCart.eventRequests.first?.metadata["pd"] as? String + let requestURL = addToCart.eventRequests.first?.deeplink as? String XCTAssertNotNil(requestURL) XCTAssertFalse(requestURL?.isEmpty ?? true) } diff --git a/Tests/TestCases/ATTNProductViewEventTests.swift b/Tests/TestCases/ATTNProductViewEventTests.swift index 3af1f1d..4050c40 100644 --- a/Tests/TestCases/ATTNProductViewEventTests.swift +++ b/Tests/TestCases/ATTNProductViewEventTests.swift @@ -15,14 +15,14 @@ final class ATTNProductViewEventTests: XCTestCase { let item = ATTNTestEventUtils.buildItem() let productView = ATTNProductViewEvent(items: [item]) XCTAssertFalse(productView.eventRequests.isEmpty) - XCTAssertNil(productView.eventRequests.first?.metadata["pd"]) + XCTAssertNil(productView.eventRequests.first?.deeplink) } func testProductView_GivenData_ShouldBuildURLWithRequestURL() { let item = ATTNTestEventUtils.buildItem() let productView = ATTNProductViewEvent(items: [item], deeplink: "https://mydeeplink.com/products/32432423") XCTAssertFalse(productView.eventRequests.isEmpty) - let requestURL = productView.eventRequests.first?.metadata["pd"] as? String + let requestURL = productView.eventRequests.first?.deeplink as? String XCTAssertNotNil(requestURL) XCTAssertFalse(requestURL?.isEmpty ?? true) }