Support » Plugin: Google Tag Manager » Doesn't work

  • Would give it 0/5 as the app does not behave as it should. Puts the code snippet in the wrong place and Google can’t use it.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author George Stephanis

    (@georgestephanis)

    Code Monkey

    Why do you say that Google can’t use it? JS can run just as easily at the top of the body as at the footer, however WordPress doesn’t by default have a way to output at the top of the body, it would be heavily dependent on theme support, which has not congealed around any specific method.

    @georgestephanis The JS will run, but when you use Google Tag Manager to load things like Google Analytics (which needs to be loaded right after the opening body tag), it simply doesn’t work.

    I get that WordPress doesn’t have a hook right after the body tag, but there is a wp_head hook where you can place the portion of the GTM script that needs to be in the document head. Perhaps that small change would make things like loading Google Analytics work?

    • This reply was modified 1 year, 8 months ago by  Micah Wood.
    Plugin Author George Stephanis

    (@georgestephanis)

    Code Monkey

    The downside there is that the GTM script is all or nothing. Any GTM bits that directly write stuff to the page would then do it in the head instead of the body and other things might break.

    I have been thinking about how to address this, and I’m thinking I may implement some of what @zamoose has done with Theme Hooks Alliance, and only print in the footer as a last resort. Which means users with these concerns can pop a one-line do_action() call right after their <body> tag.

    @georgestephanis I’m not sure what the recommended GTM implementation was when you created the plugin, but the current instructions from Google are to implement the part of the script with the immediately invoked function expression as high in the document head as possible (so an early wp_head hook) and the part with the noscript tag just after the opening body tag. What I’m suggesting is that you just leave the noscript tag in the footer and bump the other portion to the head to see if that fixes implementations such as when trying to dynamically inject the Google Analytics tag.

    It may not resolve all the issues, but would definitely get you closer to a correct implementation.

    However, I do like the idea of checking for a theme hook alliance implementation and changing up the hooks for the noscript portion so that it can actually load right after the opening body tag.

    We should probably open a ticket for adding a hook in WordPress after the opening body tag (I haven’t checked to see if one already exists).

    • This reply was modified 1 year, 8 months ago by  Micah Wood.

    @georgestephanis Looks like this has been around a while, but the more backing we can get the better: https://core.trac.wordpress.org/ticket/12563#comment:37

    Plugin Author George Stephanis

    (@georgestephanis)

    Code Monkey

    Okay, they did split up the JS. I had the initial version up in the repo about four years back when they first released.

    Fixed both that, and added early print of the iframe version when possible via Theme Hook Alliance or Genesis theme hooks here:

    https://plugins.trac.wordpress.org/changeset/1583687/google-tag-manager/trunk/

    Can you give the v1.0.2-beta1 a spin and let me know how that works for you?

    https://downloads.wordpress.org/plugin/google-tag-manager.1.0.2-beta1.zip

    @georgestephanis

    Works splendidly! I tested it by dynamically injecting Google Analytics and it works as it should. I also verified that it works properly in the presence of the additional hooks. I also like that you’ve added the escaping functions.

    I think you’re ready for prime time!

    Plugin Author George Stephanis

    (@georgestephanis)

    Code Monkey

    Solid! Shipping it now.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Doesn't work’ is closed to new replies.