Expand my Community achievements bar.

Join us January 15th for an AMA with Champion Achaia Walton, who will be talking about her article on Event-Based Reporting and Measuring Content Groups!
SOLVED

Recently implemented OneTrust consent manager (hardcoded) and need help!

Avatar

Level 3

We have hard coded the OneTrust cookie consent manager to the site, and to be GDPR compliant we have had to use an opt-in methodology, whereby upon entering the site all cookies are blocked until the user accepts them. However, this has meant that it looks like the pageview tag is not firing once the customer accepts all cookies for the first page, it only fires once someone navigates to a new page. This means we are losing a heap of single-page visit traffic.

How can we get the pageview to fire for that same first page once cookies are accepted?

1 Accepted Solution

Avatar

Correct answer by
Level 10

Welcome to OneTrust nightmare implementation. Their SDK is flowed and it is fairly difficult to work with (at least I found). We had contractors that have done the job but finally we can to redo the whole thing as we had same issues as you experience.

 

So if you set the adobe opt in to disable by default I believe that Adobe will queue the analytics call if you send them and as soon as you reenable the opt in again it will send the queued analytics calls.

 

Right:

 

First of all we asked our developers to send an custom event for us to piggyback on. They deployed this code before Adobe launch script is injected. OneTrust does provide a function you can overwrite to do what you need called `OptanonWrapper`

 

 

function OptanonWrapper() {
    //Dispatch event for Adobe Launch
    window.dispatchEvent(new Event('oneTrustCategoriesChanged'))
}

 

 

Please be aware that this function will be called when onetrust load and categories changes (nightmare I said).

So what we need to do in Adobe Launch is to listen for the custom event then evaluate the condition if cookie OptanonAlertBoxClosed is present and the value is in date format. Once it is true then update Adobe Opt in based on optanon cookie preference.

 

We have also created a private extension to create a queue system for marketing tags but it is out of scope of this response

 

Event:

  • Name: Core - Custom Event - oneTrustCategoriesChanged
  • Config:
    • Extension: Core
    • Event type: Custom Event
    • Custom Event Type: oneTrustCategoriesChanged
      • Make sure to select any element

Condition

  • Name: Core - Cookie - OptanonAlertBoxClosed ~ ^\d{4}-\d{2}-\d{2}T
  • Config
    • Logic Type: regular
    • Extension: Core
    • Condition Type: Cookie
    • Return true if the cookie name OptanonAlertBoxClosed has the value ^\d{4}-\d{2}-\d{2}T (regexxswitch selected)

Actions

  • Name: Update Adobe OptIn Status
  • This will require some code that I will describe. Up to you to either put everything in the same custom code action or create data element to reuse later on. I am taking this from a private extension that I wrote but the whole code should work if pasted in custom code as is.

 

function getGroupsFromCookie() {
    try {
        _satellite.logger.info('Checking Consent taken from OneTrust cookie OptanonConsent');
        var consentCookie = _satellite.cookie.get('OptanonConsent');
        if (typeof consentCookie !== 'undefined' && consentCookie) {
            var value = ',' + consentCookie.split('groups=')[1].split('&')[0].match(/(C000\d):1/gi).join(',').replace(/:1/g, ''); //you might want to change that if you cookie categories are different
            _satellite.logger.info('Cookie Consent taken from OneTrust cookie OptanonConsent');
            return value;
        }
        _satellite.logger.info('Consent not found in OneTrust cookie');
        return '';
    } catch (e) {
        _satellite.logger.info('Failed while Checking Consent from cookie', e);
        return '';
    }
}

function getGroupsFromOnetrustObject() {
    try {
        _satellite.logger.info('Checking Consent taken from OneTrust Object OptanonActiveGroups');
        var oneTrustObject = window['OptanonActiveGroups'];
        if (oneTrustObject && oneTrustObject !== ',,') {
            turbine.logger.info('Cookie Consent taken from OneTrust Object OptanonActiveGroups', );
            return oneTrustObject;
        }
        _satellite.logger.info('Consent not found in OneTrust Object');
        return '';
    } catch (e) {
        _satellite.logger.info('Failed while Checking Consent from OneTrust Object', e);
        return '';
    }
}

function getPreferences() {
    try {
        var consentSettings;

        var cookieGetters = [
            getGroupsFromOnetrustObject,
            getGroupsFromCookie
        ];

        for (var i = 0; i < cookieGetters.length; i++) {
            consentSettings = cookieGetters[i]();
            if (consentSettings) {
                break;
            }
        }

        return consentSettings;
    } catch (e) {
        _satellite.logger.error('Failed to get onetrust consent settings - ' + e);
    }
}

