Skip to content

Commit

Permalink
updated pd parameter position
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Espinola committed Jul 12, 2024
1 parent c11d53c commit c163c88
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 16 deletions.
12 changes: 4 additions & 8 deletions Example/Example/ProductViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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];
Expand Down
1 change: 1 addition & 0 deletions Sources/API/ATTNEventRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions Sources/Helpers/Extension/ATTNAddToCartEvent+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Sources/URLProviders/ATTNEventURLProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/TestCases/ATTNAddToCartEventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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["pd"])
XCTAssertNil(addToCart.eventRequests.first?.deeplink)
}

func testAddCart_GivenData_ShouldBuildURLWithRequestURL() {
let item = ATTNTestEventUtils.buildItem()
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)
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/TestCases/ATTNProductViewEventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit c163c88

Please sign in to comment.