Google Tag Manager (GTM) Integration

If your site uses Google Tag Manager, Qookies.js is can send events and variables directly to GTM to use in triggers.

Using the GTM plugin for Qookies.js allows you to handle consents and include scripts directly from GTM. In order to configure the plugin, you'll have to provide Qookies.js the customized Data Layer name (if you use a non default value in GTM).

Configure the GTM Plugin

To configure the GTM Plugin, make sure that you have Qookies.js 1.2 or later installed, and provide the configuration via a script tag added before the Qookies.js include:

                <html>
    <head>
        <script>window['_q_config'] = {gtm: true};</script>
        <script src="https://cookies.fo/qookies/qookies.1.2.0.js"></script>

        <!-- rest of head (including the consent banner) -->
    </head>
    <!-- your body -->
</html>
    

If you've configured GTM to use a non-default name for the data-layer, pass it into the gtm field instead, e.g. {gtm: 'myCustomLayer'}.

Add Triggers and Variables to GTM

On the GTM side, we'll add a Data Layer Variable to track what consents are given, and add a trigger for each cookie category you use. To begin, log on to your GTM dashboard and open the workspace for the container you want to use.

Adding a Custom Variable

  1. Select the Variables item from the sidemenu.
  2. Under User-Defined Variables, click the New button.
  3. Click on the Variable Configuration block to choose a type.
  4. Select Data Layer Variable from the Page Variables section.
  5. Configure the variable as follows
    • Data Layer Variable Name: q-consent
    • Data Layer Version: Version 2
    • Set Default Value:
  6. Click Save and give your variable a descriptive name such as Qookies.js Consents

Adding Triggers for Page Loads

  1. Select the Triggers item from the sidemenu.
  2. On the Triggers panel, click New.
  3. Click on the Trigger Configuration block to choose a type.
  4. Select DOM Ready from the Page View section.
  5. On This trigger fires on select the Some DOM Ready Events option.
  6. Configure Fire this trigger when an Event occurs and all of these conditions are true as follows:
    • Qookies Consents contains statistics
    • If you chose another variable name in the previous section, replace Qookies Consents with your variable name
    • If you want to create a trigger for some other cookie category, replace statistics with the appropriate category from the identifier list below
  7. Click Save and give your trigger a descriptive name such as Statistics Cookies Enabled.

Adding Triggers for Events

  1. Select the Triggers item from the sidemenu.
  2. On the Triggers panel, click New.
  3. Click on the Trigger Configuration block to choose a type.
  4. Select Custom Event from the Other section.
  5. In the Event Name textbox input QookiesConsentUpdated.
  6. On This trigger fires on select the Some Custom Events option.
  7. Configure Fire this trigger when an Event occurs and all of these conditions are true as follows:
    • Qookies Consents contains statistics
    • If you chose another variable name in the previous section, replace Qookies Consents with your variable name
    • If you want to create a trigger for some other cookie category, replace statistics with the appropriate category from the identifier list below
  8. Click Save and give your trigger a descriptive name such as When Statistics Cookies Are Consented.

Configure a Tag that Requires Consent

  1. Create a tag configuration as you normally would OR click on a tag you want to apply triggers to.
  2. Click on the Triggering panel to choose triggers.
  3. Select the Tags item from the sidemenu.
  4. Select the Event and DOM Ready events you created for the appropriate cookie category.

Cookie Category Identifiers

The cookie category identifiers used by the GTM plugin are:

Configure a trigger for each category you use.