function getAdobeOptInStatus() {
    try {
        var preferences = getPreferences();

        var aa = false;
        var aam = false;
        var ecid = false;
        var target = false;

        if (preferences.match(/C0009/g)) { //same might be different for you in terms of which group to use
            aa = true;
            target = true;
            ecid = true;
        }

        if (preferences.match(/C0002.*C0009|C0009.*C0002/)) { //same might be different for you in terms of which group to use
            aam = true;
        }

        return {
            "aa": aa,
            "aam": aam,
            "ecid": ecid,
            "target": target
        }
    } catch (e) {
        _satellite.logger.error('Failed to get Adobe Opt In Status', e);
    }
}

function updateAdobeOptInStatus() {
    try {
        var groups = getPreferences();
        var storedGroups = sessionStorage.getItem('optanonActiveGroups');
        if (((storedGroups && storedGroups !== groups) || !storedGroups) && typeof adobe !== 'undefined') {
            _satellite.logger.log('Updating Adobe Opt In Status');
            var adobeOptInStatus = getAdobeOptInStatus();
            for (var key in adobeOptInStatus) {
                if (adobeOptInStatus[key]) {
                    adobe.optIn.approve([key], true);
                } else {
                    adobe.optIn.deny([key], true);
                }
            }
            adobe.optIn.complete();
            adobe.optIn.fetchPermissions(updateAdobeOptInStatusCallback);
            sessionStorage.setItem('optanonActiveGroups', groups);
        }
    } catch (e) {
        turbine.logger.error('Failed in updateAdobeOptInStatus -- ', e);
    }
}

function updateAdobeOptInStatusCallback() {
    turbine.logger.log('Adobe OptIn Status updated', adobe.optIn.isComplete, adobe.optIn.status);
}


try {
    updateAdobeOptInStatus();
} catch (e) {
    _satellite.logger.error('Failed to update Adobe OptIn Status', e);
}

Hope this helps with the analytics calls. That is a lot of code but there is nothing much you can do about it if you want to cover all the basis. That is also a leaned version of the code we have as we have logic where we check cookie preference in query params and some default behaviour we set.

 

There is a way to queue the marketing tags as well but unlike Adobe you will have to create the solution manually. Might do a post about this as I complete my auto-tagging series.

 

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Welcome to OneTrust nightmare implementation. Their SDK is flowed and it is fairly difficult to work with (at least I found). We had contractors that have done the job but finally we can to redo the whole thing as we had same issues as you experience.

 

So if you set the adobe opt in to disable by default I believe that Adobe will queue the analytics call if you send them and as soon as you reenable the opt in again it will send the queued analytics calls.

 

Right:

 

First of all we asked our developers to send an custom event for us to piggyback on. They deployed this code before Adobe launch script is injected. OneTrust does provide a function you can overwrite to do what you need called `OptanonWrapper`

 

 

function OptanonWrapper() {
    //Dispatch event for Adobe Launch
    window.dispatchEvent(new Event('oneTrustCategoriesChanged'))
}

 

 

Please be aware that this function will be called when onetrust load and categories changes (nightmare I said).

So what we need to do in Adobe Launch is to listen for the custom event then evaluate the condition if cookie OptanonAlertBoxClosed is present and the value is in date format. Once it is true then update Adobe Opt in based on optanon cookie preference.

 

We have also created a private extension to create a queue system for marketing tags but it is out of scope of this response

 

Event:

  • Name: Core - Custom Event - oneTrustCategoriesChanged
  • Config:
    • Extension: Core
    • Event type: Custom Event
    • Custom Event Type: oneTrustCategoriesChanged
      • Make sure to select any element

Condition

  • Name: Core - Cookie - OptanonAlertBoxClosed ~ ^\d{4}-\d{2}-\d{2}T
  • Config
    • Logic Type: regular
    • Extension: Core
    • Condition Type: Cookie
    • Return true if the cookie name OptanonAlertBoxClosed has the value ^\d{4}-\d{2}-\d{2}T (regexxswitch selected)

Actions

  • Name: Update Adobe OptIn Status
  • This will require some code that I will describe. Up to you to either put everything in the same custom code action or create data element to reuse later on. I am taking this from a private extension that I wrote but the whole code should work if pasted in custom code as is.

 

