Skip Navigation

[Resolved] GTM code not in all pages (not in toolset custom pages)

This thread is resolved. Here is a description of the problem and solution.

Problem:

Add Google Tag Manager code in everypage of my site

Solution:

It needs custom codes, see details here:

https://toolset.com/forums/topic/gtm-code-not-in-all-pages-not-in-toolset-custom-pages/#post-1135916

Relevant Documentation:

This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 8 replies, has 2 voices.

Last updated by Miranda 5 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#1132921

I am trying to: add Google Tag Manager code in everypage of my site.
I uploaded the code in header.php and it work on some worpdress pages, but not the pages that use toolset view/layout/types

Link to a page where the issue can be seen: bestcase.com/community does not have the GTM code. bestcase.com does have it.

thank you

#1133235

Hi,

Please describe detail steps to duplicate the same problem:
How do you setup the Google Tag Manager code in header.php?
How do you setup those pages that use toolset view/layout/types?

I need to test and debug it in my localhost. thanks

#1133548

Hi,

navigate to bestcase.com, check in the code or via "Google Tag Assistant" that the GTM code is present.
Navigate to bestcase.com/community, repeat the step and see that code is not present.
Navigate to bestcase.com/cac and see that code is also note present.

I have added bot GTM code in header.php I made a copy of the header.php from the DIVI theme, and paste it in my divi-child theme folder.

I have no idea how to setup the pages using toolset plugin, I did not build the website. I see that some pages are using layout, and it looks like layout contains 'bricks' of other page like: breadcumbs, menu, footer, etc.

I don't see any space for pasting head and body code

thanks for your help

REgards

#1134044

I have tried the URL you mentioned above:
hidden link
I can see only below message:

This site has been blocked by the network administrator.
Block reason: Gateway GEO-IP Filter Alert

As I mentioned above, please provide detail steps to duplicate the same problem, what is the GTM code you have added into header.php?

I need to test and debug it in my localhost. thanks

#1134315

Are you guys in Russia? Can you use a proxy from another country to access our website?

Code I put in header.php (in my divi child theme):

<!-- 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=
'hidden link);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
<!-- End Google Tag Manager -->

<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="hidden link"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

The code is present on most pages. but not on the ones created/using toolset views/layouts.
Are you stripping the code or something?

#1134811

No, I am in China, I don't have other proxy of other country,

In your case, it depends on your theme files, and since it is a custom codes problem, in order to debug this problem, please provide a copy of your website, I need to duplicate and debug the same problem in my localhost:
https://toolset.com/faq/provide-supporters-copy-site/

You can put the duplicator package in google drive disk, and share the downloadable links.

#1135032

Can you ask another of your team member not in russia or china, to look at this ticket please?

It will be much easier.

Serhii Salii answered the same problem in this ticket, I need more information starting from there:
https://toolset.com/forums/topic/adding-google-tag-manager-js-code-to-the-head-of-every-page-that-uses-a-layout/

Thank you for your understanding.

#1135916

I have been able to get a proxy account from USA, and for the custom codes mentioned in the thread:
https://toolset.com/forums/topic/adding-google-tag-manager-js-code-to-the-head-of-every-page-that-uses-a-layout/#post-443737

I have tested those codes in my localhost, there is a typo in it, you can put them into your theme file "functions.php", and test again:

// define the wp_print_scripts callback
function action_wp_print_scripts() {
    echo "<!-- 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=
'<em><u>hidden link</u></em>);
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
<!-- End Google Tag Manager -->";
};
  
// add the action
add_action( 'wp_print_scripts', 'action_wp_print_scripts', 10);

function filter_wp_add_after_body($content){
    return '<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="<em><u>hidden link</u></em>"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->' . $content;
}
 
add_filter('get_layout_content_for_render', 'filter_wp_add_after_body');

Please replace GTM-XXXXXX with your GTM key/ID.

#1136093

Thanks, I did see the "" typo, and it seems to work. I ended up using a plugin in the meantime.

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.