- This topic has 10 replies, 6 voices, and was last updated 7 years, 6 months ago by
Tom.
-
AuthorPosts
-
January 5, 2018 at 4:58 am #463674
Edin
I’ve used the search, but there are different answers on this. Just to be sure, is that how you add the two different parts of the Google Tag Manager code:
1. The code that goes as high in the <head> of the page goes here:
“wp_head” in the GP Hooks
2. The code that goes immediately after the opening <body> tag goes here:
“Before Header” in the GP Hooks
Thanks,
EddieJanuary 5, 2018 at 8:28 am #463887Leo
StaffCustomer SupportHi there,
Both correct 🙂
April 2, 2018 at 12:05 pm #538943David
Hi
I got three question about this too:
1) When using the hooks as described above, do I guess correctly that I will not need a WP plugin such as this one anymore, because the 2 hooks will take care of the correct implementation of the 2 GTM codes? I am actually also using the Google Analytics Dashboard for WP (GADWP) plugin which also offers me to connect to connect with GTM, but I don’t know if this is automatically taking care of implementing both tracking scripts that are necessary for GTM.
2) The GTM code that needs to go “immediately after the opening <body> tag”: In my “Before Header” hook I see already some code:
Is it OK to add the GTM code after that, or do I have to add it before that other ‘full container’ code, since it talks about “immediately”?3) I have another code (Mixpanel) that I need to add in connection with GTM. It says: “Paste this snippet just before the </head> tag of your page”. Do I assume correctly that I need to add that under the “After Header Content” hook then? Or is “before the </head> tag” another hook?
Your answer will be much appreciated.
Kind regards
DavidApril 2, 2018 at 12:26 pm #538967Satori
Hi Edin and David! I had this issue before, but since GP 2.0 Tom created a little snippet that you can add via your functions.php file or via a plugin like Code Snippets.
add_action( 'generate_before_header', 'tu_add_google_tag_manager', 0 ); function tu_add_google_tag_manager() { ?> Here goes the GTM code <?php }
And there you go, your GTM is ready to work!
April 2, 2018 at 12:32 pm #538972David
Hi Roverd
Thank you for your answer.
Do I assume correctly that I can/should change the “tu” prefix to something of my own? I remember reading today this quick knowledge base entry where Tom says he’s using “tu” based on his initials:
https://docs.generatepress.com/article/using-hooks/Logically, this will not make any difference, but I just wanted to ask it, to avoid that the code breaks if indeed I adjust that from “tu” to something of my own.
Thanks
DavidApril 2, 2018 at 12:33 pm #538976David
PS: Do you happen to have an answer for my question #3 as well?
April 2, 2018 at 2:30 pm #539045Dan
Hi David,
Code that you need to show inside the <head></head> tag of your site will go into the “wp_head” hook of GPP.
As a reference you can take a look at GP hook locations here:
http://demo.generatepress.com/hook-locations/ (The wp_head hook is not mentioned in this link)
The “wp_head” hook, like the “wp_footer” hook are intended for adding JS, tracking codes, etc…
The other hooks can be used to actually display content on your site.Hope this helps,
DanApril 2, 2018 at 8:32 pm #539274David
Thank you, Dan! I must have been tired yesterday evening to not understand that ‘before the </head>’ means inside the <head>’… duh… 🙂
April 2, 2018 at 8:45 pm #539277Tom
Lead DeveloperLead DeveloperDavid – you can absolutely change the function prefix, but you have to change it in both places (add_action() and the function).
I use
tu_
as they’re my initials 🙂April 3, 2018 at 11:57 am #540105David
Thank you, “TU” 🙂
April 3, 2018 at 3:41 pm #540320Tom
Lead DeveloperLead DeveloperNo problem! 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.