BoxLang 🚀 A New JVM Dynamic Language Learn More...

PresideCMS Extension: Google Tag Manager

v1.2.0+0000061 Preside Extensions

Google Tag Manager for Preside

This extension is for installing the installation scripts and configuration for adding Google Tag Manager (GTM) to the HEAD and BODY sections of the required layout templates as per the instructions in GTM.

Installation

From a commandline at the root of your application:

box install preside-ext-google-tag-manager

Configuration

Once installed, login to the Preside admin and head to System -> Settings -> Google Tag Manager and enter the snippets from the instructions section in Google Tag Manager Admin -> Container -> install Google Tag Manager .

For Google Consent Mode v2 and other configuration parameters, you can also add your required signals for Google, see the example below:

<invalidTag>
    window.dataLayer = window.dataLayer || [];
    function gtag() {
        dataLayer.push(arguments);
    }
    gtag("consent", "default", {
          ad_personalization: "denied"
        , ad_storage: "denied"
        , ad_user_data: "denied"
        , analytics_storage: "denied"
        , wait_for_update: 1000
    });
    gtag("set", "url_passthrough", true);
</script>

<!-- Google Tag Manager Script after -->

Usage

The extension will take care of inserting the Google Tag manager "snippets" into your layout automatically for you, you won't need to do anything else. However, you can customize the layouts that are affected.

To customize the layouts, set the settings.googleTagManager.layouts variable in your Config.cfc:

settings.googleTagManager.layouts = [ "main", "newsletter" ]; // The default is [ "main" ]

New helper methods

There are two new helper methods that can be used for pushing and exposing application data to the DataLayer

  • publishDataForAnalytics - used to push data into the DataLayer
  • getPublishedDataForAnalytics - used by the extension to construct the DataLayer output ** The outputting of the DataLayer JSON object is taken care of you automatically by the extension, if anything is set in the DataLayer using the publishDataForAnalytics method

Note

If you're using the Google Analytics extension or any other method of installing your tracking scripts, please ensure they are removed OR the configuration for the tracking ID is removed in the Admin to help prevent double tags/events being fired.

Contributing and roadmap

Pull requests, issues and ideas are all welcome :) Please get in touch with the Preside team on our Preside Slack.

Changelog

v1.2.0

  • Refactoring: Refactoring to use the new postRenderDelayedViewlets interception point due to the postLayoutRender to accomodate for delayedViewlets and caching too

v1.1.17

  • Bug Fix: Updating the form definition input type attribute to be control and not type

v1.1.16

  • Adding dataLayer output even if the scripts are not loaded via this extension and possibly via another method built into the site ** This could be within the project code directly or via another extension e.g. Civic Cookie Control

v1.1.14 & v1.1.15

  • Refactoring to ensure the dataLayer is always in front of the GTM script + updating the CHANEGLOG file

v1.1.13

  • Bug Fix: Wrong view path set for the dataLayer data template

v1.1.12

  • Updating the interceptor to retrieve and output the DataLayer data, if any exists

v1.1.11

  • Add helper functions publishDataForAnalytics() and getPublishedDataForAnalytics()

v1.1.10

  • Output head tags directly after element

v1.1.9

  • Remove asset building from build script

v1.1.8

  • Migrate build to GitHub Actions

v1.1.7

  • Increasing the text limit on both form fields to allow for bigger scripts

v1.1.6

  • Allow for the possibility of one or more comment tags inside the opening <body> tag

v1.1.5

  • Removing local asset preprocessing, not required

v1.1.4

  • Completing move to GitHub, including ensuring the build script is executable and the ChangeLog is recognised by ForgeBox

v1.1.3

  • Relocating repo to Pixl8 GitHub account

v1.1.2

  • Publishing to Forgebox, opensource

v1.1.1

  • Bug fix - missing commas

v1.1.0

  • Original build - completed

v1.0.0

  • Original build

$ box install preside-ext-google-tag-manager

   
  • {{ getFullDate("2019-09-25T04:33:25Z") }}
  • {{ getFullDate("2024-03-01T16:43:51Z") }}
  • 3,440
  • 71,203