Google Tag Manager
The Google Tag Manager integration allows you to send purchase events to Google Tag Manager.
Tracking Code Example
The following code snippet is an example of how to send a purchase event to Google Tag Manager. You can use this code snippet as a reference to send purchase events to Google Tag Manager. Replace YOUR_GTM_ID with your Google Tag Manager ID.
The code snippet must be placed on the Thank You page of your checkout flow.
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','YOUR_GTM_ID');</script>
<!-- End Google Tag Manager -->
<script>
const urlParams = new URLSearchParams(window.location.search);
const total = urlParams.get('total');
const customerName = urlParams.get('customerName');
const customerEmail = urlParams.get('customerEmail');
const currency = urlParams.get('currency');
const productId = urlParams.get('productId');
const productName = urlParams.get('productName');
const purchaseId= urlParams.get('purchaseId');
dataLayer.push({
event: "purchase",
ecommerce: {
fullname:customerName,
email:customerEmail,
transaction_id: purchaseId,
value: total,
currency: currency,
items: [
{
item_id: productId,
item_name: productName,
price: total,
quantity: 1
}]
}
});
</script>