heimrichhannot / contao-google-tag-manager-bundle
This bundle offers google tag manager for the Contao CMS.
Installs: 196
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 8
Forks: 0
Open Issues: 1
Type:contao-bundle
Requires
- php: ^7.1 || ^8.0
- contao/core-bundle: ^4.4
- heimrichhannot/contao-utils-bundle: ^2.0
Requires (Dev)
- contao/manager-plugin: ^2.0
- contao/test-case: ^1.1
- friendsofphp/php-cs-fixer: ^2.2
- php-coveralls/php-coveralls: ^2.0
- php-http/guzzle6-adapter: ^1.1
- php-http/message-factory: ^1.0.2
- phpunit/phpunit: >=6.0 <6.5
- symfony/phpunit-bridge: ^3.2
README
Implementation
To implement Google Tag Manager on your website
-
Set your google tag manager container id under the contao backend settings.
-
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 ?>
-
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>