Skip to content

Commit

Permalink
chore: deprecate purchase event top-level queryID param (#522)
Browse files Browse the repository at this point in the history
Create distinct type for `purchase` event parameters - same as a normal
`conversion` event but the top-level `queryID` is optional and
deprecated.

[EEX-808](https://algolia.atlassian.net/browse/EEX-808)

[EEX-808]:
https://algolia.atlassian.net/browse/EEX-808?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
  • Loading branch information
jkaho authored Nov 30, 2023
1 parent b803f95 commit 4a88391
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/__tests__/conversion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ describe("addedToCartObjectIDsAfterSearch", () => {
describe("purchasedObjectIDsAfterSearch", () => {
const convertParams = {
index: "index1",
eventName: "Product added to cart",
eventName: "Product purchased",
objectIDs: ["12345"],
queryID: "test",
objectData: [
{
queryID: "query-1",
price: 12.99,
quantity: 2
}
Expand Down
12 changes: 10 additions & 2 deletions lib/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,20 @@ export function addedToCartObjectIDsAfterSearch(
);
}

export type InsightsSearchPurchaseEvent = Omit<
InsightsSearchConversionEvent,
"queryID"
> & {
/** @deprecated Use objectData.queryID instead. */
queryID?: string;
};

export function purchasedObjectIDsAfterSearch(
this: AlgoliaAnalytics,
...params: Array<WithAdditionalParams<InsightsSearchConversionEvent>>
...params: Array<WithAdditionalParams<InsightsSearchPurchaseEvent>>
): ReturnType<AlgoliaAnalytics["sendEvents"]> {
const { events, additionalParams } =
extractAdditionalParams<InsightsSearchConversionEvent>(params);
extractAdditionalParams<InsightsSearchPurchaseEvent>(params);

return this.sendEvents(
addEventTypeAndSubtype("conversion", "purchase", events),
Expand Down

0 comments on commit 4a88391

Please sign in to comment.