Problem/Motivation

gtm.js file defines a constant named "dl". Unfortunately, this is a global constant that might interfere with other function name/variables declaration on other JS files. ( as it's happening with my installation ) creating the following error:

Uncaught SyntaxError: Identifier 'dl' has already been declared
    at: my-js-file.here.js

Unfortunately, I cannot control my lib compression, making it impossible for me to use my own lib with gtm, unless I don't minimize the js file.

Steps to reproduce

Create any js lib/script that declares a function / constant named "dl"

Proposed resolution

if it's not possible to move those global declarations to inside the function wrapper in gtm.js file itself, would it be possible to prefix the constant name to make is more scoped to google_tag module?

Remaining tasks

User interface changes

API changes

Data model changes

Comments

tbsiqueira created an issue. See original summary.

tbsiqueira’s picture

Issue summary: View changes
tbsiqueira’s picture

Suggestion patch

viniciusrp’s picture

I tested the patch locally and fix the problem.

viniciusrp’s picture

Status: Active » Reviewed & tested by the community
tbsiqueira’s picture

From the Google Tag documentation we can see that the code is self-contained, and we can't find any necessary usage for the globally defined variable.

japerry’s picture

Status: Reviewed & tested by the community » Fixed

Nope, I don't see any reason why it'd need to be global. Fixed!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • japerry committed 80535950 on 2.0.x
    Issue #3560472 by tbsiqueira: dl const declaration conflicts with other...
foxy-vikvik’s picture

Status: Fixed » Needs work

I’m experiencing the same issue. JS aggregation is enabled on my project, and we have a duplicate variable dl, which causes the error:

Uncaught SyntaxError: Identifier 'dl' has already been declared

Applying this patch resolves the issue for me.

i-trokhanenko’s picture

I ran into the exact same error on a Drupal 11 site:

Uncaught SyntaxError: Identifier 'dl' has already been declared

In our case, the issue was occurring for anonymous users and was caused by a conflict around the global dl declaration coming from the Google Tag module integration.

After applying the patch #3 provided in this issue, the problem was resolved and the error no longer appears.

jeroent’s picture

Status: Needs work » Fixed

This issue was fixed in the latest dev-version, which still needs to be released. So closing this issue.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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

daften’s picture

Hi, qq. Is a release planned in the near future? :)