generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change GTM integration to delayed integration
- Loading branch information
1 parent
59bf391
commit 52e2568
Showing
5 changed files
with
44 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ | |
* [email protected] | ||
*/ | ||
|
||
import { loadThirdPartyScriptWithoutPartytown } from '../../scripts/load-thirdparty-script.js'; | ||
import { buildBlock, decorateBlock, loadBlock } from '../../scripts/aem.js'; | ||
import { loadScriptDelayed } from '../../scripts/load-resource.js'; | ||
|
||
const includeScript = false; | ||
|
||
|
@@ -44,7 +44,7 @@ export default async function decorate(block) { | |
|
||
// load script | ||
if (includeScript) { | ||
loadThirdPartyScriptWithoutPartytown( | ||
loadScriptDelayed( | ||
`https://portal.combeenation.com/plugin/EDER/${configuratorCode}`, | ||
) | ||
.then(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,11 @@ | |
* [email protected] | ||
*/ | ||
|
||
import { | ||
createThirdPartyRelatedScriptTag, | ||
loadThirdPartyScript, | ||
loadThirdPartyScriptWithoutPartytown, | ||
} from '../../scripts/load-thirdparty-script.js'; | ||
import { createThirdPartyRelatedScriptTag, loadThirdPartyScript } from '../../scripts/load-thirdparty-script.js'; | ||
import { | ||
getCurrentUrl, hasUrlParam, isLocal, isTest, transformRowsToData, | ||
} from '../../scripts/helpers.js'; | ||
import { betterLoadScript } from '../../scripts/load-resource.js'; | ||
import { loadScriptDelayed } from '../../scripts/load-resource.js'; | ||
|
||
/** | ||
* Load usercentrics | ||
|
@@ -32,11 +28,8 @@ function loadUsercentrics(id) { | |
it works with partytown but settings button in footer doesn't work | ||
If we use "loader.js" with "betterLoadScript": | ||
everything works but without partytown loading to a lower lighthouse score | ||
If we use "loadThirdPartyScriptWithoutPartytown" | ||
the script will load too late | ||
So we use "betterLoadScript" for now. | ||
*/ | ||
return betterLoadScript( | ||
return loadScriptDelayed( | ||
'https://app.usercentrics.eu/browser-ui/latest/loader.js', | ||
{ | ||
id: 'usercentrics-cmp', | ||
|
@@ -53,26 +46,21 @@ function loadUsercentrics(id) { | |
*/ | ||
function loadUserlike(id) { | ||
// FIXME we already contacted userlike to provide support for partytown, they did not respond yet | ||
return loadThirdPartyScriptWithoutPartytown( | ||
return loadScriptDelayed( | ||
`https://userlike-cdn-widgets.s3-eu-west-1.amazonaws.com/${id}.js`, | ||
); | ||
} | ||
|
||
/** | ||
* Init data layer | ||
* | ||
* @param {string} id | ||
*/ | ||
function initDataLayer(id) { | ||
window.dataLayer = window.dataLayer || []; | ||
|
||
window.gtag = function gtag() { | ||
// eslint-disable-next-line prefer-rest-params | ||
window.dataLayer.push(arguments); | ||
}; | ||
|
||
window.gtag('js', new Date()); | ||
window.gtag('config', id); | ||
function initDataLayer() { | ||
const dataLayerName = 'dataLayer'; | ||
window[dataLayerName] = window[dataLayerName] || []; | ||
window[dataLayerName].push({ | ||
'gtm.start': new Date().getTime(), | ||
event: 'gtm.js', | ||
}); | ||
} | ||
|
||
/** | ||
|
@@ -87,16 +75,16 @@ function loadGoogleTagManager(id) { | |
* we can switch to serving GTM normally here | ||
*/ | ||
const usePartyTownForGTM = false; | ||
const gtmUrl = `https://www.googletagmanager.com/gtag/js?id=${id}`; | ||
const gtmUrl = `https://www.googletagmanager.com/gtm.js?id=${id}`; | ||
if (!usePartyTownForGTM || hasUrlParam('gtm_debug') || sessionStorage.getItem('gtm_debug')) { | ||
sessionStorage.setItem('gtm_debug', '1'); | ||
initDataLayer(id); | ||
betterLoadScript(gtmUrl).then(); | ||
initDataLayer(); | ||
loadScriptDelayed(gtmUrl).then(); | ||
return Promise.resolve(); | ||
} | ||
return Promise.all( | ||
[ | ||
createThirdPartyRelatedScriptTag(`${initDataLayer.toString()} ${initDataLayer.name}('${id}');`), | ||
createThirdPartyRelatedScriptTag(`${initDataLayer.toString()} ${initDataLayer.name}();`), | ||
loadThirdPartyScript(gtmUrl), | ||
], | ||
); | ||
|
@@ -153,7 +141,7 @@ function loadAdobeAnalytics(url) { | |
|
||
// load URL | ||
// FIXME use "loadThirdPartyScript" as soon as Adobe Analytics uses the correct CORS headers | ||
return loadThirdPartyScriptWithoutPartytown(url); | ||
return loadScriptDelayed(url); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters