Skip to content

This class provides some simple PHP helper functions for implementing Google Tag Manager within your website.

License

Notifications You must be signed in to change notification settings

marcwitteveen/google-tag-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

google-tag-manager

This class provides some simple PHP helper functions for implementing Google Tag Manager within your website.

Getting Started

You can install this package using Composer by adding this line to your composer.json require statement.

"marcwitteveen/google-tag-manager": "dev-master"

And then run from terminal:

sudo composer update

Code Sample

use MarcWitteveen\Gtm\Gtm;

Gtm::renderHeadTag('GTM-XXXXXX');
/* This will render the following code:
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
<!-- End Google Tag Manager -->
*/

Gtm::renderBodyTag('GTM-XXXXXX');
/* This will render the following code:
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
*/

Methods:

  • Gtm::renderHeadTag($container_id = "")
  • Gtm::renderBodyTag($container_id = "")

renderHeadTag Method

Description

Renders a Google Tag Manager container that needs to be placed as high in the of the page as possible.

Parameters

  • $container_id (required): The id of your container. You can get this value from your Google Tag Manager account admin panel.

renderBodyTag Method

Description

Optional: Renders a Google Tag Manager container that needs to be placed immediately after the opening tag.

Parameters

  • $container_id (required): The id of your container. You can get this value from your Google Tag Manager account admin panel.

About

This class provides some simple PHP helper functions for implementing Google Tag Manager within your website.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages