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
Comment #2
tbsiqueiraComment #3
tbsiqueiraSuggestion patch
Comment #4
viniciusrp commentedI tested the patch locally and fix the problem.
Comment #5
viniciusrp commentedComment #6
tbsiqueiraFrom 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.
Comment #7
japerryNope, I don't see any reason why it'd need to be global. Fixed!
Comment #10
foxy-vikvik commentedI’m experiencing the same issue. JS aggregation is enabled on my project, and we have a duplicate variable dl, which causes the error:
Applying this patch resolves the issue for me.
Comment #11
i-trokhanenkoI ran into the exact same error on a Drupal 11 site:
Uncaught SyntaxError: Identifier 'dl' has already been declaredIn our case, the issue was occurring for anonymous users and was caused by a conflict around the global
dldeclaration 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.
Comment #12
jeroentThis issue was fixed in the latest dev-version, which still needs to be released. So closing this issue.
Comment #15
daften commentedHi, qq. Is a release planned in the near future? :)