Skip to main content
All CollectionsAdvanced Topics
Integrating MetaLocator & OneTrust
Integrating MetaLocator & OneTrust

Configure MetaLocator to respond to user cookie and tracking preferences

Michael Fatica avatar
Written by Michael Fatica
Updated yesterday

When configuring MetaLocator to work with a consent management platform like OneTrust there are a few use cases to consider:

  1. A new user has visited the page with MetaLocator installed, they are presented with a OneTrust consent banner, and the MetaLocator UI also loads. In this case MetaLocator should be loaded with cookies disabled, and cookies should be enabled dynamically if the user chooses to allow them.
    โ€‹

  2. An existing user who has previously provided consent answers has visited the page with MetaLocator installed. In this case MetaLocator should be loaded with cookies enabled or disabled automatically based on the previously-provided consent settings.

  3. An existing user who has previously provided consent answers changes their preferences while on the page with MetaLocator installed.

<script type="text/javascript"> 
// Handle changes to User Cookie Preferences, (scenarios 2 and 3)
// Per OneTrust:
// The OptanonWrapper function is called after banner script execution.
// You can use the OptanonWrapper function to listen for a user event and determine script behavior based on the user event.
// https://my.onetrust.com/s/article/UUID-29158b4e-22f6-0067-aa36-94f3b8cf3561?language=en_US&topicId=0TO1Q000000ssJBWAY
function OptanonWrapper() {

if(typeof OneTrust !== 'undefined') {

OneTrust.OnConsentChanged(function(e) {

// when both functional and performance cookies are accepted, we enable tracking
// these values may need customization based on your cookie requirements
// find your cookie IDs from OneTrust as described here:
// https://my.onetrust.com/s/article/UUID-8102e851-d860-d465-d8d6-b1d636d68eb9?language=en_US
const requiredCookies = ["C0001", "C0002"];
// if we have all values, then we don't opt out
const optOut = requiredCookies.every(value => {

// START these lines can be removed
console.log("DEBUG: Received consent for the following cookies");
console.log(e.detail);
// END these lines can be removed

return e.detail.includes(value);
}) ? 0 : 1;
if(typeof ml___setOptOutState === 'function') {

// START these lines can be removed
console.log("DEBUG: Setting MetaLocator Tracking to opt-out = " + optOut);
// END these lines can be removed
// tell MetaLocator to dynamically set tracking.
// optOut = 1 disables tracking, optOut = 0 enables it
ml___setOptOutState(optOut);

}

});
}
}
</script>

<script>
// this signals to MetaLocator to disable tracking by default
// ensuring tracking is not enabled when the page loads (scenario 1)
var ml___params = {"_opt_out":1};
</script>

<!-- MetaLocator.com Code START --><script data-ot-ignore language="javascript" src="//code.metalocator.com/index.php?option=com_locator&view=directory&layout=_javascript&framed=1&format=raw&tmpl=component&no_html=1&Itemid=XXXXXXXXX"></script><!-- MetaLocator.com Code END: Do not modify this code block. See TOS for details. -->

The code starting with <!-- MetaLocator.com Code START --> is the usual MetaLocator installation code provided with your Interface. Be sure to update the code above to use your installation code.

You may also need to customize the cookie IDs by updating the line:

const requiredCookies = ["C0001", "C0002"];

Some customers have customized these IDS. Find your OneTrust IDs as described in this article:

https://my.onetrust.com/s/article/UUID-8102e851-d860-d465-d8d6-b1d636d68eb9?language=en_US

Update the requriedCookies variable to include the cookie categories that should enable MetaLocator to track analytics.

Debug mode can also be enabled in your interface to watch the flow of analytics data. Update this Interface setting, found under Analytics Settings, to Yes, which will enable Web developer console output showing analytics events.

Messages similar to the below will appear in the Web developer console, enabling visibility into the tracking system.

Did this answer your question?