Google Tag Manager

by mokusiga on 05/26/2013


Questions and Answers to the “Google Tag Manager – Mokusiga” plugin I’ve created for WordPress

How can I place the GTM code to immediately after the <body> tag?

  1. In your template’s header file, place something like <?php do_action(‘gtm_hook’); ?> to where you want the GTM code to load.
  2. In the settings, select ‘custom’ and fill in ‘gtm_hook’ (without quotes).
  3. Save the settings.
  4. The GTM code should now appear where is defined.

What is my Container ID?
Container IDThis is the ID used to identify your Google Tag Manager container. Assuming that you’ve already created a container within Google Tag Manager, you can find this by logging in to and selecting the container. And then in the left hand menu, select
Users & Settings\Settings. You will see a textfield like below. The GTM-XXXX value is your container ID.


Where do I set the GTM code? What is the location of the script?
You have two options

  1. Option ‘footer’: select ‘footer’ and the Google Tag Manager code will appear in the footer. This is the default for this plugin because most wordpress plugins support the wp_footer() hook.
  2. Option ‘custom’: select this option if you want to place the Google Tag Manager code elsewhere. You would need to add the hook manually to your theme. See how to add the script to after the <body> tag

What is the dataLayer name?
The datalayer variable is used to pass key/value variables into Google Tag Manager. The plugin allows you to change the datalayer name if it conflicts with your existing scripts. The default is ‘dataLayer’ and for more information, see renaming data layer.

How do I use the dataLayer?
Please see Using a Data Layer .

What is my dataLayer variable for logged in users?
Check this to enable a data layer variable to indicate if the current user is logged in or not. Using this, you can add custom variables (Google Analytics) or custom dimensions (Universal Analytics) to the tracking code.
The key of this variable is 'isLoggedIn' and the value would either be 'true' or 'false'.

What is my dataLayer variable for the Word Press version?
The version of WordPress will be sent to the dataLayer via the variable ‘wpVersion’.
dataLayer: [{ 'wpVersion':'<wordpress version>' }]

What are custom dataLayer variables I can add?
Add your own key/value pairs here. These will be inserted into the data layer variable directly as is.

No comments yet.

Write a comment: