- This topic has 8 replies, 3 voices, and was last updated 7 years, 5 months ago by
Tom.
-
AuthorPosts
-
December 3, 2014 at 8:16 am #51019
Randolph Philp
Good morning,
Yesterday I tried for several hours to use a plugin, but I don’t think I did it correctly. I installed and activated the following:
DuracellTomi’s Google Tag Manager for WordPress
In his installation instruction, the plugin developer wrote the following of code:
<?php if ( function_exists( ‘gtm4wp_the_gtm_tag’ ) ) { gtm4wp_the_gtm_tag(); } ?>
after the body tag in order to keep Google Tag Manager from showing at the footer. I did so, but it did not seem to work.
I checked my Google Analytics Account and says that tracking is not installed. Here is a copy of how I added the snippet to the header template:
<body itemtype=”http://schema.org/WebPage” itemscope=”itemscope” <?php body_class(); ?>>
<?php if ( function_exists( ‘gtm4wp_the_gtm_tag’ ) ) { gtm4wp_the_gtm_tag(); } ?>
<?php do_action( ‘generate_before_header’ ); ?>
<header itemtype=”http://schema.org/WPHeader” itemscope=”itemscope” id=”masthead” role=”banner” <?php generate_header_class(); ?>>Did I do this correctly? Was that the correct body tag? I am rather new at using html and css. Could you please be detailed in your response?
Thank you very much!
Randy
December 3, 2014 at 10:07 am #51053Tom
Lead DeveloperLead DeveloperHi Randy,
First – I wouldn’t edit any of the core files as those edits will be removed if you decide to update to a newer version.
This would be much easier if you happen to have GP Hooks, as it would allow you to hook this code into your website without touching any core files.
As for the functionality of the code – I’m afraid I’m not much help as I’ve never used it. You’ll have to ask the developer why it’s not working for you.
Let me know π
December 3, 2014 at 10:53 am #51069Randolph Philp
Thank you for the prompt response Tom. I left a question in the plugin developer’s forum. It makes sense to use the hooks. Thank you for pointing that out.
Which hook should I use if the plugin developer wrote that his code should be placed after the body tag?
I also called Google Analytics. They said it can take 24 to 48 hours for Google Analytics to be able to see the tracking code on my website. Maybe the plugin works, but I just have to wait and see…
Thanks again,
Randy πDecember 3, 2014 at 12:31 pm #51090Tom
Lead DeveloperLead DeveloperIt depends.. Usually Google Analytics code is placed in the “wp_head” hook.
However, I’m not sure what this plugin is doing exactly, so it’s hard to tell.
It will be in wp_head or wp_footer.
Also, be sure to check “Execute PHP” in the hook in order for the PHP to be read.
December 3, 2014 at 12:32 pm #51092Randolph Philp
Excellent! I will give it a shot. Thanks again Tom!
December 4, 2014 at 6:34 am #51210Randolph Philp
Hi Tom,
Thanks again for the great advise! I didn’t even need the plugin I referred to earlier!!!
I deleted the plugin and pasted the google tag manager code into the footer hook. It worked like a charm. Also, my google analytics is now tracking (as directed by the tag manager)
I just had to wait about 24 hours for google analytics to “find” my code and now I can see my stats.
I hope this helps someone else! Awesome theme!
Randy
December 4, 2014 at 9:32 am #51221Tom
Lead DeveloperLead DeveloperHappy I could help π
March 30, 2016 at 9:52 pm #183052Ryan
I actually think it’s best to put the GTM code in the “Before Header” section so that the browser reads it immediately after the body tag.
March 30, 2016 at 11:23 pm #183070Tom
Lead DeveloperLead DeveloperGood point! Just looked it up and that’s where it should go π
-
AuthorPosts
- You must be logged in to reply to this topic.