Problem/Motivation
Since https://www.drupal.org/project/google_tag/issues/3452712, parts of this module's javascript load in the <head> element and have started somewhat of a cascade effect for performance.
The gtag and gtm libraries have a dependency on core/drupalSettings which causes the drupal settings loader to become render-blocking as well. All in all, it's fairly bad business to load javascript synchronously in the head these days.
Steps to reproduce
Enable the module, notice first paint is blocked by a round-trip for javascript resources that don't actually influence rendering.
Proposed resolution
Revert the change that loads the javascript synchronously.
GTM based site verification is only one mechanism of ownership verification that Google offers!
Remaining tasks
- Review
- Commit
- Update documentation to encourage site owners to use alternative verification methods
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | new-optimize-web-vitals-setting.png | 110.81 KB | luke.leber |
Issue fork google_tag-3549374
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- revert-3452712
changes, plain diff MR !128
- 2.0.x
compare
- 3549374-synchronous-js-in
changes, plain diff MR !126
Comments
Comment #2
dpagini commentedI'd like to propose this issue as a major priority. If you don't want this change due to the aforementioned performance issues, you have to rollback to 2.0.3, I believe, and that version of the module has an open security threat.
Comment #3
nitesh624yes we can't roll back to previous version due to security issue in older version. I believe this need to be prioritize and worked on based on suggestion given.
Comment #4
nitesh624Is there any update here?
Comment #5
nitesh624I did some research around this I posted my findings in https://www.drupal.org/project/google_tag/issues/3452712 issue.
I think we can rollback changes done in https://www.drupal.org/project/google_tag/issues/3452712 and address the actual root cause for that
Comment #6
luke.leberUpdated proposed resolution; merge request imminent.
Comment #8
luke.leberComment #9
luke.leberComment #10
dpagini commentedThanks for putting this up, @luke.leber!
I have a question for this module, and I was thinking I'm going to create a new issue for it, but I might as well start here... In my team's testing, the original PR that does this is 3452712, which states that there was a problem registering the site with "Google Search Console".
In our testing, I can't register a site with the
google_tagmodule installed BEFORE 3452712, and I can't register a site with it AFTER. In both cases, I get the error message that the snippet is in the wrong location. I almost expected this, b/c this module doesn't add the code that Google tells you to use directly, it's wrapped in some Drupal-ism wrapper javascript so we can use drupalSettings, and included via a local JS file. So I have a lot of questions if the original change was fully tested...? Or maybe Google changed since then, I just can't figure out how to determine what happened...Anyways, one of our team's developers figured out that, he actually COULD get Google Search Console to recognize the site by making sure the
<noframe>snippet was immediately following the body tag, which it does not do by default.So this new MR is going to make this an optional setting... but I guess I want to challenge if this code should even be left intact in the first place. If it's a) not working, and b) causing some real javascript challenges... why not just revert 3452712? I really don't see any comments on that original issue that indicate that this worked for them...
Comment #11
luke.leberHey David,
My take on the situation is that this module was "doing it wrong" from the beginning by making the Google libraries dependent on the Drupal libraries (purely speaking in terms of site verification through Tag Manager). Given we can't know how Google operates internally when it comes to such verification, I think it'd be safest to encourage site owners to use alternative verification methods wholesale.
My first pass at this (that I didn't commit) also added a textfield for the meta-tag driven verification method as well, but I opted against that in the end because it seems like something this module shouldn't be doing.
I would wager that this module has always had somewhat of a race condition with Google's GTM based verification method. If the maintainers would be up to reverting #3452712: Possibly script loading/placement issue that would be preferable to me as well.
Comment #12
dpagini commentedYeah, I think we're on the same page.
This is slightly funny, this conversation reminded me of recently coming across this issue, https://www.drupal.org/project/drupal/issues/3542042, which you also appear to be the author of, so not much use in brining it forward, ha! But it almost seems like the google_tag module should do something like this inline approach if a user wants the "google way" of loading it as high as possible on the page...
Any suggestions on getting some maintainers attention on this...? It seems these issues with the
header: truehave been ongoing since this was committed in the Fall of '24, and issues like this, to bring up that concern, have seemed to be going ignored... maybe the entire module is not actively maintained...?Comment #13
catchReverting #3452712: Possibly script loading/placement issue and trying to fix the original problem in a different way sounds good to me too.
Comment #14
nitesh624yes agreed with @catch here
Comment #16
luke.leberUpdate IS.
Comment #18
nitesh624Latest MR worked for me
Comment #19
nagy.balint commentedMR !128 gave me an around 20 point increase in the mobile performance score on google pagespeed insights.
Comment #21
japerryConfirmed the bug with a test. MR !128 looks correct to me. Fixed!
Note, in our release notes: