- Issue created by @J-Lee
- 🇩🇪Germany Anybody Porta Westfalica
Thanks @J-Lee, could you prepare a MR to fix this eventually? I'm very busy currently.
- 🇩🇪Germany J-Lee 🇩🇪🇪🇺
After looking at the new behavior, I'm not quite sure which way to go.
The iframe is inserted via
hook_page_top()
(is now rendered via a template).
Viahook_page_attachments()
the information about the Google tag manager (gtm) and Google tag (gtag) are inserted indrupalSettings
. For both, a JS-library is also added there. In the JavaScripts the information is read fromdrupalSettings
and the script tags are generated dynamically.As far as I understood, so far (google_tag module v1) the script
type="text/javascript"
was changed to scripttype="text/plain"
. After the approval was successful, thetext/plain
was then removed again, which enabled the script.In version 2 the script tags are no longer generated in PHP. Therefore, the only option I see right now is to use
hook_page_attachments_alter()
to remove the two libraries (gtm and gtag) and rebuild the two scripts in the cookies module and adjust them accordingly so that it matches the current behaviorGoogle tag manager script: https://git.drupalcode.org/project/google_tag/-/blob/2.0.x/js/gtm.js
Google tag script: https://git.drupalcode.org/project/google_tag/-/blob/2.0.x/js/gtag.js - 🇩🇪Germany Anybody Porta Westfalica
@J-Lee short hint: Perhaps take a look into the COOKiES submodules and COOKiES contrib modules, perhaps there's already a solution for a similar case.
Thank you!
We'll come back here as soon as possible, but I think that may need at least some weeks, sorry. Of course, we'll be able to review MR's in the meantime.
- last update
over 1 year ago 87 pass, 2 fail - @j-lee opened merge request.
- 🇩🇪Germany J-Lee 🇩🇪🇪🇺
The MR is not ready yet.
- The support for the google_tag module v1 still needs to be checked.
- There are errors when loading the Google Tag Manager:
Failed to load resource: net::ERR_SOCKET_NOT_CONNECTED
forwww.googletagmanager.com/gtm.js?id=GTM-XXXXXX
- Status changed to Needs work
over 1 year ago 11:37am 28 July 2023 - last update
over 1 year ago 87 pass, 2 fail - last update
over 1 year ago 88 pass - Status changed to Needs review
over 1 year ago 7:14am 31 July 2023 - 🇩🇪Germany J-Lee 🇩🇪🇪🇺
Compatibility for google_tag module v1 restored.
TheERR_SOCKET_NOT_CONNECTED
error was apparently only a local problem and cannot be reproduced at the moment.The tests should be fine for the google_tag module v2. Since the functionality of JS is actually the same.
- 🇩🇪Germany Anybody Porta Westfalica
Thanks @J-Lee very awesome work!
Some thoughts:
1. Is the code simply for both versions, or are parts for v1 and others for v2? (If yes, please add comments to make it easier to remove the old parts one day)
2. "eval is evil", any way to solve that differently? https://dev.to/amitkhonde/eval-is-evil-why-we-should-not-use-eval-in-jav...
We're gaining security risks this way, so if possible it should be avoided.Thank you very much, this already looks very promising!
- 🇩🇪Germany J-Lee 🇩🇪🇪🇺
1. I can add something like
/** @group google_tag_v1 */
and/** @group google_tag_v2*/
.
2. The scripts must be executed for the Tag Manager to load. However, the scripts are IIFEs. I can do something like this:... const script = document.querySelector('script#' + id); const code = script.textContent || script.innerText; const executeCode = Function(code); executeCode();
But, is this more secure?
- last update
over 1 year ago 88 pass - last update
over 1 year ago 88 pass - last update
over 1 year ago 88 pass - 🇩🇪Germany J-Lee 🇩🇪🇪🇺
I addressed the points from #9 and fixed a few minor bugs.
With this the MR is ready to be reviewed further. - 🇫🇷France Asterovim Paris
Hello, I encountered a problem with the patch for Google tag 2.0.2 and drupal 9.5.10. The Google tag module does not load on my site, regardless of the consent status.
- 🇩🇪Germany J-Lee 🇩🇪🇪🇺
@Asterovim I cannot confirm your problem. TagManager loads and is visible. I have also used Google's Chrome extension "Tag Assistant" to troubleshoot.
Are there any error messages?
Have you tried clearing the cache? - 🇨🇦Canada joseph.olstad
@Asterovim
if your composer is installing the patch correctly, you'll find it listed in a PATCHES.txt file inside the patched moduleif not, then review your composer.json
are you using this patch?
https://git.drupalcode.org/project/cookies/-/merge_requests/94.patch - Assigned to Grevil
- 🇸🇮Slovenia joco_sp
Thank you for the patch.
The cookies are now blocked, but when clicking on Accept all, they are not added to the website.I'm using:
core 10.1.2
cookies (cookies_gtag) 1.2.3
google_tag 2.0.2 - 🇩🇪Germany J-Lee 🇩🇪🇪🇺
@joco_sp Can you confirm that the script has loaded? Maybe it can also help to include some console.log() for debugging.
In most cases, a caching mechanism is responsible for making it appear that it is not working. Clearing Drupal caches and possibly also the browser cache usually helps. - Status changed to Needs work
about 1 year ago 2:46pm 25 September 2023 - 🇩🇪Germany Grevil
I see a flaw in the attachment logic inside the page_attachments alter. Note that all library attachments will go through this hook, so array_diff won't work in this case as there can be further libraries outside the gtag libraries.
Furthermore, as Drupal 8 has reached its EOL long ago and D9 will very soon be also EOL, we can kill the D8 compatibility, make the module's min requirement Drupal 9.5 and end support for the Google Tag 1.x module. This way, we don't need to have old v1 code lying around, which is obsolete anyway in modern Drupal projects.
I'll do some adjustments.
- last update
about 1 year ago 88 pass - 🇩🇪Germany Grevil
Yea, I think the MR is not the right approach, I guess we simply have to add our js library in hook_page_attachments and alter the script in hook_js_alter() instead of page_attachments or page_attachments_alter. Similar to cookies_instagram or cookies_facebook_pixel, I'll create a new branch.
Sorry @J-Lee, but I might be able to reuse some of your code! 🙂👍
- Assigned to Anybody
- Status changed to Needs review
about 1 year ago 11:46am 26 September 2023 - last update
about 1 year ago 80 pass, 6 fail - @grevil opened merge request.
- Assigned to Grevil
- Status changed to Needs work
about 1 year ago 12:24pm 26 September 2023 - last update
about 1 year ago 84 pass, 4 fail - last update
about 1 year ago 84 pass, 4 fail - 🇩🇪Germany Grevil
6 failing tests
Yea, that old problem where you are not able to log in for some reason... I forgot how we fixed that back then. I'll have a look.
- last update
about 1 year ago 84 pass, 4 fail - last update
about 1 year ago 88 pass - last update
about 1 year ago 88 pass - Assigned to Anybody
- Status changed to Needs review
about 1 year ago 2:34pm 26 September 2023 - Issue was unassigned.
- Status changed to RTBC
about 1 year ago 2:36pm 26 September 2023 - 🇩🇪Germany Anybody Porta Westfalica
@all here: Could you please test, if the fix works for you? Code looks good, I'll merge it into dev so for easier testing.
With positive results we'll tag a new stable release! - last update
about 1 year ago 88 pass - 🇩🇪Germany Anybody Porta Westfalica
Just tried in production and works GREAT! Thank you @Grevil and @J-Lee!
- Status changed to Fixed
about 1 year ago 2:42pm 26 September 2023 - 🇩🇪Germany Anybody Porta Westfalica
Waiting for feedback before we tag a new release.
- Status changed to RTBC
about 1 year ago 2:43pm 26 September 2023 - Status changed to Fixed
about 1 year ago 2:45pm 26 September 2023 Automatically closed - issue fixed for 2 weeks with no activity.