Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Features

* Purchase tracking: optional `isGiftPackage` on `PurchaseTrackingRequest` — sent as `gift_package` only when `true`, the way `tax_free` is.
* Strict purchase tracking: `trackPurchase(_:recommendedBy:completion:)` with `PurchaseTrackingRequest` / `PurchaseItemRequest` (camelCase API; snake_case on the wire). Validation before send; `tax_free` only when `isTaxFree` is true; optional properties omitted when unset. Demo buttons for minimal and full payloads.
* The stories block collapses when a load brings nothing to show — a block switched off in the dashboard, or a failed request — instead of leaving an empty row on the screen. New `StoriesView.hasStories`, `onStoriesCollapse`, `StoriesView.defaultHeight` and `StoriesWidget.onCollapse(_:)` for hosts that pin the height themselves or draw their own header around the block.

Expand Down
3 changes: 2 additions & 1 deletion DemoApp/REES46Demo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,8 @@ class MainViewController: UIViewController, UIScrollViewDelegate {
custom: ["demo_custom": "ios_demo"],
recommendedSource: ["source_key": "source_value"],
stream: "demo-stream",
segment: "A"
segment: "A",
isGiftPackage: true
)
sdk.tracking.purchase(request) { result in
switch result {
Expand Down
43 changes: 43 additions & 0 deletions DemoApp/Rees46DemoTests/TrackingNamespaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,49 @@ final class TrackingNamespaceTests: XCTestCase {
XCTAssertEqual(items?.first?["price"] as? Double, 49.9)
}

func test_purchaseGiftPackage_reachesTheWire() {
let sdk = MockPersonalizationSDK()
let service = TrackEventServiceImpl(sdk: sdk)
let expectation = expectation(description: "purchase tracked")

TrackingAPIImpl(trackService: service, sourceService: TrackSourceServiceSpy())
.purchase(Self.purchaseRequest(isGiftPackage: true)) { _ in
expectation.fulfill()
}

waitForExpectations(timeout: 2.0)

XCTAssertEqual(sdk.lastPostPath, "push")
XCTAssertEqual(sdk.lastPostParams?["event"] as? String, "purchase")
XCTAssertEqual(sdk.lastPostParams?["gift_package"] as? Bool, true)
}

func test_purchaseWithoutGiftPackage_omitsTheKey() {
let sdk = MockPersonalizationSDK()
let service = TrackEventServiceImpl(sdk: sdk)
let expectation = expectation(description: "purchase tracked")

TrackingAPIImpl(trackService: service, sourceService: TrackSourceServiceSpy())
.purchase(Self.purchaseRequest(isGiftPackage: false)) { _ in
expectation.fulfill()
}

waitForExpectations(timeout: 2.0)

XCTAssertEqual(sdk.postCallCount, 1)
XCTAssertEqual(sdk.lastPostParams?["event"] as? String, "purchase")
XCTAssertNil(sdk.lastPostParams?["gift_package"])
}

private static func purchaseRequest(isGiftPackage: Bool) -> PurchaseTrackingRequest {
PurchaseTrackingRequest(
orderId: "order-1",
orderPrice: 100,
items: [PurchaseItemRequest(id: "sku-1", amount: 1, price: 100)],
isGiftPackage: isGiftPackage
)
}

func test_searchResults_reachTheWireAsCommaSeparatedList() {
let sdk = MockPersonalizationSDK()
let service = TrackEventServiceImpl(sdk: sdk)
Expand Down
6 changes: 5 additions & 1 deletion REES46/Classes/Model/PurchaseTrackingRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public struct PurchaseTrackingRequest {
public let stream: String?
public let segment: String?

public let isGiftPackage: Bool

public init(
orderId: String,
orderPrice: Double,
Expand All @@ -44,7 +46,8 @@ public struct PurchaseTrackingRequest {
custom: [String: Any]? = nil,
recommendedSource: [String: Any]? = nil,
stream: String? = nil,
segment: String? = nil
segment: String? = nil,
isGiftPackage: Bool = false
) {
self.orderId = orderId
self.orderPrice = orderPrice
Expand All @@ -63,5 +66,6 @@ public struct PurchaseTrackingRequest {
self.recommendedSource = recommendedSource
self.stream = stream
self.segment = segment
self.isGiftPackage = isGiftPackage
}
}
4 changes: 4 additions & 0 deletions REES46/Classes/Tracking/Service/impl/TrackServiceImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class TrackEventServiceImpl: TrackEventServiceProtocol {
static let removeWish = "remove_wish"
static let paymentType = "payment_type"
static let taxFree = "tax_free"
static let giftPackage = "gift_package"
static let fullCart = "full_cart"
static let fullWish = "full_wish"
static let wish = "wish"
Expand Down Expand Up @@ -441,6 +442,9 @@ class TrackEventServiceImpl: TrackEventServiceProtocol {
if request.isTaxFree {
params[Constants.taxFree] = true
}
if request.isGiftPackage {
params[Constants.giftPackage] = true
}
if let promocode = request.promocode?.trimmingCharacters(in: .whitespacesAndNewlines), !promocode.isEmpty {
params[Constants.promocode] = promocode
}
Expand Down
Loading