Skip to content

shineunited/tagmanager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shine United - Tag Manager

A basic PHP abstraction for Google Tag Manager container and datalayer.

Latest Stable Version Minimum PHP Version Build Status

Installation

The recommended way to install Tag Manager is through Composer.

Install Composer

$ curl -sS https://getcomposer.org/installer | php

Add package to composer.json

$ composer require shineunited/tagmanager

Update dependencies

$ composer.phar update

Include autoloader

include(__DIR__ . '/../vendor/autoload.php');

Usage

Silex

To use Tag Manager with Silex, register the service provider

use ShineUnited\TagManager\Silex\TagManagerServiceProvider();

$app->register(new TagManagerServiceProvider(), [
	'gtm.options' => [
		'id'      => 'GTM-XXXX', //gtm container id (required)
		'persist' => true,       //persist datalayer in session if true (optional, defaults to false)
		'varname' => 'gtm'       //session varname (optional, defaults to 'gtm')
	]
]);

Adding messages to the datalayer

$app['gtm.datalayer']->push([
	'event'     => 'gtm.eventName',
	'eventData' => [
		// event data goes here
	]
]);

Twig

The extension adds the 'gtm()' function to the Twig environment. Note: the silex service provider will automatically install the twig extension if twig is present.

<html>
<body>
	...
	{{ gtm() }}
</body>
</html>

Or load the javascript and no-script snippets separately.

<html>
<head>
	...
	{{ gtm('head') }}
</head>
<body>
	{{ gtm('body') }}
	...
</body>
</html>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published