From 3eb82128708a73b9174d36e62943ec518d30e03d Mon Sep 17 00:00:00 2001 From: Vladimir Espinola Date: Wed, 10 Jul 2024 17:20:15 -0400 Subject: [PATCH 1/8] added deeplink property to events --- .../Extension/ATTNAddToCartEvent+Extension.swift | 5 +++++ .../Extension/ATTNProductViewEvent+Extension.swift | 5 +++++ Sources/Public/Events/ATTNAddToCartEvent.swift | 3 +++ Sources/Public/Events/ATTNDeeplinkHandling.swift | 12 ++++++++++++ Sources/Public/Events/ATTNProductViewEvent.swift | 3 +++ attentive-ios-sdk.xcodeproj/project.pbxproj | 4 ++++ 6 files changed, 32 insertions(+) create mode 100644 Sources/Public/Events/ATTNDeeplinkHandling.swift diff --git a/Sources/Helpers/Extension/ATTNAddToCartEvent+Extension.swift b/Sources/Helpers/Extension/ATTNAddToCartEvent+Extension.swift index 86678e5..f4c7a1c 100644 --- a/Sources/Helpers/Extension/ATTNAddToCartEvent+Extension.swift +++ b/Sources/Helpers/Extension/ATTNAddToCartEvent+Extension.swift @@ -19,6 +19,11 @@ extension ATTNAddToCartEvent: ATTNEventRequestProvider { for item in items { var metadata = [String: Any]() item.addItem(toDictionary: &metadata, with: priceFormatter) + + if let deeplink { + metadata["requestURL"] = deeplink + } + eventRequests.append(.init(metadata: metadata, eventNameAbbreviation: ATTNEventTypes.addToCart)) } diff --git a/Sources/Helpers/Extension/ATTNProductViewEvent+Extension.swift b/Sources/Helpers/Extension/ATTNProductViewEvent+Extension.swift index c77c347..be59244 100644 --- a/Sources/Helpers/Extension/ATTNProductViewEvent+Extension.swift +++ b/Sources/Helpers/Extension/ATTNProductViewEvent+Extension.swift @@ -19,6 +19,11 @@ extension ATTNProductViewEvent: ATTNEventRequestProvider { for item in items { var metadata = [String: Any]() item.addItem(toDictionary: &metadata, with: priceFormatter) + + if let deeplink { + metadata["requestURL"] = deeplink + } + eventRequests.append(.init(metadata: metadata, eventNameAbbreviation: ATTNEventTypes.productView)) } diff --git a/Sources/Public/Events/ATTNAddToCartEvent.swift b/Sources/Public/Events/ATTNAddToCartEvent.swift index c72c0b1..4323338 100644 --- a/Sources/Public/Events/ATTNAddToCartEvent.swift +++ b/Sources/Public/Events/ATTNAddToCartEvent.swift @@ -10,6 +10,7 @@ import Foundation @objc(ATTNAddToCartEvent) public final class ATTNAddToCartEvent: NSObject, ATTNEvent { @objc public let items: [ATTNItem] + @objc public var deeplink: String? @objc public init(items: [ATTNItem]) { @@ -21,3 +22,5 @@ public final class ATTNAddToCartEvent: NSObject, ATTNEvent { fatalError("init() has not been implemented") } } + +extension ATTNAddToCartEvent: ATTNDeeplinkHandling { } diff --git a/Sources/Public/Events/ATTNDeeplinkHandling.swift b/Sources/Public/Events/ATTNDeeplinkHandling.swift new file mode 100644 index 0000000..a2d7d17 --- /dev/null +++ b/Sources/Public/Events/ATTNDeeplinkHandling.swift @@ -0,0 +1,12 @@ +// +// ATTNDeeplinkHandling.swift +// attentive-ios-sdk-framework +// +// Created by Vladimir - Work on 2024-07-10. +// + +import Foundation + +protocol ATTNDeeplinkHandling { + var deeplink: String? { get set } +} diff --git a/Sources/Public/Events/ATTNProductViewEvent.swift b/Sources/Public/Events/ATTNProductViewEvent.swift index 23af889..22b0cb6 100644 --- a/Sources/Public/Events/ATTNProductViewEvent.swift +++ b/Sources/Public/Events/ATTNProductViewEvent.swift @@ -10,6 +10,7 @@ import Foundation @objc(ATTNProductViewEvent) public final class ATTNProductViewEvent: NSObject, ATTNEvent { @objc public let items: [ATTNItem] + @objc public var deeplink: String? @objc(initWithItems:) public init(items: [ATTNItem]) { @@ -21,3 +22,5 @@ public final class ATTNProductViewEvent: NSObject, ATTNEvent { fatalError("init() has not been implemented") } } + +extension ATTNProductViewEvent: ATTNDeeplinkHandling { } diff --git a/attentive-ios-sdk.xcodeproj/project.pbxproj b/attentive-ios-sdk.xcodeproj/project.pbxproj index a8bf9b0..ae17bc1 100644 --- a/attentive-ios-sdk.xcodeproj/project.pbxproj +++ b/attentive-ios-sdk.xcodeproj/project.pbxproj @@ -52,6 +52,7 @@ FB60AF0B2C1211C700C61537 /* ATTNEventURLProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB60AF0A2C1211C700C61537 /* ATTNEventURLProvider.swift */; }; FB65536A2C1B72D4008DB3B1 /* ATTNSDKTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB6553692C1B72D4008DB3B1 /* ATTNSDKTests.swift */; }; FB65536C2C1B74A9008DB3B1 /* ATTNAPIProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB65536B2C1B74A9008DB3B1 /* ATTNAPIProtocol.swift */; }; + FB84E3032C3F30FF0011936B /* ATTNDeeplinkHandling.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB84E3022C3F30FF0011936B /* ATTNDeeplinkHandling.swift */; }; FB90EF0B2C109CB4004DFC4A /* ATTNAPIITTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB90EF0A2C109CB4004DFC4A /* ATTNAPIITTests.swift */; }; FB90EF0D2C10A7F7004DFC4A /* NSURLSessionDataTaskMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB90EF0C2C10A7F7004DFC4A /* NSURLSessionDataTaskMock.swift */; }; FB90EF0F2C10A81E004DFC4A /* NSURLSessionMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB90EF0E2C10A81E004DFC4A /* NSURLSessionMock.swift */; }; @@ -156,6 +157,7 @@ FB6553692C1B72D4008DB3B1 /* ATTNSDKTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ATTNSDKTests.swift; sourceTree = ""; }; FB65536B2C1B74A9008DB3B1 /* ATTNAPIProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ATTNAPIProtocol.swift; sourceTree = ""; }; FB65536D2C1B7747008DB3B1 /* ATTNAPISpy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ATTNAPISpy.swift; sourceTree = ""; }; + FB84E3022C3F30FF0011936B /* ATTNDeeplinkHandling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ATTNDeeplinkHandling.swift; sourceTree = ""; }; FB90EF0A2C109CB4004DFC4A /* ATTNAPIITTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ATTNAPIITTests.swift; sourceTree = ""; }; FB90EF0C2C10A7F7004DFC4A /* NSURLSessionDataTaskMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSURLSessionDataTaskMock.swift; sourceTree = ""; }; FB90EF0E2C10A81E004DFC4A /* NSURLSessionMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSURLSessionMock.swift; sourceTree = ""; }; @@ -437,6 +439,7 @@ FBA9F9F72C0A77AB00C65024 /* ATTNPrice.swift */, FBA9F9F82C0A77AB00C65024 /* ATTNProductViewEvent.swift */, FBA9F9F92C0A77AB00C65024 /* ATTNPurchaseEvent.swift */, + FB84E3022C3F30FF0011936B /* ATTNDeeplinkHandling.swift */, ); path = Events; sourceTree = ""; @@ -680,6 +683,7 @@ FB4E3FE72C372C54004B8FF0 /* ATTNWebViewProviding.swift in Sources */, FBA9FA0A2C0A77AB00C65024 /* ATTNCreativeUrlProvider.swift in Sources */, FB65536C2C1B74A9008DB3B1 /* ATTNAPIProtocol.swift in Sources */, + FB84E3032C3F30FF0011936B /* ATTNDeeplinkHandling.swift in Sources */, FB35C17D2C0E039E009FA048 /* ATTNConstants.swift in Sources */, FB56D4DC2C208D6100AF7530 /* Boolean+Extension.swift in Sources */, FBA9FA082C0A77AB00C65024 /* Dictionary+Extension.swift in Sources */, From 4b119a3cee81715097747f7ea085ace618b16f1f Mon Sep 17 00:00:00 2001 From: Vladimir Espinola Date: Thu, 11 Jul 2024 15:24:13 -0400 Subject: [PATCH 2/8] added unit test --- Example/Base.lproj/Main.storyboard | 110 +++++++++++------- Example/Example/ProductViewController.m | 23 ++-- Tests/TestCases/ATTNAddToCartEventTests.swift | 28 +++++ .../TestCases/ATTNProductViewEventTests.swift | 30 +++++ attentive-ios-sdk.xcodeproj/project.pbxproj | 8 ++ 5 files changed, 152 insertions(+), 47 deletions(-) create mode 100644 Tests/TestCases/ATTNAddToCartEventTests.swift create mode 100644 Tests/TestCases/ATTNProductViewEventTests.swift diff --git a/Example/Base.lproj/Main.storyboard b/Example/Base.lproj/Main.storyboard index 821d493..85567ee 100644 --- a/Example/Base.lproj/Main.storyboard +++ b/Example/Base.lproj/Main.storyboard @@ -157,48 +157,80 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/Example/ProductViewController.m b/Example/Example/ProductViewController.m index 4e00b84..6abbab4 100644 --- a/Example/Example/ProductViewController.m +++ b/Example/Example/ProductViewController.m @@ -26,16 +26,26 @@ - (void)viewDidLoad { - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; - [self showToast:@"Product View event sent"]; + [self showToast:@"Product View event sent" duration:2]; } - (IBAction)addToCartButtonPressed:(id)sender { ATTNItem* item = [self buildItem]; ATTNAddToCartEvent* addToCart = [[ATTNAddToCartEvent alloc] initWithItems:@[ item ]]; + addToCart.deeplink = @"https://www.clientapp.com/flow=payment"; [[ATTNEventTracker sharedInstance] recordEvent:addToCart]; - [self showToast:@"Add To Cart event sent"]; + [self showToast:@"Add To Cart event sent" duration:2]; +} + +- (IBAction)addToCartWithDeeplinkButtonPressed:(id)sender { + ATTNItem* item = [self buildItem]; + ATTNAddToCartEvent* addToCart = [[ATTNAddToCartEvent alloc] initWithItems:@[ item ]]; + addToCart.deeplink = @"https://www.clientapp.com/flow=payment"; + + [[ATTNEventTracker sharedInstance] recordEvent:addToCart]; + [self showToast: [NSString stringWithFormat:@"Add To Cart event sent with requestURL: '%@'", addToCart.deeplink] duration:4]; } - (IBAction)purchaseButtonPressed:(id)sender { @@ -50,7 +60,7 @@ - (IBAction)purchaseButtonPressed:(id)sender { [[ATTNEventTracker sharedInstance] recordEvent:purchase]; - [self showToast:@"Purchase event sent"]; + [self showToast:@"Purchase event sent" duration:2]; } - (ATTNItem*)buildItem { @@ -67,19 +77,16 @@ - (IBAction)customEventButtonPressed:(id)sender { [[ATTNEventTracker sharedInstance] recordEvent:customEvent]; - [self showToast:@"Custom event sent"]; + [self showToast:@"Custom event sent" duration:2]; } - -- (void)showToast:(NSString*)message { +- (void)showToast:(NSString*)message duration:(int)duration { UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert]; [self presentViewController:alert animated:YES completion:nil]; - int duration = 1; // duration in seconds - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ [alert dismissViewControllerAnimated:YES completion:nil]; }); diff --git a/Tests/TestCases/ATTNAddToCartEventTests.swift b/Tests/TestCases/ATTNAddToCartEventTests.swift new file mode 100644 index 0000000..21b7cd3 --- /dev/null +++ b/Tests/TestCases/ATTNAddToCartEventTests.swift @@ -0,0 +1,28 @@ +// +// ATTNAddToCartEventTests.swift +// attentive-ios-sdk Tests +// +// Created by Vladimir - Work on 2024-07-11. +// + +import XCTest +@testable import ATTNSDKFramework + +final class ATTNAddToCartEventTests: XCTestCase { + func testAddCart_GivenData_ShouldBuildURL() { + let item = ATTNTestEventUtils.buildItem() + let addToCart = ATTNAddToCartEvent(items: [item]) + XCTAssertFalse(addToCart.eventRequests.isEmpty) + XCTAssertNil(addToCart.eventRequests.first?.metadata["requestURL"]) + } + + func testAddCart_GivenData_ShouldBuildURLWithRequestURL() { + let item = ATTNTestEventUtils.buildItem() + let addToCart = ATTNAddToCartEvent(items: [item]) + addToCart.deeplink = "https://www.clientapp.com/flow=payment" + XCTAssertFalse(addToCart.eventRequests.isEmpty) + let requestURL = addToCart.eventRequests.first?.metadata["requestURL"] as? String + XCTAssertNotNil(requestURL) + XCTAssertFalse(requestURL?.isEmpty ?? true) + } +} diff --git a/Tests/TestCases/ATTNProductViewEventTests.swift b/Tests/TestCases/ATTNProductViewEventTests.swift new file mode 100644 index 0000000..3ba71e7 --- /dev/null +++ b/Tests/TestCases/ATTNProductViewEventTests.swift @@ -0,0 +1,30 @@ +// +// ATTNProductViewEventTests.swift +// attentive-ios-sdk Tests +// +// Created by Vladimir - Work on 2024-07-11. +// + +import Foundation + +import XCTest +@testable import ATTNSDKFramework + +final class ATTNProductViewEventTests: XCTestCase { + func testProductView_GivenData_ShouldBuildURL() { + let item = ATTNTestEventUtils.buildItem() + let productView = ATTNProductViewEvent(items: [item]) + XCTAssertFalse(productView.eventRequests.isEmpty) + XCTAssertNil(productView.eventRequests.first?.metadata["requestURL"]) + } + + func testProductView_GivenData_ShouldBuildURLWithRequestURL() { + let item = ATTNTestEventUtils.buildItem() + let productView = ATTNProductViewEvent(items: [item]) + productView.deeplink = "https://www.clientapp.com/flow=payment" + XCTAssertFalse(productView.eventRequests.isEmpty) + let requestURL = productView.eventRequests.first?.metadata["requestURL"] as? String + XCTAssertNotNil(requestURL) + XCTAssertFalse(requestURL?.isEmpty ?? true) + } +} diff --git a/attentive-ios-sdk.xcodeproj/project.pbxproj b/attentive-ios-sdk.xcodeproj/project.pbxproj index ae17bc1..7b21641 100644 --- a/attentive-ios-sdk.xcodeproj/project.pbxproj +++ b/attentive-ios-sdk.xcodeproj/project.pbxproj @@ -53,6 +53,8 @@ FB65536A2C1B72D4008DB3B1 /* ATTNSDKTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB6553692C1B72D4008DB3B1 /* ATTNSDKTests.swift */; }; FB65536C2C1B74A9008DB3B1 /* ATTNAPIProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB65536B2C1B74A9008DB3B1 /* ATTNAPIProtocol.swift */; }; FB84E3032C3F30FF0011936B /* ATTNDeeplinkHandling.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB84E3022C3F30FF0011936B /* ATTNDeeplinkHandling.swift */; }; + FB86C03E2C40611A00E35580 /* ATTNAddToCartEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB86C03D2C40611A00E35580 /* ATTNAddToCartEventTests.swift */; }; + FB86C0402C40669400E35580 /* ATTNProductViewEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB86C03F2C40669400E35580 /* ATTNProductViewEventTests.swift */; }; FB90EF0B2C109CB4004DFC4A /* ATTNAPIITTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB90EF0A2C109CB4004DFC4A /* ATTNAPIITTests.swift */; }; FB90EF0D2C10A7F7004DFC4A /* NSURLSessionDataTaskMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB90EF0C2C10A7F7004DFC4A /* NSURLSessionDataTaskMock.swift */; }; FB90EF0F2C10A81E004DFC4A /* NSURLSessionMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB90EF0E2C10A81E004DFC4A /* NSURLSessionMock.swift */; }; @@ -158,6 +160,8 @@ FB65536B2C1B74A9008DB3B1 /* ATTNAPIProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ATTNAPIProtocol.swift; sourceTree = ""; }; FB65536D2C1B7747008DB3B1 /* ATTNAPISpy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ATTNAPISpy.swift; sourceTree = ""; }; FB84E3022C3F30FF0011936B /* ATTNDeeplinkHandling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ATTNDeeplinkHandling.swift; sourceTree = ""; }; + FB86C03D2C40611A00E35580 /* ATTNAddToCartEventTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ATTNAddToCartEventTests.swift; sourceTree = ""; }; + FB86C03F2C40669400E35580 /* ATTNProductViewEventTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ATTNProductViewEventTests.swift; sourceTree = ""; }; FB90EF0A2C109CB4004DFC4A /* ATTNAPIITTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ATTNAPIITTests.swift; sourceTree = ""; }; FB90EF0C2C10A7F7004DFC4A /* NSURLSessionDataTaskMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSURLSessionDataTaskMock.swift; sourceTree = ""; }; FB90EF0E2C10A81E004DFC4A /* NSURLSessionMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSURLSessionMock.swift; sourceTree = ""; }; @@ -337,6 +341,8 @@ FB2984072C0FAE040039759C /* ATTNAPITests.swift */, FB90EF0A2C109CB4004DFC4A /* ATTNAPIITTests.swift */, FB6553692C1B72D4008DB3B1 /* ATTNSDKTests.swift */, + FB86C03D2C40611A00E35580 /* ATTNAddToCartEventTests.swift */, + FB86C03F2C40669400E35580 /* ATTNProductViewEventTests.swift */, ); path = TestCases; sourceTree = ""; @@ -704,7 +710,9 @@ FB90EF0F2C10A81E004DFC4A /* NSURLSessionMock.swift in Sources */, FB2983E42C0F73990039759C /* ATTNAppInfoMock.swift in Sources */, FB2983F82C0F7FB60039759C /* ATTNUserAgentBuilderTests.swift in Sources */, + FB86C03E2C40611A00E35580 /* ATTNAddToCartEventTests.swift in Sources */, FB2983F62C0F7CF10039759C /* ATTNUserIdentityTests.swift in Sources */, + FB86C0402C40669400E35580 /* ATTNProductViewEventTests.swift in Sources */, FB2983F42C0F759D0039759C /* ATTNVisitorServiceTests.swift in Sources */, FB2983FA2C0F80A30039759C /* ATTNPersistentStorageTests.swift in Sources */, FB080C722C1C755F00834BAA /* ATTNCreativeUrlProviderSpy.swift in Sources */, From 656b473454fa8774d504b3d343696390d908ba1a Mon Sep 17 00:00:00 2001 From: Vladimir Espinola Date: Thu, 11 Jul 2024 15:38:31 -0400 Subject: [PATCH 3/8] updated events init signatures to accept deeplink --- Sources/Public/Events/ATTNAddToCartEvent.swift | 10 ++++++++-- Sources/Public/Events/ATTNProductViewEvent.swift | 8 +++++++- Tests/TestCases/ATTNProductViewEventTests.swift | 3 +-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Sources/Public/Events/ATTNAddToCartEvent.swift b/Sources/Public/Events/ATTNAddToCartEvent.swift index 4323338..7e02c09 100644 --- a/Sources/Public/Events/ATTNAddToCartEvent.swift +++ b/Sources/Public/Events/ATTNAddToCartEvent.swift @@ -12,9 +12,15 @@ public final class ATTNAddToCartEvent: NSObject, ATTNEvent { @objc public let items: [ATTNItem] @objc public var deeplink: String? - @objc - public init(items: [ATTNItem]) { + @objc(initWithItems:) + public convenience init(items: [ATTNItem]) { + self.init(items: items) + } + + @objc(initWithItems:deeplink:) + public init(items: [ATTNItem], deeplink: String?) { self.items = items + self.deeplink = deeplink super.init() } diff --git a/Sources/Public/Events/ATTNProductViewEvent.swift b/Sources/Public/Events/ATTNProductViewEvent.swift index 22b0cb6..7ac0176 100644 --- a/Sources/Public/Events/ATTNProductViewEvent.swift +++ b/Sources/Public/Events/ATTNProductViewEvent.swift @@ -13,8 +13,14 @@ public final class ATTNProductViewEvent: NSObject, ATTNEvent { @objc public var deeplink: String? @objc(initWithItems:) - public init(items: [ATTNItem]) { + public convenience init(items: [ATTNItem]) { + self.init(items: items, deeplink: nil) + } + + @objc(initWithItems:deeplink:) + public init(items: [ATTNItem], deeplink: String?) { self.items = items + self.deeplink = deeplink super.init() } diff --git a/Tests/TestCases/ATTNProductViewEventTests.swift b/Tests/TestCases/ATTNProductViewEventTests.swift index 3ba71e7..33ebf6b 100644 --- a/Tests/TestCases/ATTNProductViewEventTests.swift +++ b/Tests/TestCases/ATTNProductViewEventTests.swift @@ -20,8 +20,7 @@ final class ATTNProductViewEventTests: XCTestCase { func testProductView_GivenData_ShouldBuildURLWithRequestURL() { let item = ATTNTestEventUtils.buildItem() - let productView = ATTNProductViewEvent(items: [item]) - productView.deeplink = "https://www.clientapp.com/flow=payment" + let productView = ATTNProductViewEvent(items: [item], deeplink: "https://www.clientapp.com/flow=payment") XCTAssertFalse(productView.eventRequests.isEmpty) let requestURL = productView.eventRequests.first?.metadata["requestURL"] as? String XCTAssertNotNil(requestURL) From 9d7e131783dde9cd8f641fde8a25cbddbd6854c5 Mon Sep 17 00:00:00 2001 From: Vladimir Espinola Date: Thu, 11 Jul 2024 15:57:14 -0400 Subject: [PATCH 4/8] fixed convenience init method --- Sources/Public/Events/ATTNAddToCartEvent.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Public/Events/ATTNAddToCartEvent.swift b/Sources/Public/Events/ATTNAddToCartEvent.swift index 7e02c09..181f454 100644 --- a/Sources/Public/Events/ATTNAddToCartEvent.swift +++ b/Sources/Public/Events/ATTNAddToCartEvent.swift @@ -14,7 +14,7 @@ public final class ATTNAddToCartEvent: NSObject, ATTNEvent { @objc(initWithItems:) public convenience init(items: [ATTNItem]) { - self.init(items: items) + self.init(items: items, deeplink: nil) } @objc(initWithItems:deeplink:) From c11d53cfc34b7564dfe6369a5947bd8b623daaf8 Mon Sep 17 00:00:00 2001 From: Vladimir Espinola Date: Fri, 12 Jul 2024 10:11:31 -0400 Subject: [PATCH 5/8] updated param name to pd --- Example/Example/ProductViewController.m | 2 +- .../Helpers/Extension/ATTNAddToCartEvent+Extension.swift | 2 +- .../Helpers/Extension/ATTNProductViewEvent+Extension.swift | 2 +- Tests/TestCases/ATTNAddToCartEventTests.swift | 6 +++--- Tests/TestCases/ATTNProductViewEventTests.swift | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Example/Example/ProductViewController.m b/Example/Example/ProductViewController.m index 6abbab4..e6e2ef9 100644 --- a/Example/Example/ProductViewController.m +++ b/Example/Example/ProductViewController.m @@ -45,7 +45,7 @@ - (IBAction)addToCartWithDeeplinkButtonPressed:(id)sender { addToCart.deeplink = @"https://www.clientapp.com/flow=payment"; [[ATTNEventTracker sharedInstance] recordEvent:addToCart]; - [self showToast: [NSString stringWithFormat:@"Add To Cart event sent with requestURL: '%@'", addToCart.deeplink] duration:4]; + [self showToast: [NSString stringWithFormat:@"Add To Cart event sent with requestURL(pd): '%@'", addToCart.deeplink] duration:4]; } - (IBAction)purchaseButtonPressed:(id)sender { diff --git a/Sources/Helpers/Extension/ATTNAddToCartEvent+Extension.swift b/Sources/Helpers/Extension/ATTNAddToCartEvent+Extension.swift index f4c7a1c..0ae0a89 100644 --- a/Sources/Helpers/Extension/ATTNAddToCartEvent+Extension.swift +++ b/Sources/Helpers/Extension/ATTNAddToCartEvent+Extension.swift @@ -21,7 +21,7 @@ extension ATTNAddToCartEvent: ATTNEventRequestProvider { item.addItem(toDictionary: &metadata, with: priceFormatter) if let deeplink { - metadata["requestURL"] = deeplink + metadata["pd"] = deeplink } eventRequests.append(.init(metadata: metadata, eventNameAbbreviation: ATTNEventTypes.addToCart)) diff --git a/Sources/Helpers/Extension/ATTNProductViewEvent+Extension.swift b/Sources/Helpers/Extension/ATTNProductViewEvent+Extension.swift index be59244..30b9020 100644 --- a/Sources/Helpers/Extension/ATTNProductViewEvent+Extension.swift +++ b/Sources/Helpers/Extension/ATTNProductViewEvent+Extension.swift @@ -21,7 +21,7 @@ extension ATTNProductViewEvent: ATTNEventRequestProvider { item.addItem(toDictionary: &metadata, with: priceFormatter) if let deeplink { - metadata["requestURL"] = deeplink + metadata["pd"] = deeplink } eventRequests.append(.init(metadata: metadata, eventNameAbbreviation: ATTNEventTypes.productView)) diff --git a/Tests/TestCases/ATTNAddToCartEventTests.swift b/Tests/TestCases/ATTNAddToCartEventTests.swift index 21b7cd3..80850f1 100644 --- a/Tests/TestCases/ATTNAddToCartEventTests.swift +++ b/Tests/TestCases/ATTNAddToCartEventTests.swift @@ -13,15 +13,15 @@ final class ATTNAddToCartEventTests: XCTestCase { let item = ATTNTestEventUtils.buildItem() let addToCart = ATTNAddToCartEvent(items: [item]) XCTAssertFalse(addToCart.eventRequests.isEmpty) - XCTAssertNil(addToCart.eventRequests.first?.metadata["requestURL"]) + XCTAssertNil(addToCart.eventRequests.first?.metadata["pd"]) } func testAddCart_GivenData_ShouldBuildURLWithRequestURL() { let item = ATTNTestEventUtils.buildItem() let addToCart = ATTNAddToCartEvent(items: [item]) - addToCart.deeplink = "https://www.clientapp.com/flow=payment" + addToCart.deeplink = "https://mydeeplink.com/products/32432423" XCTAssertFalse(addToCart.eventRequests.isEmpty) - let requestURL = addToCart.eventRequests.first?.metadata["requestURL"] as? String + let requestURL = addToCart.eventRequests.first?.metadata["pd"] as? String XCTAssertNotNil(requestURL) XCTAssertFalse(requestURL?.isEmpty ?? true) } diff --git a/Tests/TestCases/ATTNProductViewEventTests.swift b/Tests/TestCases/ATTNProductViewEventTests.swift index 33ebf6b..3af1f1d 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["requestURL"]) + XCTAssertNil(productView.eventRequests.first?.metadata["pd"]) } func testProductView_GivenData_ShouldBuildURLWithRequestURL() { let item = ATTNTestEventUtils.buildItem() - let productView = ATTNProductViewEvent(items: [item], deeplink: "https://www.clientapp.com/flow=payment") + let productView = ATTNProductViewEvent(items: [item], deeplink: "https://mydeeplink.com/products/32432423") XCTAssertFalse(productView.eventRequests.isEmpty) - let requestURL = productView.eventRequests.first?.metadata["requestURL"] as? String + let requestURL = productView.eventRequests.first?.metadata["pd"] as? String XCTAssertNotNil(requestURL) XCTAssertFalse(requestURL?.isEmpty ?? true) } From c163c88757219d80b88ee1b9f69e8ced406a1a59 Mon Sep 17 00:00:00 2001 From: Vladimir Espinola Date: Fri, 12 Jul 2024 12:17:13 -0400 Subject: [PATCH 6/8] updated pd parameter position --- Example/Example/ProductViewController.m | 12 ++++-------- Sources/API/ATTNEventRequest.swift | 1 + .../Extension/ATTNAddToCartEvent+Extension.swift | 9 +++++++-- .../Extension/ATTNProductViewEvent+Extension.swift | 9 +++++++-- Sources/URLProviders/ATTNEventURLProvider.swift | 4 ++++ Tests/TestCases/ATTNAddToCartEventTests.swift | 4 ++-- Tests/TestCases/ATTNProductViewEventTests.swift | 4 ++-- 7 files changed, 27 insertions(+), 16 deletions(-) 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) } From a89a43917ec7b117d8a22b7374c6b31d34c35a49 Mon Sep 17 00:00:00 2001 From: Vladimir Espinola Date: Fri, 12 Jul 2024 13:31:41 -0400 Subject: [PATCH 7/8] cleaned up product screen --- Example/Example/ProductViewController.m | 1 - 1 file changed, 1 deletion(-) diff --git a/Example/Example/ProductViewController.m b/Example/Example/ProductViewController.m index 32cefa9..46ad054 100644 --- a/Example/Example/ProductViewController.m +++ b/Example/Example/ProductViewController.m @@ -29,7 +29,6 @@ - (void)viewDidAppear:(BOOL)animated { - (IBAction)addToCartButtonPressed:(id)sender { ATTNItem* item = [self buildItem]; ATTNAddToCartEvent* addToCart = [[ATTNAddToCartEvent alloc] initWithItems:@[ item ]]; - addToCart.deeplink = @"https://www.clientapp.com/flow=payment"; [[ATTNEventTracker sharedInstance] recordEvent:addToCart]; [self showToast:@"Add To Cart event sent" duration:2]; From b717c3b8dc367f506c618d8511eea732568744b2 Mon Sep 17 00:00:00 2001 From: Vladimir Espinola Date: Fri, 12 Jul 2024 13:48:35 -0400 Subject: [PATCH 8/8] adjusted product view layout --- Example/Base.lproj/Main.storyboard | 39 +++++++++++++----------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/Example/Base.lproj/Main.storyboard b/Example/Base.lproj/Main.storyboard index 85567ee..3c2c3e0 100644 --- a/Example/Base.lproj/Main.storyboard +++ b/Example/Base.lproj/Main.storyboard @@ -158,28 +158,27 @@ - + - - + + - + - - - - - - - + - + - - + +