Site logo

Archived topic

Google Tag Manager related isshu

22 replies · Started by Ajay on March 19, 2020

Viewing posts 1–15 of 23

hey, I'm unable to see a Google Tag Manager head code on my site. the body tag is visible but the head tag isn't watchable. head tag applied hook is wp_head and the proxy is 10 with all pages. how can I see my code?

Hi there,

i can see the HTML comments for the Tag in the WP_head ie.

<!-- Google Tag Manager -->
<!-- End Google Tag Manager -->

If the comments are part of your code it says the hook is working.

The missing script says that maybe the code has an error in there.

Can you copy and paste the exact code you have here. Make sure you highlight the code and click the Code button before submitting.

sorry but I didn't get it what do you wanna say but I did copy and past again in and the issue is not sorted out until now. please help?

Copy the code you have in your site. And paste it here in this forum.

look:

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

why I cannot put code via hook? also, I'm using autopimize plugin that might be causing the problem? any solution add code without using any plugin?

The Hook Element writes the code to the Database.
Some Hosts will not allow <script> tags to be written to the database. You can check this with your Host.

The functions method i provided does not require plugins.

so i can simply put the code into the head and body section? in theme editor? but if someday the theme update would come in the future then my code will be there whether yes or not? please guide me step by step how to do that?

what should I do I'm so confused?

This is the code - simply add your scripts in place of <!-- Add your code --> :

<?php
add_action( 'wp_head','gtm_part_1' );  
function gtm_part_1() { ?> 
    <!-- Google Tag Manager -->

        <!-- Add your code -->

    <!-- End Google Tag Manager -->
<?php }

add_action( 'wp_body_open','gtm_part_2',0 );  
function gtm_part_2() { ?> 
    <!-- Google Tag Manager (noscript) -->

        <!-- Add your code -->

    <!-- End Google Tag Manager (noscript) -->
<?php }

Then you have two choices to add these codes:

1. Install the Code Snippets plugin:
https://en-gb.wordpress.org/plugins/code-snippets/

2. Install a Child Theme.
Link to child theme here:
http://generatepress.com/api/themes/generatepress_child.zip

Then edit the Child Theme Functions.php and add the codes

I got the reason why it was happening. As my investigation, the autoptimize plugin was causing the problem. otherwise, I could be able to see my code. I think code is working properly but autoptimize has been hidden the code. isn't it right? there is no need to do anything. what is your thought about it?

If you can disable Autoptimize i can take a look.

ok now I do let's check that

Yep - i can see GTM Script in the <head>.
What are the JS settings you have used in Autoptimize ? Can you share a screenshot ?

This archived topic is closed to new replies.