Site logo

[Resolved] Google Global Site Tag (gtag.js)

Home Forums Support [Resolved] Google Global Site Tag (gtag.js)

Home Forums Support Google Global Site Tag (gtag.js)

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1981338
    Mario

    Hi there,
    I tried to insert the Google Global Site Tag (gtag.js) from my Goggle Analytics admin panel into the header section of my website using a hook as per the advice in the documentation (I set the hook position to wp_head and to Entire Site). However, when I look at the HTML code of the website, I can see that it’s actually located in the body section (after <body>) and the code itself has also changed from what I copied and pasted into the hook text box.
    How do I resolve this?

    #1981372
    Leo
    Staff
    Customer Support

    Hi there,

    However, when I look at the HTML code of the website, I can see that it’s actually located in the body section (after <body>)

    That’s not really possible as the wp_head hook is located here:
    https://github.com/tomusborne/generatepress/blob/master/header.php#L17

    Can you disable all plugins except GP premium to test first?

    #1981400
    Mario

    Hi Leo,
    I can’t disable all other plugins – it is a live site. The code in line 313:
    }</style></head><body class="home page-template-default page page-id-10914 wp-custom-logo wp-embed-responsive post-image-aligned-center slideout-enabled slideout-mobile sticky-menu-no-transition sticky-enabled both-sticky-menu mobile-header mobile-header-logo mobile-header-sticky no-sidebar nav-below-header separate-containers nav-search-enabled header-aligned-left dropdown-hover full-width-content elementor-default elementor-kit-7434" itemtype="https://schema.org/WebPage" itemscope> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXX"></script> <script>window.dataLayer = window.dataLayer || [];
    You can see it is in line after the </head>.

    #1981408
    Leo
    Staff
    Customer Support

    Can you start a staging site so we can go through some debugging tests?

    Make sure you are actually using the wp_head hook:
    https://github.com/tomusborne/generatepress/blob/master/header.php#L17

    and not the wp_body_open hook which is right after the opening of the <body>:
    https://github.com/tomusborne/generatepress/blob/master/header.php#L27

    #1982970
    Mario

    Hi Leo,
    Thanks for the help.
    I have made the research on my development site and found that the problem was with a plugin: Asset CleanUp Pro – Move All <SCRIPT> tags From HEAD to BODY – I have disabled.
    The analytics code is bak in the head section.

    #1983227
    Leo
    Staff
    Customer Support

    No problem 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.