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

dmundra created an issue. See original summary.

dmundra’s picture

StatusFileSize
new3.33 KB

Here is the patch that fixes the error for me. It replaces 'drupalSettings' with the regular convention 'Drupal.settings'.

dmundra’s picture

StatusFileSize
new3.19 KB

Noticed a small bug in my previous patch. Here is a new one.

damienmckenna’s picture

Version: 7.x-2.7 » 7.x-2.x-dev
Status: Active » Needs review

That seems like the correct approach - D7 uses Drupal.settings instead of drupalSettings.

mglaman’s picture

Status: Needs review » Reviewed & tested by the community

Oh jeez, thanks. That's a big whoopsie.

  • mglaman committed 72ea808a on 7.x-2.x authored by dmundra
    Issue #3349458 by dmundra, DamienMcKenna: drupalSettings is not defined...
mglaman’s picture

Status: Reviewed & tested by the community » Fixed

Thank you! Committed. I am waiting to release to review any other issues, I'll release next week.

damienmckenna’s picture

Thanks for the quick response, mglaman. I wonder might this have caused some of the other bugs people reported?

mglaman’s picture

:/ probably

dmundra’s picture

Hey @mglaman, no worries and thank you for committing it.

Status: Fixed » Closed (fixed)

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

ohanm’s picture

Hi mglaman, if I undertsand #7 correctly, will there be another release?

mglaman’s picture

Ah sorry, I thought I did. I made a task for myself. Sorry!

mglaman’s picture