[Resolved] Google Tag Manager

Home Forums Support [Resolved] Google Tag Manager

Home Forums Support Google Tag Manager

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #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,
    Eddie

    GeneratePress 2.0.1
    #463887
    Leo
    Staff
    Customer Support

    Hi there,

    Both correct 🙂

    #538943
    David

    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
    David

    #538967
    Satori

    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!

    #538972
    David

    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
    David

    #538976
    David

    PS: Do you happen to have an answer for my question #3 as well?

    #539045
    Dan

    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,
    Dan

    #539274
    David

    Thank you, Dan! I must have been tired yesterday evening to not understand that ‘before the </head>’ means inside the <head>’… duh… 🙂

    #539277
    Tom
    Lead Developer
    Lead Developer

    David – 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 🙂

    #540105
    David

    Thank you, “TU” 🙂

    #540320
    Tom
    Lead Developer
    Lead Developer
Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.