WordPress.org

Ready to get started?Download WordPress

Forums

Google Tag Manager and Webmaster Tools
[resolved] Container snippet NOT immediately after (5 posts)

  1. ahess1
    Member
    Posted 1 year ago #

    Google's instructions say:

    Copy the following code then paste it onto every page of your website. Place it immediately after the opening <body> tag.

    But this plug-in has the container snippet after the footer. Is that on purpose? Is that OK?

    http://wordpress.org/extend/plugins/google-webmaster-tools-manager/

  2. lauraeus
    Member
    Plugin Author

    Posted 1 year ago #

    Thank you for that note!
    Due to the lack of hooks in wp core we had to choose between placing the tag manager snippet in "html head" or at the bottom of the page. The corresponding hooks are "wp-head" and "footer" respectivly.

    For the non-programming geeks, this meens absolutely nothing.

    In order to meet the Google recommendation as closely as possible, this plugin activates the Google Tag Manager snippet in the head, but awaits the "body" document object to become available and thereafter attaches itself to this element. Just as Google prescribes.

    Hope this helps and clears the issue a little bit?

    Cheers!

  3. ltaloi
    Member
    Posted 1 year ago #

    Hi, I just watched a webinar about GTM. The reason we should put the GTM snippet just after the <body> tag is to ensure that GTM works on browsers w/o Javascript activated. So.. for all browsers that are JS enabled there is no need to put it after the <body>, it should work as well as inside the <head> section.

    I'm telling you that because I saw (i just installed your plugin, thx) that the code you wrote has no "<noscript>" section. So.. you put the GTM just after the <body> but you ripped off the <noscript> section which is the very reason to move that code in that position.

    May you try to attach to the GTM the <noscript> section?? Thx.

  4. ltaloi
    Member
    Posted 1 year ago #

    In fact, using JS to move the code after the <body> means that on JS non-enabled browsers will not work. The iframe tag cannot be executed inside the <head> on a nonJS browser. That's why we need to put the GTM (script + noscript) just after the <body>.

  5. lauraeus
    Member
    Plugin Author

    Posted 1 year ago #

    The <noscript> will always be added to the footer as you aldready may have noticed.

    The other issue regarding loading of GTM snippet in HEAD section of a page is another matter. By doing so you would get into a lot of timing problems with especially Internet Explorer. The GTM snippet tries to attach to the Body DOM object. If snippet is loaded in HEAD the BODY may not be yet available. This is a serious problem an will fail a lot of visitors.

    Cheers!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.