File size: 713 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { recordOrder } from 'calypso/lib/analytics/ad-tracking';
import { costToUSD } from 'calypso/lib/analytics/utils';
import { gaRecordEvent } from './ga';
import type { ResponseCart } from '@automattic/shopping-cart';

export async function recordPurchase( {
	cart,
	orderId,
	sitePlanSlug,
}: {
	cart: ResponseCart;
	orderId: number | null | undefined;
	sitePlanSlug: string | null | undefined;
} ) {
	if ( cart.total_cost >= 0.01 ) {
		const usdValue = costToUSD( cart.total_cost, cart.currency );

		// Google Analytics
		gaRecordEvent(
			'Purchase',
			'calypso_checkout_payment_success',
			'',
			usdValue ? usdValue : undefined
		);

		// Marketing
		recordOrder( cart, orderId, sitePlanSlug );
	}
}