Skip to main content

Integration with web analytics

The integration functionality with data analytics libraries allows you to keep track of events in order to monitor user interactions with the banner and collect data in this regard.

If you want to use Google Analytics with OIL, and therefore be able to collect the data useful for generating the Cookie Banner Statistics, you can use the OIL Events (described in the appropriate section) and track them through your GA installation.

Below we see an example of integration with Google Tag Manager:

NB: the tracker name (UA-XXXXXX-Y) must be taken from your GA account in the admin panel.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async   src="https://www.googletagmanager.com/gtag/js?id=CODICE_ANALYTICS"></script>
<script>
   window.dataLayer = window.dataLayer || [];
   function gtag(){dataLayer.push(arguments);}
   gtag('js', new Date());
   gtag('config', 'CODICE_ANALYTICS',{ 'anonymize_ip': true });  
</script>

NB:_ In order to anonymously collect the events sent to Google Analytics it is necessary to also enter the following in the configuration:_

{ 'anonymize_ip': true }

In this example we want to monitor and send to Google Analytics the event that is triggered when the cookie acceptance button is clicked. In the page we insert a script that listens for events, checks if the event is oil_optin_done and if so sends it to GA.

<script>
    window.ga('create', 'UA-XXXXXXXX-Y', {'name': 'avacyTracker'});
    window.addEventListener('message', message => {
        if( message.data == "oil_optin_done") {
            window.ga('avacyTracker.send', {
                hitType: 'event',
                eventCategory: 'OIL',
                eventAction: message.data,
                eventLabel: 'test'
            });
        }
    });
</script>

Once the event has been sent, you can verify that it has been intercepted in the Analytics dashboard under Behavior > Events.

alt_text

Categorization of events on Google Analytics

Here is a table of event types that are sent to your Google Analytics installation.

Event LabelDescription
Banner ShownEvent sent when the banner is displayed to the user.
clickEvent sent when the user accepts.
click from settingsEvent sent when the user accepts after modifying preferences from the Cookie Control Panel.
scrollEvent sent when the user accepts by scrolling the page. (NOTE: consent given through scrolling is no longer considered legal by the Data Protection Authority)