heimrichhannot/contao-google-tag-manager-bundle

This bundle offers google tag manager for the Contao CMS.

1.2.0 2022-10-11 09:03 UTC

This package is auto-updated.

Last update: 2023-01-11 09:28:32 UTC


README

Implementation

To implement Google Tag Manager on your website

  1. Set your google tag manager container id under the contao backend settings.

  2. Copy the following code snippet and paste it as close to the opening <head> tag as possible on every page of your website. <?= $this->googleTagManagerHead ?>

  3. Copy the following code snippet and paste it as close to the opening <body> tag as possible on every page of your website. <?= $this->googleTagManagerBody ?>

add data layer variables to a page

System::getContainer()->get('huh.google_tag_manager.data_layer')->setContent(['key' => 'value']);

add an a tag with data layer event handler

System::getContainer()->get('huh.google_tag_manager.tag_manager')->getLink(class, link, linkText, ['event': 'button1-click'])

This will output: <a href="link" class="class" onclick="dataLayer.push({'event': 'button1-click'});">linkText</a>