Community Forums › Forums › Archived Forums › General Discussion › Google Tag Manager
Tagged: google tag manager
- This topic has 6 replies, 2 voices, and was last updated 7 years, 10 months ago by jeffbogaczyk.
-
AuthorPosts
-
February 13, 2017 at 11:14 am #201049jeffbogaczykParticipant
I'm trying to add Google Tag Manager to my Lifestyle Pro Genesis Child theme. There are two parts to this. Part one is:
Paste this code as high in the <head> of the page as possible:
<!-- 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 -->I can place this no problem in multiple ways - editing Genesis header.php and placing the code there, or by putting it in the box in the Genesis Theme settings, or even with simple hooks. I'm wondering what is the best method and second where do I put the second part of the code.
Additionally, paste this code immediately after the opening <body> tag:
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-W6VGNHX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->I have tried many ways to get this in there but none have been successful and I'm still getting an error that no matter what way I try to get it in there (code added to function.php, similar attempts in simple hooks) , it is outside the <body> tag. Any help would be greatly appreciated.
http://www.mindforlife.org/February 13, 2017 at 12:31 pm #201055Victor FontModeratorThe genesis_before hook executes immediately after the body tag. You can use the Genesis Simple Hooks plugin or create a function to add your code:
add_action( 'genesis_before', 'my_google_tag_manager_code'); function my_google_tag_manager_code() { echo "<!-- Google Tag Manager (noscript) -->"; echo '<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-W6VGNHX" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>'; echo "<!-- End Google Tag Manager (noscript) -->"; }
I tested this in my local environment using the Genesis Sample theme.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?February 13, 2017 at 2:05 pm #201071jeffbogaczykParticipantVictor,
I tried posting the code into the genesis_before hook but am getting the error that the code is outside of the <body> tag. I also pasted your code into the functions.php file and still no luck. I'm not sure what I'm doing wrong on this.
February 13, 2017 at 3:27 pm #201081Victor FontModeratorThat code works fine in functions.php. I tested it. I just looked at your site source code and you are inserting it twice directly after the body tag and once in the site header. My code dosen't touch the site header. The error is coming from something you did prior to adding my code.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?February 13, 2017 at 8:59 pm #201105jeffbogaczykParticipantVictor,
I must be doing something wrong. I'm sorry I'm not a coder and I can't figure it out. I put your code in the functions.php of the child theme, but when I put the other Google tag code in after the <head> tag, I get an error with Google tag assistant saying the code is found outside the <body> tag. The Google Tag Manager says that there's supposed to be two sections of code so I'm not sure how to get it to work. When you tested it with the Genesis sample, were you running the Google Tag assistant to verify the tag manager was working on the site and everything was good?
February 14, 2017 at 10:13 am #201142Victor FontModeratorNo. I wasn't using Google tag assistant. I simply tested it to make sure the code appeared where you asked. If you're having trouble getting it to work, I suggest hiring someone to help you. I gave you want you asked for, beyond that, helping will require access to the backend of your site and testing that goes beyond what I can do as a community volunteer.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?February 14, 2017 at 11:40 am #201148jeffbogaczykParticipantSure. Thanks for all your help.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.