How to
Implement Retrack with Google Tag Manager (GTM)
This page will guide you through the process of implementing script tracking for Retrack in GTM. The implementation tries to use only GTM and thus lacks some features from the regular implementation, such as a separate redirect page. Instead, we rely on the existing features available in the GTM interface.
Important: Let us know if you plan to implement the tracking using only GTM, because we need to disable some features in order for the tracking to function correctly.
Please be careful when implementing the tracking code. We do not take responsibility for any bugs or damage. Test the implementation thoroughly, and consult a web developer if needed.
Create the Needed Variables
Go to Variables and click the New button. Create the following variables:
- 1. Click UUID
-
Name Retrack - Click UUID Type URL Component Type Query Query click - 2. Click UUID Cookie
-
Name Retrack - Click UUID Cookie Type 1st Party Cookie Cookie Name retrack - 3. UTM Source
-
Name UTM Source Type URL Component Type Query Query utm_source
Create the Needed Triggers
Go to Triggers and click the New button. Create the following triggers:
- 1. Page View From Refunder
-
Name Retrack - Page View From Refunder Type Page View This trigger fires on Some Page Views Conditions
Retrack - Click UUID does not equal undefined UTM Source equals refunder - 2. Order Completed
-
Name Retrack - Order Completed Type Page View This trigger fires on Some Page Views Conditions
Retrack - Click UUID Cookie does not equal undefined Page Path contains checkout Important: The last condition for Page Path is optional and should be adjusted for your setup. Make sure that the trigger is set up to fire on the order confirmation page.
Create the Needed Tags
Go to Tags and click the New button. Create the following tags:
- 1. Save Click UUID
-
Name Retrack - Save Click UUID Type Custom HTML HTML
<script> (function() { var cookieName = 'retrack'; var cookieValue = encodeURIComponent('{{Retrack - Click UUID}}'); if (!cookieValue) { // Uncomment line below for debugging purposes // console.warn('[retrack] cookie value not found'); return; } var targetDate = new Date(); targetDate.setDate(targetDate.getDate() + 10); // 10 days expiration var expires = targetDate.toUTCString(); var retrackCookie = cookieName + '=' + cookieValue + ';expires=' + expires + ';path=/;secure;samesite=lax'; document.cookie = retrackCookie; })(); </script>
Triggers
- Retrack - Page View From Refunder
- 2. Track Order
-
Name Retrack - Track Order Type Custom HTML HTML
<script type="text/javascript"> !function(){"re" in window||(window.re=function(){window.re.q.push(arguments)},window.re.q=[]);var e=document.createElement("script");e.src="https://retrack-app.com/track/v2/script",e.async=!0;var n=document.scripts[0];n.parentElement.insertBefore(e,n.nextSibling)}(); // Object. Required re('addTransaction', { // UUID. Base event for the transaction. Can be overridden on product level using addProduct event: '{eventUUID - replace with value from retrack portal}', // UUID. Replace with actual click UUID from cookie: Example: ce5fc4b5-0ddc-4176-ba64-44c3423bbae1 click: '{{Retrack - Click UUID Cookie}}', // String. Replace with actual order number. Example: test123 orderNumber: '{orderNumber - replace with value from GTM variable}', // Numeric. Replace with actual order sum in minor units (ie cents), excluding VAT. Example: 8000 (80 SEK) orderSum: {orderSum - replace with value from GTM variable (minor units = multiply by 100}, // Numeric. Replace with actual VAT sum in minor units (ie cents). Example: 2000 (20 SEK) vatSum: {vatSum - replace with value from GTM variable (minor units = multiply by 100}, // String. Replace with actual currency. Example: SEK currency: 'SEK', // String. Optional (remove or leave empty if not applicable). Replace with actual voucher / coupon code. Comma separated if there are multiple codes. voucher: '{voucher}', // String. Optional (remove or leave empty if not applicable). Applicable if the order has a general discount. Use minor units (ie cents) discountSum: {voucher - replace with value from GTM variable} }); re('send'); </script>
Important: This code is not complete and needs to be adjusted to your specific GTM setup. Use the variables for order data that you probably already have and insert them into the script. See the click property for an example of how to use GTM variables.
Note that GTM uses double curly brackets for variables, like this: {{variableName}}. However hard coded values like eventUUID should not have any curly brackets.
If you do not have variables for your order data, consult your developers.Triggers
- Retrack - Order Completed
Done
That's it! You have now implemented tracking for Retrack. We would now like to test the implementation before it goes live. Reach out to us with testing instructions.