Possibly script loading/placement issue

Created on 5 June 2024, 7 months ago

I am using the module, latest version 2.0.5, and have attached a GTM code. The script is loaded both in the header and in the body - with the tag.
Although I can see the script is loaded, when I attempt to run Google Search Console, I receive the following error: " Verification method:
Google Tag Manager
Failure reason:
The Google Tag Manager snippet on your site is in the wrong location on the page. Find out more".

Is there an issue with the way the JS script is loaded?
Before the upgrade, when I was using version 1.x, I was able to use Google Search Console without any issues. What could be causing this problem in the new version?
The GTM code implementation has not changed.
The problem started occurring immediately after upgrading to version 2.0.5.

Thank you!

πŸ’¬ Support request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡·πŸ‡΄Romania ioana apetri

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @ioana apetri
  • πŸ‡ΊπŸ‡ΈUnited States jmester13

    I'm running 2.0.4 and also getting this in Search Console.

    tag is being places inside the

  • πŸ‡¨πŸ‡¦Canada hommesreponse

    Same problem here. Running version 2.04

  • πŸ‡ΊπŸ‡ΈUnited States jmester13

    Update here, be sure to check you GA account settings.

    Admin > Account > Account Details. Be sure that Data Processing Terms is unchecked. My website is US based and doesn't have GDPR requirements.

  • πŸ‡·πŸ‡΄Romania ioana apetri

    Can you provide me more details, how to set up this option? I can't find any 'Data Processing Terms'.
    Thank you!

  • Hi all! Our team has started receiving the following error on Google Analaytics: Your Google Tag code isn’t configured correctly, which may soon prevent your property from measuring automatic events. To fix this, place your Google Tag configuration code in the correct location on all pages that measure events.

    We presume this is because of the new GTM updates that require script tags to be placed in the head tag, rather than the body tag. Currently, this module only places a script tag in the body of our site.

    How have people configured the tags to show up in the head? And has anyone else encountered this GTM error before?
    Thank you :)

  • πŸ‡©πŸ‡ͺGermany marcusx

    I can confirm that Google complains about the placement of the gtag.js script.

    See:
    https://support.google.com/tagmanager/answer/14847097?sjid=4908559106955...

    Copy the first block of code and paste it as high in the tag as possible.

    I patched the google_tag.libraries.yml file. Can someone confirm that this creates not a problem elsewhere?

    I also had to switch off consent mode (on the Google_tag settings page, at the bottom) (which switches on the default gtag settings) and put the default values manually in the head tag at the very first line. I was unable to alter the module logic to achieve this goal through an alter API call. But I had not enough time to dig deep into that. Considering that, putting the settings into html.html.twig a hack. Better ideas are appreciated.

      <head>
        <script>
          window.dataLayer = window.dataLayer || [];
          function gtag() { dataLayer.push(arguments); }
          gtag('consent', 'default', {
            'ad_user_data': 'denied',
            'ad_personalization': 'denied',
            'ad_storage': 'denied',
            'analytics_storage': 'denied',
            'wait_for_update': 500,
          });
          gtag('js', new Date());
        </script>
    
  • Status changed to Needs review 5 months ago
  • πŸ‡©πŸ‡ͺGermany marcusx
  • First commit to issue fork.
  • Merge request !87Move tag injection to header β†’ (Merged) created by japerry
  • Pipeline finished with Skipped
    5 months ago
    #234241
  • Status changed to Fixed 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States japerry KVUO
  • πŸ‡¬πŸ‡§United Kingdom newaytech

    Thanks for all the work on the GTM module - sorry I didn't see this issue earlier to chime in...

    We use CookieBot to set consent - so need opportunity for that to load - provide consent signals to the dataLayer - for us to then utilise those within the framework of GTM. At the moment with this addition - the placement of all the Google Tag code in the header is causing the dataLayer events to be pushed prior to consent being delivered by CookieBot. The other side effect here is that we pull a heap more Javascript up into the head - slowing the perceived page rendering speed by Google.

    Is it possible for me to retrospectively apply a dependency on my CookieBot cookie library such that the cookie code always runs first - at the moment it is being called after the gtag / ajax & gtm javascript files...

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • πŸ‡¨πŸ‡¦Canada adixon

    This patch should be reverted asap, it causes issues with Olivero. See below:

    https://www.drupal.org/project/drupal/issues/3474666 πŸ› Olivero theme have an error for Drupal 10.3 Active

    https://www.drupal.org/project/google_tag/issues/3468036#comment-15811949 πŸ› Problems with google tag i think after it upgraded to 2.0.6 Active

Production build 0.71.5 2024