Skip to content

invit/GoogleTagManagerBundle

 
 

Repository files navigation

GoogleTagManagerBundle

Software License Build Status

The GoogleTagManagerBundle provides you an easy-to-use method to integrate the Google Tag Manager into your Symfony 2 application.

Note: This Bundle is still in development. Feel free to report encountered issues!

Requirements

  • PHP 5.3 and higher
  • Symfony 2.0 and higher

Install

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require xynnn/google-tag-manager-bundle "~1.0"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding the following line in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Xynnn\GoogleTagManagerBundle\GoogleTagManagerBundle(),
        );

        // ...
    }

    // ...
}

Step 3: Enable Google Tag Manager

Add the configuration to your yaml file. Please don't forget to adjust your Google Tag Manager Id.

Step 4: Insert the ViewHelper

Insert the ViewHelper into your layout file to enable the Google Tag Manager. Please be aware to insert into right after the HTML body tag!

<body>
{{ google_tag_manager() }}
...
</body>

Step 5: Fill up the DataLayer from Google Tag Manager (Optional)

If you want to send some information to the Google Tag Manager, you can use the dataLayer.

/** @var GoogleTagManager $manager */
$manager = $this->get('google_tag_manager');
$manager->addData('example', 'value');

Configuration

google_tag_manager:
    enabled: true
    id: "GTM-XXXXXX"
    autoAppend: true|false

Authors

Philipp Bräutigam

License

Copyright (c) 2015 Philipp Bräutigam This repository is released under the GNU LGPL v3.0 license.

Packages

No packages published

Languages

  • PHP 95.8%
  • HTML 4.2%