PHP code example of xynnn / google-tag-manager-bundle

1. Go to this page and download the library: Download xynnn/google-tag-manager-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xynnn / google-tag-manager-bundle example snippets



// app/AppKernel.php

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

            new Xynnn\GoogleTagManagerBundle\GoogleTagManagerBundle(),
        );

        // ...
    }

    // ...
}

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

/** @var GoogleTagManagerInterface $manager */
$manager = $this->get('google_tag_manager');
$manager->addPush(['test' => 123);
html
<body>
{{ google_tag_manager_body() }}
...
</body>
html
{{ google_tag_manager_body_end() }}
</body>
yaml
google_tag_manager:
    additionalParameters: gtm_auth=XXXXXXXXXXXXX&gtm_preview=env-30&gtm_cookies_win=x