Skip to main content

โš™๏ธ Google Tag Manager

After this guide, you will have the knowledge to implement sale conversion tracking over Google Tag Manager.

note

This guide assumes that you understand the functionality of Google Tag Manager and are familiar with JavaScript.

Due to the openness of Google Tag Manager (GTM) it is not possible to provide a script that works right out of the box. Nevertheless, the following script can be used as a guideline to keep efforts low.

Since it is most likely that you will have to customize the script, it is strongly recommended hat you read through the introduction, tracking overview and sale conversion tracking guides first.

caution

The user tracking container must be installed first before you can start using this integration.

Requirementsโ€‹

If you want to integrate sale conversion tracking with GTM, make sure the following requirements are met:

  1. A purchase trigger exists, that is fired after a purchase has happened.
  2. A fully filled GA4 ecommerce purchase object or detailed order information are available in the data layer, when the trigger fires.

Sale conversion scriptโ€‹

This script uses data from the enhanced ecommerce object to build and send a sale conversion tracking request to Linkster.

The ecommerce object is a data structure that google recommends for tracking sales data. However, this does not mean that this object is automatically present in your data layer. You/your developers have to implement it explicitly for it to be available.

caution

It is assumed that all line item prices are net priced with deducted discounts.

If your line item prices are not net prices with deducted discounts, you would need to adapt the script to your data structure. Read more about on how to calculate and transmit net prices to Linkster here.

We assume, that you are pushing GA4 purchase events to the GTM datalayer.

This script should be implemented as a Tag of type Custom HTML. Please replace the variable placeholders (written UPPERCASE) with the variable name of your GTM Setup. Your Linkster campaign ID was communicated to you in the onboarding briefing. Please contact us if you do not have it.:

<script>
var campaignId = YOUR_LINKSTER_CAMPAIGN_ID; // set YOUR_LINKSTER_CAMPAIGN_ID to your campaign id
var cookieEmid = document.cookie.match(/emid\=([a-zA-Z0-9\-\_]+)/i);
var emid = window.localStorage['emid'] || (cookieEmid === null || cookieEmid === void 0 ? void 0 : cookieEmid[1]);

/* order variables */
var ordertoken = {{INSERT_DLV_TRANSACTION_ID}};
var attribution = 1;
var currency = {{INSERT_DLV_CURRENCY}};
var items = {{INSERT_DLV_ITEMS}} || [];
var voucherCode = {{INSERT_DLV_COUPON}};
var triggerId = 1;
var basket = [];

/* basket item object */
/* fore ach item in basket */
items.forEach(function (item) {
basket.push({
'campaign_id': campaignId,
'attribution': attribution,
'emid': emid,
'trigger_id': triggerId,
'token': ordertoken,
'article_number': item.item_id,
'productname': item.item_name,
'category': item.item_category,
'amount': item.quantity,
'price': item.price,
});
});

var trackingUrl = 'https://trck.linkster.co/trck/ebasket/?json=' + encodeURIComponent(JSON.stringify(basket)) + '&currency=' + currency + '&vc=' + encodeURIComponent(voucherCode);
var req = new XMLHttpRequest(); req.withCredentials = true; req.open("GET", trackingUrl); req.send();
</script>

Testing the integrationโ€‹

It is always best practice to test your work. Testing your sale conversion script consists of four simple steps.

  1. Start a new debugging session from within GTM.

  2. Open your browser's network tab (Right click > Inspect > Network)

    2.1. If you see a checkbox named Preserve log, make sure it is checked.

    Chrome network tabChrome network tab

  3. Make a test purchase in the debugging session.

  4. Check in your browser's network tab/tool if an HTTP GET request has been sent to https://trck.linkster.co/trck/ebasket/ and make sure it contains all required attributes. The status of the request should be in the okay range (200 - 299) and under Payload you should see all your order information in a structure looking like this:

    Chrome network tabChrome network tab

If you don't see this request at the end of your order process, it means that there is still at least one error in your integration. You can check the troubleshooting section for more information.

Troubleshootingโ€‹

No HTTP request was sentโ€‹

If no HTTP request was sent, this could either be because the set trigger did not fire or the sale conversion script threw an error.

Check in your GTM debugging tab if the sale conversion script tag was fired in the first place.

If the script was fired, but you don't see a request in the network tab, it is most likely that the sale conversion script threw an error. In this case, check the error message in your browser's JavaScript console.

Possible error causesโ€‹

  • GTM couldn't find one ore more of the {{INSERT_DLV_...}} variables. Maybe you have misspelled them?
  • The data structure of items is incompatible with your sale conversion script.

Make sure that the object paths you are accessing in code are present in the custom variables.

Incomplete request payload / missing dataโ€‹

If your request payload has not all the required attributes or some keys of the required basket data are missing, check if your variables contain the needed data and check if your sale conversion script access this data correctly. See possible error causes from above for more information.