Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use items in purchase ids #283

Merged
merged 2 commits into from
Sep 4, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ We follow the format used by [Open Telemetry](https://github.com/open-telemetry/
### Fixed
- Fix truncation of `seenEvents`
([#282](https://github.com/Topsort/analytics.js/pull/282))
- Fix id of purchase events
([#283](https://github.com/Topsort/analytics.js/pull/283))

## Version 2.3.1 (2024-04-11)

Expand Down
9 changes: 9 additions & 0 deletions src/detector.purchases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ test("check purchase", async () => {
});
document.body.innerHTML = `
<div data-ts-action="purchase" data-ts-items='[{"product":"product-id-purchase1", "price": "2399", "quantity": 1}, {"product":"product-id-purchase2", "price": "299", "quantity": 1}, {"product":"product-id-purchase3", "price": "399", "quantity": 4}]'></div>
<div data-ts-action="purchase" data-ts-items='[{"product":"product-id-purchase-after", "price": "2199", "quantity": 1}]'></div>
`;
await import("./detector");

Expand All @@ -25,5 +26,13 @@ test("check purchase", async () => {
{ product: "product-id-purchase3", price: "399", quantity: 4 },
],
},
{
type: "Purchase",
page: "/",
product: undefined,
bid: undefined,
id: expect.stringMatching(/[\d.a-zA-Z-]+/),
items: [{ product: "product-id-purchase-after", price: "2199", quantity: 1 }],
},
]);
});
5 changes: 4 additions & 1 deletion src/detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ function logEvent(info: ProductEvent, node: Node) {
}

function getId(event: ProductEvent): string {
return [event.page, event.type, event.product ?? event.additionalProduct, event.bid].join("-");
const items = JSON.stringify(event.items || []);
return [event.page, event.type, event.product ?? event.additionalProduct, event.bid, items].join(
"-",
);
}

function getPage(): string {
Expand Down