Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Functionality

The enableGoogleAnalytics function enables analytic events to track user behavior with AdConsent.

Syntax

function adconsent()

argument name

type

optional

value

description

command

string

'enableGoogleAnalytics'

parameter

boolean

✔️

true | false

Enables or disables Google Analytics. Defaults to true

callback

function

✔️

function(data: EventData)

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
}

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 with Error 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

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.

No privacy region analytic event flow

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}`
});

  • No labels