- Issue created by @alemadlei
- π¨π¦Canada gapple
In 1.x a dynamically created inline script is added to the document head that:
1. Initializes a placeholderdataLayerarray
2. Adds the external tag manager script to the page with thedeferattribute. 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 placeholderdataLayerarray.
2. Uses configuration passed withdrupalSettingsto add the external tag manager script to the page with theasyncattribute (since the script is at the bottom of the page, it is technically alreadydefered). 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
dataLayervariable is available to other scripts on the page. With 2.x, other libraries which usedataLayerwill need to specify the google_tag library as a dependency to ensure they are correctly ordered to execute later whendataLayeris available. Any inline scripts inserted earlier in the page will not have access to thedataLayervariable. (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 thatdataLayeris 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
about 1 year ago 9:12pm 27 August 2024