soee/googletagmanager

Easily integrates Google Tag Manager code with your Neos website.

1.0.0 2018-05-26 08:23 UTC

This package is auto-updated.

Last update: 2022-06-09 20:06:39 UTC


README

Easily integrates Google Tag Manager installation code with your Neos website.

Installation

Add manually soee-googletagmanager package to your composer.json file to type in command line:

composer require soee/googletagmanager

Configuration

By default Google Tag Manager codes are rendered only if you have identifier set through configuration:

Soee:
  GoogleTagManager:
    identifier: 'MY-GOOGLETAGMANAGER-IDENTIFIER'

Customizations

The whole process and integration code is highly customizable. This package defines 2 new nodetypes:

Soee.GoogleTagManager:Code - used to render Google Tag Manager code inside head section Soee.GoogleTagManager:NoscriptCode - used to render noscript Google Tag Manager code after body opening tag

Both Code and NoscriptCode inherit from Neos.Fusion:Tag so you can check current code and customize it as you will.

Important:

You probably do not want to render Google Tag Manager codes inside development or testing environment. This package will help you with that but to do so we are checking Flow context name like this:

@if.inProductionEnvironment = ${Configuration.setting('Neos.Flow.core.context') == 'Production' ? true:false}

While this should work just fine in most cases it is still recommended to use your own variable that defines current environment. For example if your site package name is Vendor.Site than you could create 2 Settings.yaml files: one would be Configuration\Production\Settings.yaml and second Configuration\Development\Settings.yaml (similar for any extra environment). Than inside this 2 files you can configure environment configuration option:

for Production it could be:

Vendor:
  Site:
    environment: 'Production'

for Development it could be:

Vendor:
  Site:
    environment: 'Development'

Than you can use it to decide if Google Tag Manager code should be rendered like this:

Neos.Neos:Page {
  ...
  googleTagManagerCode {
    @if.inProductionEnvironment = ${Configuration.setting('Vendor.Site.environment') == 'Production' ? true:false}
  }
  ...
  googleTagManagerNoscriptCode {
    @if.inProductionEnvironment = ${Configuration.setting('Vendor.Site.environment') == 'Production' ? true:false}
  }
  ...
}

Author - Marcin Sągol

License

This package is released under MIT license