Opt-in and -out of Tracking

Opt-in and -out of Tracking

  • updated 8 mths ago

Some countries have rules that prevent you from tracking users before they have decided to opt-in or -out. In those cases, you need to call the opt-out method, as described below, and when they then click on the consent button you can enable it again.

When you disable tracking of the users, the solutions will still work, but they won't be personalized for your customers.

Opt-out of all cookies

To opt-out of all cookies, the opt-out parameter needs to be set on our script before it loads. Our normal script snippet looks like this:

<script async src="https://helloretailcdn.com/helloretail.js"></script>
<script>
    window.hrq = window.hrq || [];
    hrq.push(['init', {}]);
</script>

This can be modified like this:

<script async src="https://helloretailcdn.com/helloretail.js"></script>
<script>
    window.hrq = window.hrq || [];
    hrq.push(['init', {
        trackingOptOut: true
    }]);
</script>

Notice the "trackingOptOut: true". This boolean can be set to true or false depending on if the visitor should be tracked or not. Since this is set before the script even loads, it will cause all cookies to be blocked.

You can find more information about cookie rules and GDPR here, as well as what cookies Hello Retail uses to provide a personalized shopping experience.

To disable the tracking onload you can use the following code-snippet just before </head> in your HTML. This requires a variable to represent whether the user has consented to marketing cookies. In our example, we have named this variable 'CONSENT_BOOLEAN'.

<script>
    hrq = window.hrq || [];
    hrq.push(function(sdk) {
        sdk.setTrackingOptOut(CONSENT_BOOLEAN ? false : true);
    });
</script>

Integration with cookie banners

When the customer gives consent to be tracked, you can call the following JavaScript method:

hrq = window.hrq || [];
hrq.push(["setTrackingOptOut", false]);

and we will begin personalizing the experience for the customer.

In the following section, we list some examples of how this can be achieved, if you are using some of the more common tools for handling consent.

Setup with CookieBot

Add the following lines of code just above </head> in your HTML. Then we won't track any users before they accept:

<script>
    hrq = window.hrq || [];
    hrq.push(function(sdk) {
        if (!Cookiebot.consent.marketing) {
            sdk.setTrackingOptOut(true);
        }
    });
</script>

Then just above </body> in your HTML add the following code:

<script>
    window.addEventListener('CookiebotOnLoad', function (e) {
        hrq = window.hrq || [];
        hrq.push(["setTrackingOptOut", !Cookiebot.consent.marketing]); 
    }, false);
 </script>

Remember to use the variable with one that is appropriate for the purpose needed. We have used  marketing in this example.

Setup with CookieInformation.com

Add the following lines of code just above </head> in your HTML. Then we won't track any users before they accept:

<script>
    hrq = window.hrq || [];
    hrq.push(function(sdk) {
        if (!CookieInformation.getConsentGivenFor('cookie_cat_marketing')) {
            sdk.setTrackingOptOut(true);
        }
    });
</script>

Then just above </body> in your HTML add the following code:

<script>
    window.addEventListener('CookieInformationConsentGiven', function(event) {
        hrq = window.hrq || [];
        hrq.push(["setTrackingOptOut", !CookieInformation.getConsentGivenFor('cookie_cat_marketing')]);
    });
</script>

Remember to use the variable with one that is appropriate for the purpose needed. We have used  cookie_cat_marketing in this example.

Setup with CookieYes

Add the following lines of code just above </head> in your HTML. Then we won't track any users before they accept:

<script>
    hrq = window.hrq || [];
    hrq.push(function(sdk) {
        if (document.cookie.includes("advertisement:no")) {
            sdk.setTrackingOptOut(true);
        }
    });
</script>

Then just above </body> in your HTML add the following code:

<script>
    document.addEventListener('cookieyes_consent_update', function (eventData) {
        const data = eventData.detail;
        const optOut = data.rejected.includes("advertisement");
        hrq = window.hrq || [];
        hrq.push(["setTrackingOptOut", optOut]);
    }, false);
 </script>

Remember to use the variable with one that is appropriate for the purpose needed. We have used  advertisement in this example.

 

Like Follow
  • 1 yr agoLast active
  • 1397Views
  • 1 Following