How to add Google Tag Manager code to the Thesis 2.1 WordPress framework and theme

by

in

Tidy up your code and gather all your stats and conversions tags in one place. Manage tags for all your websites in one place.

  • Google Analytics
  • Google AdWords remarketing
  • Google Adwords conversion
  • Facebook ads tracking
  • Twitter ads tracking
  • Microsoft Bing Ad Center ads tracking
  • Linked In ads tracking
  • – and much more

Adding tags without efficient management would potentially cause trouble. All that code bogs down your site. Redundant or incorrectly applied tags can distort your measurement and result in duplicate costs or missing data. And it can be time-consuming for the IT department or webmaster team to add new tags, which means important marketing and measurement programs could suffer from delay. With Google Tag Manager, you eliminate these problems—and run your campaigns when you need them.

 

 

 

Google Tag Manager
http://www.Google.com/tagmanager/

WordPress plugin to add extra functionality to Tag Manager, Google Analytics, AdWords and more:
https://WordPress.org/plugins/duracelltomi-google-tag-manager/

Tips on how to use the plugin
http://DuracellTomi.com/

Thesis is the ultimate design and template manager for WordPress
http://DIYthemes.com

 

 

 

You need to add the PHP code below in the file named

custom.php

This PHP-file is available in the folder:

/wp-content/thesis/skins/YOUR-THEME-NAME/custom.php

I use a theme from  http://Themedy.com called Junction 2

The path to my custom.php is:

/wp-content/thesis/skins/junction-t2/custom.php

 

This is the PHP code to add to your custom.php file in Thesis:

 

 

 

// Google TagManager START
function injectTagManager() {
?>

<?php if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) { gtm4wp_the_gtm_tag(); } ?>


<?php
}

add_action('hook_before_html','injectTagManager');


function injectDataLayer() {
?>
<script>
var dataLayer = [];
</script>
<?php
}


add_action('wp_head','injectDataLayer');

// Google TagManager STOPP

 

 

 

If you don’t want to use the WordPress plugin, and instead place the full Google Tag Manager code, please use this code:

 

 

 

// Google TagManager START
function injectTagManager() {
?>

<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-XXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<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=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXX');</script>
<!-- End Google Tag Manager -->




<?php
}

add_action('hook_before_html','injectTagManager');


function injectDataLayer() {
?>
<script>
var dataLayer = [];
</script>
<?php
}



add_action('wp_head','injectDataLayer');


// Google TagManager STOPP