Tuesday, June 26, 2018

PeopleTools - Opt-out option for Google Analytics

With GDPR taking effect on May 25th 2018, an "opt-out" option for tracking cookies is a prevalent topic in many forums. This post is not intended to provide guidance for GDPR compliance. FWIW, before implementing anything at the PeopleTools layer, we must first consider the privacy policy implications at a much broader organizational level.

That said, I have written several posts on how to implement Google Analytics in PeopleTools. The most recent approach uses gtag.js.
PeopleTools - Using Google Analytics (gtag.js)

This post describes a proof of concept to extend the gtag.js implementation to provide a simple "opt-out" feature for end users using client side code (javascript).

Demo

In the following video, we can see that the user selects the "opt-out" option and the custom opt-out cookie is created. Any subsequent requests will not be tracked in Google Analytics.


Google Analytics Real-Time Data


In the following video, we can see that the user dismisses the "opt-out" option and the custom opt-out cookie is not created. Any subsequent requests will continue to be tracked in Google Analytics.


Google Analytics Real-Time Data


Script for reference

Notes

- This version of javascript, identifies the existence of Google Analytics related cookies to check if the session is new.
- If the session is new, a popup message is displayed to the end user. The message also provides a link to "opt-out" of Google Analytics. For the purposes of this demo, I used the delivered ptSetConfirmationMessage and ptCloseConfirmation javascript functions (which are part of PT_UTIL_BASIC HTML object) to display this message.
- If the user chooses to "opt-out" of Google Analytics, the following window property is set to true.
window['ga-disable-UA-XXXXXX-Y'] = true;
- Additionally, a custom cookie (ga-disable-UA-XXXXXXXX-Y) is created to identify this choice for subsequent requests.
- This cookie preference/choice will persist as long as this custom cookie is present.

This proof of concept is only intended to provide implementation ideas. You will most certainly need to tweak this code based on your organization's privacy policy.

Useful Resources

https://developers.google.com/analytics/devguides/collection/analyticsjs/user-opt-out
https://developers.google.com/analytics/devguides/collection/gajs/
https://www.robert-matthees.de/datenschutz-cookies/

Related Posts

Implementing Google Analytics in PeopleTools using gtag.js
Implementing Google Analytics in PeopleTools using analytics.js
Implementing Google Analytics in PeopleTools using ga.js