Skip to content

Commit b7bf8db

Browse files
authored
Merge pull request #2069 from Aleperix/aleperix-ft-ga-purchase-tracking
Add transaction_id and adaptedItems to purchase event in dataLayer
2 parents 51190ca + 95e30ec commit b7bf8db

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/hooks/useSignup.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,15 +550,24 @@ const useSignup = () => {
550550
simplePlans = [{ plan: restOfPlan }];
551551
}
552552

553+
const adaptedItems = simplePlans.map((planObj) => ({
554+
item_id: planObj.plan.slug,
555+
item_name: planObj.plan.slug,
556+
price: transactionData?.amount || 0,
557+
quantity: 1,
558+
item_category: 'subscription',
559+
subscription_period: selectedPlan?.period_label || 'one-time',
560+
}));
553561
reportDatalayer({
554562
dataLayer: {
555563
event: 'purchase',
556-
value: selectedPlan?.price || 0,
564+
transaction_id: transactionData?.id,
565+
value: transactionData?.amount || 0,
557566
currency,
558567
payment_type: 'Credit card',
559568
plan: selectedPlan?.plan_slug || transactionData?.plan?.slug || defaultPlan,
560569
period_label: selectedPlan?.period_label || 'one-time',
561-
items: simplePlans,
570+
items: adaptedItems,
562571
agent: getBrowserInfo(),
563572
},
564573
});

0 commit comments

Comments
 (0)