Pro Theme - Google Tag Manager

I’m currently trying to install GTM on the site rbspencerinc.com. I’ve followed the suggested method on this thread, but it’s still not showing up. Any help would be appreciated. I’m using the Pro Theme.

1 Like

Hi there,

For the Pro theme you need to override the file below in your Child Theme:

wp-content/themes/pro/framework/views/header/base.php

So you need to add folders below in your child theme and add the base.php file there:

wp-content/themes/pro-child/framework/views/header/

After that you need to add the Tag Manager code to line 24:

<?php

// =============================================================================
// VIEWS/HEADER/BASE.PHP
// -----------------------------------------------------------------------------
// Declares the DOCTYPE for the site, includes the <head>, opens the <body>
// element as well as the .x-root <div> and .x-site <div>.
// =============================================================================

$x_root_atts = x_atts( apply_filters( 'x_root_atts', array( 'id' => 'x-root', 'class' => 'x-root' ) ) );
$x_site_atts = x_atts( apply_filters( 'x_site_atts', array( 'id' => 'x-site', 'class' => 'x-site site' ) ) );

?>

<!DOCTYPE html>

<html class="no-js" <?php language_attributes(); ?>>

<head>
  <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<!-- ADD THE TAG MANAGER CODE HERE -->
  <div <?php echo $x_root_atts; ?>>

    <?php do_action( 'x_before_site_begin' ); ?>

    <div <?php echo $x_site_atts; ?>>

    <?php do_action( 'x_after_site_begin' ); ?>

Thank you.

1 Like

This worked perfectly. Thank you!

You are most welcome. :slight_smile:

I tried this but I can’t seem to see the tag firing via tag assistant. can anyone help me? Thanks

Are you using the Pro theme or X theme? This is for Pro theme, I believe X is a little different. If you’re using X, see the link in my original post for those instructions.

Also, do you have a chaching plugin? Just make sure to clear cache after install.

@3rdcity:
Thanks for chiming in!
We really appreciate it.

@johnlaforteza:
Did you already figure it out? Please let us know how it goes.
If you need anything else we can help you with, don’t hesitate to open another thread.

Hello Christopher - I am new to Theme X Pro and need to add GTM. I started with these instructions but not sure if they are correct https://www.paulcarl.com/add-google-tag-manager-x-theme-wordpress-theme/

Next I am looking at this thread and am lost…

I am looking for specifics for Theme X Pro and Child them to at the Google Tag Manager Head an Body code.

Please help. Thanks! T.

Hi,

Please follow instructions provided on this thread.

ie. Create file base.php in wp-content/themes/pro-child/framework/views/header/ and copy the code below into that file.

<?php

// =============================================================================
// VIEWS/HEADER/BASE.PHP
// -----------------------------------------------------------------------------
// Declares the DOCTYPE for the site, includes the <head>, opens the <body>
// element as well as the .x-root <div> and .x-site <div>.
// =============================================================================

$x_root_atts = x_atts( apply_filters( 'x_root_atts', array( 'id' => 'x-root', 'class' => 'x-root' ) ) );
$x_site_atts = x_atts( apply_filters( 'x_site_atts', array( 'id' => 'x-site', 'class' => 'x-site site' ) ) );

?>

<!DOCTYPE html>

<html class="no-js" <?php language_attributes(); ?>>

<head>
  <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<!-- ADD THE TAG MANAGER CODE HERE -->
  <div <?php echo $x_root_atts; ?>>

    <?php do_action( 'x_before_site_begin' ); ?>

<div <?php echo $x_site_atts; ?>>

<?php do_action( 'x_after_site_begin' ); ?>

Add your goolge tag manager code after this line

<!-- ADD THE TAG MANAGER CODE HERE -->

Hope that helps.

Google Tag Manager has Two (2) pieces of Code Opening HEAD TAG and BODY TAG.

Do both pieces of Code go here?

Thanks Tim

Quick Start Guide
The Google Tag Manager container snippet is a small piece of JavaScript and non-JavaScript code that you paste into your pages. It enables Tag Manager to fire tags by inserting gtm.js into the page (or through the use of an iframe when JavaScript isn’t available).

To implement Google Tag Manager on your website:

Copy the following JavaScript and paste it as close to the opening tag as possible on every page of your website, replacing GTM-XXXX with your container ID:

Copy the following snippet and paste it immediately after the opening tag on every page of your website, replacing GTM-XXXX with your container ID:

Hi There @timreha

The code that you have to implement immediately after the opening tag, use the above method as @paul.r mentioned.

The other part, you can add into your child theme’s functions.php.

Example:

function my_tag_manager_code_head() { ?>

<!-- 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-xxxxxxx');</script>
<!-- End Google Tag Manager -->


<?php }

add_action( 'wp_head', 'my_tag_manager_code_head' );

Hope that helps.

Yes this worked. Thank you.

@timreha … Glad we were able to help :slight_smile:

Hi @mldarshana

Im confused here .

I’ve pasted the part on the newly created base.php file on my child theme as told initially.
Then I pasted the part on the child theme functions php.

TBut the Tag Manager code does not seem to be firing.

Have i done it correctly?

Hello Adrian,

Thanks for updating this thread. Can you please confirm that you do not have any caching plugin installed or Endurance Page Cache feature in your site. After making all the changes, you will have to clear all the caches first before testing your site again. To assist you with this issue, we’ll first need you to provide us with your URL. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.

Regards.

Hi,
I’m using Pro Theme and I was following all the instructions above.
First I created base.php file inside child theme/framework/views/header/ and there I copied the body part pf the tag.

Then I copied the header part of the tag inside functions.php of child theme.
I’ve cleared all the caches and I don’t see any gtm code when I inspect it.

One other thing that happens is that my main menu dissappears!

This is my site: https://www.mediana.com

Can you please advise me what to do.

Thank you,
Anita

There is something strange going on with the implementation of Tag Manager in the Pro theme.
Now I’ve done some trials and even copied this code inside the functions.php file and eliminated the base.php file:

Now I can see the Tag manager in my code but!: The site won’t go in debug mode when I activate it in Google Tag manager interface and the snippet in the browser sees only the tag code and it says I need to add Google Analytics but I’ve already added it inside Tag Manager workspace. > probably because the tag manager results not coded properly inside the site.

I’ve also reset the situation where I have one part of the Tag Manager inside base.php file and other inside functions.php of child theme. And my main menu first appears, and then, after some time passes it disappears, that by itself is strange.
Could it be some issue with my site menu settings? I can’t find the solution. I’m using ubermenu.

I’ve tried doing this with another site where I have another theme installed and everything went smoothly on the firs attempt.
Can you please analyse this issue?

Thank you.
Regards,
Anita

Hello Anita,

Thanks for writing in!

Although the topic is related, this is a fairly old ticket. Posting on ticket created by a different user creates lot of confusion which in turn slows down the response time.

I request you to please create a new ticket and share the details in the same. Someone from support team will take a look at assist you accordingly.

Thanks for understanding.