- Issue created by @alemadlei
- π¨π¦Canada gapple
In 1.x a dynamically created inline script is added to the document head that:
1. Initializes a placeholderdataLayer
array
2. Adds the external tag manager script to the page with thedefer
attribute. The browser will download the script, but not execute it until the DOM has finished parsing.In 2.x a local script file is added to the bottom of the page that:
1. Initializes a placeholderdataLayer
array.
2. Uses configuration passed withdrupalSettings
to add the external tag manager script to the page with theasync
attribute (since the script is at the bottom of the page, it is technically alreadydefer
ed). The browser will download the script and execute it when it is available (and the JS thread is not otherwise occupied).The only functional difference is when the
dataLayer
variable is available to other scripts on the page. With 2.x, other libraries which usedataLayer
will need to specify the google_tag library as a dependency to ensure they are correctly ordered to execute later whendataLayer
is available. Any inline scripts inserted earlier in the page will not have access to thedataLayer
variable. (You should get errors in the browser console if this were causing issues).
You can alter the google_tag library to place it in the head of the page so thatdataLayer
is available earlier in the page parsing. - First commit to issue fork.
- πΊπΈUnited States adanbouzoua
adanbouzoua β changed the visibility of the branch 3451427-script-placement-differences to hidden.
- Status changed to Closed: works as designed
11 days ago 9:12pm 27 August 2024