Skip to main content
All CollectionsFAQsCompliance and Data Governance
How to Implement the DoNotTrack Function for Event Tracking
How to Implement the DoNotTrack Function for Event Tracking
Updated over a month ago

To respect user privacy and comply with regulatory requirements, you can implement a do not track (opt-out function) that disables event tracking for your users. Below are the steps and code examples to help you integrate this feature into your website.

Step 1: Implement the DoNotTrack Function

You need to define a JavaScript function that sets a cookie and local storage to indicate that a user has opted out of tracking. This function ensures that no further tracking occurs.

//This sets the cookies our script will check for consent
function setOptOutCookie() {
document.cookie = "_EventConsentStatusGE=Optout; expires=Fri, 31 Dec 9999 23:59:59 GMT";
localStorage.setItem("_EventConsentStatusGE", "Optout");
}

function DoNotTrack(accountID) {
setOptOutCookie();
if (typeof geq !== 'undefined' && geq.doNotTrack) {
geq.doNotTrack(accountID);
}
}

Step 2: Call the DoNotTrack Function

To activate the opt-out for a user, call the DoNotTrack function you’ve defined with the appropriate accountID provided by the R! Implementation team.

Note: Only call this function if you do not intend for this user to be tracked. Calling this function at the wrong times, or when a user is in fact okay to be tracked, can reduce the effectiveness of our products.

// Example call to the DoNotTrack function 
DoNotTrack("YourAccountIDHere");
Replace "YourAccountIDHere" with the actual account ID provided by the R! Implementation team.

Step 3: (Optional) Implement the Opt-Back-In (Track) Function

While not mandatory, we recommend adding an opt-back-in function to your implementation. This function allows users to opt back into event tracking after previously opting out.

Note: The opt-in function should not be called for every user. If neither the opt-out nor the opt-in function is called, our script will track users once it is loaded.

The opt-back-in function removes the previously set cookies and local storage values indicating that the user opted out, thus re-enabling tracking. Once the user opts back in, tracking will resume.

// This removes the cookies and local storage indicating opt-out
function setOptBackInCookie() {
document.cookie = "_EventConsentStatusGE=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
localStorage.removeItem("_EventConsentStatusGE");
}

function optBackIn(accountID) {
setOptBackInCookie();
if (typeof geq !== 'undefined' && geq.track) {
geq.track(accountID);
}
}

Explanation:

  • This function removes the opt-out cookie and local storage to clear the user's opt-out status, effectively opting the user back into event tracking.

When to Use This Function:

  • The opt-in (track function is not intended to be used for every user.

  • It should be called only in situations where a user previously opted out but has now explicitly opted back into tracking.

Shopify R! Pixel

Our Shopify pixel is built to acknowledge successful geq.DoNotTrack() requests automatically, however, we also support allowing for OptOuts to be sent directly to the R! Pixel via Shopify for pages that do not enable third party scripts to fire (i.e. Checkout Page).

Opt-Out (DoNotTrack)

Shopify.analytics.publish('custom_geq', { name: 'doNotTrack', data: {label: account.hashid }});

Opt-In

Shopify.analytics.publish('custom_geq', { name: 'track', data: { label: scriptID }});

Recommendations for Using Consent Management Platforms:

  • If using a service like OneTrust:

    • Delay Loading the Script: We recommend not loading our script until you have determined whether the user consents to being tracked.

    • Post-Consent Removal: If our script has already been loaded and the user later withdraws consent, you should immediately call the DoNotTrack function to disable tracking.

    • For detailed information on integrating the Retention script with OneTrust and other cookie consent tools, please refer to our documentation here.

  • Client-Side Cookies: This solution requires our cookies to be preserved and maintained to ensure the opt-out status is recognized across sessions.

Did this answer your question?