Functionality
The enableGoogleAnalytics
function enables analytic events to track user behavior with AdConsent.
Syntax
function adconsent()
argument name | type | optional | value | description |
---|---|---|---|---|
command | string |
| ||
parameter | boolean | ✔️ |
| Enables or disables Google Analytics. Defaults to |
callback | function | ✔️ |
| The callback receives the Google Analytics event data. Default detects ga or gtag objects and uses them automatically. |
EventData
EventData = { category: 'AdConsent', action: '', label: '', value: '', nonInteraction: true }COPY
EventData.action
The consent region of this event:
'NONE'
'GDPR'
'CCPA'
EventData.label
The AdConsent event type:
User interface events
'GuiShow'
- User interface is open. This does not include the USP notice link.'GuiSubmit'
- User submits it settings, the following consent event will show the users choice.
Consent events
'FullConsent'
- Vendors have full consent'PublisherFullConsent'
- Publisher has full consent'PartialConsent'
- Vendors have partial consent'PublisherPartialConsent'
- Publisher has partial consent'NoConsent'
- Vendors have no consent'PublisherNoConsent'
- Publisher has no consent
Others
'GooglePurposeOneMissing'
- Google does not have purpose 1 or vendor consent and will not deliver ads'Reconsider'
- The reconsider timeout triggered, see reconsiderConsent'Error...'
- Error events starting withError
and showing specific errors
EventData.value
The time in milliseconds since the page was loaded.
Description
The analytics functionality is used to observe and track users behavior with the AdConsent consent management.
It support Google Analytics analytics.js and gtag.js by default. If you choose to use Google Analytics with custom names or an entirely different analytic system, you can pass a custom callback to convert analytic events to the format of your choice. See the examples section for use cases.
Scope
The function must be called before AdConsent start
, i.e. in the stub. Calls after AdConsent is started will be ignored.
GDRP analytic event flow
User visits pageConsent given?Full consent?FullConsentPublisherFullConsent (optional)Partial consent?PartialConsentPublisherPartialConsent (optional)GooglePurposeOneMissing (optional)Reconsider?ReconsiderGuiShowGuiSubmitNoConsentPublisherNoConsent (optional)GooglePurposeOneMissingyesnoyesnoyesnoyes
CCPA analytic event flow
Note that GuiShow
can happen multiple times before a user decides to submit consent settings triggering GuiSubmit
. This means that GuiShow
in the CCPA region should not be used to measure the acceptance rate.
User visits pageConsent given?Full consent?FullConsentNoConsentGooglePurposeOneMissingFullConsentClick privacy linkGuiShowPage action?GuiSubmityesnoyesnoyesno
Insert new CCPA analytic flowchart
No privacy region analytic event flow
User visits pageFullConsent
Insert no GDPR region flowchart
Examples
Google Analytics with automatic API detection
Requires analytics.js or gtag.js to be loaded and either the tag ga
or gtag
must be defined.
adconsent('enableGoogleAnalytics');
Google Analytics with custom ga API name
adconsent('enableGoogleAnalytics', true, function(data) { gaCustomName('send', { hitType: 'event', eventCategory: event.category, eventAction: event.action, eventLabel: event.label, eventValue: event.value, nonInteraction: event.nonInteraction }); });
Google Analytics with custom gtag API name
adconsent('enableGoogleAnalytics', true, function(data) { gtagCustomName('event', event.action, { event_category: event.category, event_label: event.label, event_value: event.value }); });
Google Analytics with Google Tag Manager
This requires further configuration in GTM in order to provide the needed variables and linking to the correct Google Analytics account.
adconsent('enableGoogleAnalytics', true, function(data) { dataLayer.push({ publisherGAId: 'UA-XXXXX-X', event:'gaEvent', eventCategory:event.category, eventAction:event.action, eventLabel: event.label, eventValue: event.value, nonInteraction: event.nonInteraction }); });
Analytic events with custom event listener
adconsent('enableGoogleAnalytics', true, function(data) { console.log(`AdConsent analytic event: ${data.action}, label: ${data.label}, value: ${data.value}` });