function getGroupsFromCookie() {
    try {
        _satellite.logger.info('Checking Consent taken from OneTrust cookie OptanonConsent');
        var consentCookie = _satellite.cookie.get('OptanonConsent');
        if (typeof consentCookie !== 'undefined' && consentCookie) {
            var value = ',' + consentCookie.split('groups=')[1].split('&')[0].match(/(C000\d):1/gi).join(',').replace(/:1/g, ''); //you might want to change that if you cookie categories are different
            _satellite.logger.info('Cookie Consent taken from OneTrust cookie OptanonConsent');
            return value;
        }
        _satellite.logger.info('Consent not found in OneTrust cookie');
        return '';
    } catch (e) {
        _satellite.logger.info('Failed while Checking Consent from cookie', e);
        return '';
    }
}

function getGroupsFromOnetrustObject() {
    try {
        _satellite.logger.info('Checking Consent taken from OneTrust Object OptanonActiveGroups');
        var oneTrustObject = window['OptanonActiveGroups'];
        if (oneTrustObject && oneTrustObject !== ',,') {
            turbine.logger.info('Cookie Consent taken from OneTrust Object OptanonActiveGroups', );
            return oneTrustObject;
        }
        _satellite.logger.info('Consent not found in OneTrust Object');
        return '';
    } catch (e) {
        _satellite.logger.info('Failed while Checking Consent from OneTrust Object', e);
        return '';
    }
}

function getPreferences() {
    try {
        var consentSettings;

        var cookieGetters = [
            getGroupsFromOnetrustObject,
            getGroupsFromCookie
        ];

        for (var i = 0; i < cookieGetters.length; i++) {
            consentSettings = cookieGetters[i]();
            if (consentSettings) {
                break;
            }
        }

        return consentSettings;
    } catch (e) {
        _satellite.logger.error('Failed to get onetrust consent settings - ' + e);
    }
}

function getAdobeOptInStatus() {
    try {
        var preferences = getPreferences();

        var aa = false;
        var aam = false;
        var ecid = false;
        var target = false;

        if (preferences.match(/C0009/g)) { //same might be different for you in terms of which group to use
            aa = true;
            target = true;
            ecid = true;
        }

        if (preferences.match(/C0002.*C0009|C0009.*C0002/)) { //same might be different for you in terms of which group to use
            aam = true;
        }

        return {
            "aa": aa,
            "aam": aam,
            "ecid": ecid,
            "target": target
        }
    } catch (e) {
        _satellite.logger.error('Failed to get Adobe Opt In Status', e);
    }
}

function updateAdobeOptInStatus() {
    try {
        var groups = getPreferences();
        var storedGroups = sessionStorage.getItem('optanonActiveGroups');
        if (((storedGroups && storedGroups !== groups) || !storedGroups) && typeof adobe !== 'undefined') {
            _satellite.logger.log('Updating Adobe Opt In Status');
            var adobeOptInStatus = getAdobeOptInStatus();
            for (var key in adobeOptInStatus) {
                if (adobeOptInStatus[key]) {
                    adobe.optIn.approve([key], true);
                } else {
                    adobe.optIn.deny([key], true);
                }
            }
            adobe.optIn.complete();
            adobe.optIn.fetchPermissions(updateAdobeOptInStatusCallback);
            sessionStorage.setItem('optanonActiveGroups', groups);
        }
    } catch (e) {
        turbine.logger.error('Failed in updateAdobeOptInStatus -- ', e);
    }
}

function updateAdobeOptInStatusCallback() {
    turbine.logger.log('Adobe OptIn Status updated', adobe.optIn.isComplete, adobe.optIn.status);
}


try {
    updateAdobeOptInStatus();
} catch (e) {
    _satellite.logger.error('Failed to update Adobe OptIn Status', e);
}

Hope this helps with the analytics calls. That is a lot of code but there is nothing much you can do about it if you want to cover all the basis. That is also a leaned version of the code we have as we have logic where we check cookie preference in query params and some default behaviour we set.

 

There is a way to queue the marketing tags as well but unlike Adobe you will have to create the solution manually. Might do a post about this as I complete my auto-tagging series.

 

Avatar

Level 1

Hi, clairea.

Has your issue been resolved or not? can you please provide me with any document for that implementation for that or can you tell me which changes you made in the global page view load rule?

I will be grateful if you reply to this comment.

 

Thanks & Regards,

Adarsh Tank.