Google Tag Manager

Google Tag Manager

For tracking all page views and orders we need to install two custom pixels into GTM. The first one will be fired on all pages and tracks pageviews for Divvit. The second one will be fired only on the "thankyou" page after an order has been placed successfully and track orders for Divvit.

General Tracking Pixel

1

Log in to your GTM account, click on "Tags" in the left sidebar navigation and click the "New" button on top of the page. You should reach a screen like this:

General Tracking Pixel
2

Click on "Custom HTML Tag" and copy/paste the following code into the text field, replacing the YOUR_FRONTEND_ID with your Frontend ID from Divvit and modifying variable names as needed.

<script type="text/javascript"> !function(){var t=window.divvit=window.divvit||[];if(t.DV_VERSION="1.0.0",t.init=function(e){if(!t.bInitialized){var i=document.createElement("script");i.setAttribute("type","text/javascript"),i.setAttribute("async",!0),i.setAttribute("src","https://tag.divvit.com/tag.js?id="+e);var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(i,n)}},!t.bInitialized){t.functions=["customer","pageview","cartAdd","cartRemove","cartUpdated","orderPlaced","nlSubscribed","dv"];for(var e=0;e<t.functions.length;e++){var i=t.functions[e];t[i]=function(e){return function(){return Array.prototype.unshift.call(arguments,e),t.push(arguments),t}}(i)}}}(); divvit.init("YOUR_FRONTEND_ID"); divvit.pageview(); </script>
Copy to clipboard
3
Under the section "Triggering" make sure to select "All pages", so that the tracking code is invoked on all pages.
4
Click "Save" to create the tag with the configuration above.

Order Tracking Pixel

1

Go back to "Tags" by clicking in the left sidebar and select "New" to create another pixel. Choose the same settings as above ("Custom HTML Tag") and place the following code into the text field:

<script type="text/javascript"> var orderData = { order: { orderId: {{transactionId}}, total: {{transactionTotal}}, shipping: {{transactionShipping}}, // optional, if available currency: {{transactionCurrency}}, // optional, if available paymentMethod: {{transactionPaymentMethod}}, // optional, if available voucher: {{transactionDiscount}}, // optional, if available voucherDiscount: {{transactionDiscountCode}}, products: [], // optional, if available customer: { idFields: { customerId: {{transactionCustomerId}} } } } }; var orderItems = {{transactionProducts}} || []; for (var i = 0; i < orderItems.length; i++) { var orderItem = orderItems[i]; orderData.order.products.push({ id: orderItem.sku, name: orderItem.name, category: orderItem.category, price: orderItem.price, quantity: orderItem.quantity }); } divvit.orderPlaced(orderData); </script>
Copy to clipboard
2
To make sure that this pixel is fired after the general tracking pixel, in the section of Advanced settings underneath the text field please activate the checkbox "Fire a tag before Divvit Order Tracking fires." and select the first general Divvit tracking pixel from the select list.
3
Under the section ”Triggering" make sure to select a trigger that ensures that this pixel is only fired on the thankyou (checkout success) page.