Problem/Motivation
We are using the 7.x-2.7 version with the Google Analytics 4 patches and noticed that colorbox popups are throwing JavaScript errors. Here is the error and the line in the source https://git.drupalcode.org/project/google_analytics/-/blob/7.x-2.7/googl....
Best seen if you have colorbox setup but I don't think the issue is caused by colobox. I think the variable 'drupalSettings' is not being loaded correctly.
Uncaught ReferenceError: drupalSettings is not defined
at HTMLDocument.<anonymous> (googleanalytics.js?rrw0pp:82:16)
at HTMLDocument.dispatch (jquery.min.js?v=1.8.3:2:38053)
at HTMLDocument.u (jquery.min.js?v=1.8.3:2:33916)
at Object.trigger (jquery.min.js?v=1.8.3:2:36647)
at HTMLDocument.<anonymous> (jquery.min.js?v=1.8.3:2:44416)
at Function.each (jquery.min.js?v=1.8.3:2:14543)
at $.fn.init.each (jquery.min.js?v=1.8.3:2:11217)
at $.fn.init.trigger (jquery.min.js?v=1.8.3:2:44392)
at trigger (jquery.colorbox-min.js?v=1.3.25:6:4422)
at complete (jquery.colorbox-min.js?v=1.3.25:6:14752)
Proposed resolution
I think the google analytics JavaScript needs to load 'drupalSettings' in the initial function setup. Is it maybe a Drupal 9 feature and not something available in Drupal 7?
Comments
Comment #2
dmundraHere is the patch that fixes the error for me. It replaces 'drupalSettings' with the regular convention 'Drupal.settings'.
Comment #3
dmundraNoticed a small bug in my previous patch. Here is a new one.
Comment #4
damienmckennaThat seems like the correct approach - D7 uses Drupal.settings instead of drupalSettings.
Comment #5
mglamanOh jeez, thanks. That's a big whoopsie.
Comment #7
mglamanThank you! Committed. I am waiting to release to review any other issues, I'll release next week.
Comment #8
damienmckennaThanks for the quick response, mglaman. I wonder might this have caused some of the other bugs people reported?
Comment #9
mglaman:/ probably
Comment #10
dmundraHey @mglaman, no worries and thank you for committing it.
Comment #12
ohanm commentedHi mglaman, if I undertsand #7 correctly, will there be another release?
Comment #13
mglamanAh sorry, I thought I did. I made a task for myself. Sorry!
Comment #14
mglamanReleased! https://www.drupal.org/project/google_analytics/releases/7.x-2.8