Issue-piwik_pro-3482342: Moved JS snippets to separate script files.
Closes #3482342
Merge request reports
Activity
added 1 commit
- 59cd259d - Issue-piwik_pro-3482342:Solved PHPCS Errors.
added 1 commit
- 7d1d7823 - Issue-piwik_pro-3482342: Tried to solve ESLint Errors.
1 1 (function (window, document, dataLayerName, id) { 2 window[dataLayerName] = window[dataLayerName] || []; 3 window[dataLayerName].push({ start: new Date().getTime(), event: 'stg.start' }); 4 5 var scripts = document.getElementsByTagName('script')[0]; 6 var tags = document.createElement('script'); 7 8 function stgCreateCookie(a, b, c) { 9 var d = ''; 10 if (c) { 11 var e = new Date(); 12 e.setTime(e.getTime() + 24 * c * 60 * 60 * 1e3); 13 d = '; expires=' + e.toUTCString(); 14 } 15 document.cookie = a + '=' + b + d + '; path=/'; 2 window[dataLayerName] = window[dataLayerName] || []; @anish.ir I think we can add these files to .eslintignore because the code is most likely directly coming from Piwik PRO and we don't need to modify it.
It might be hard to maintain also because we don't know what changes they are making to the script and we might break something accidentally.
I would add these Piwik PRO snippet scripts to .eslintignore and comment in the file that they are third party vendor code.
Hey @HeikkiY , I have solved the eslint errors, the errors were because of quotes, which are resolved now.
added 1 commit
- f4da4800 - Issue-piwik_pro-3482342: Solved the Eslint errors.
added 1 commit
- ad2a7d49 - Issue-piwik_pro-3482342: Solved the Eslint errors.
16 16 stgCreateCookie("stg_debug", isStgDebug ? 1 : "", isStgDebug ? 14 : -1); 17 17 18 var qP = []; 18 const qP = []; 19 19 if (dataLayerName !== "dataLayer") { 20 qP.push("data_layer_name=" + dataLayerName); 20 qP.push(`data_layer_name=${dataLayerName}`); 21 21 } 22 22 if (isStgDebug) { 23 23 qP.push("stg_debug"); 24 24 } 25 var qPString = qP.length > 0 ? "?" + qP.join("&") : ""; 26 document.write('<script src="' + id + ".sync.js" + qPString + '"></script>'); 25 const qPString = qP.length > 0 ? `?${qP.join("&")}` : ""; 26 document.write(`<script src="${id}.sync.js${qPString}"></script>`); 27 27 })(window, document, "dataLayer", "https://your-piwik-pro-domain.com/"); 13 13 (window.location.href.match("stg_debug") || 14 14 document.cookie.match("stg_debug")) && 15 15 !window.location.href.match("stg_disable_debug"); 16 16 stgCreateCookie("stg_debug", isStgDebug ? 1 : "", isStgDebug ? 14 : -1); 17 17 18 var qP = []; 18 const qP = []; 19 19 if (dataLayerName !== "dataLayer") { 20 qP.push("data_layer_name=" + dataLayerName); 20 qP.push(`data_layer_name=${dataLayerName}`); 21 21 } 22 22 if (isStgDebug) { 23 23 qP.push("stg_debug"); 24 24 } 25 var qPString = qP.length > 0 ? "?" + qP.join("&") : ""; 26 document.write('<script src="' + id + ".sync.js" + qPString + '"></script>'); I am mildly worried about these changes because I would suspect that these are originally coming from Piwik PRO and might be hard to test that everything works correctly at their end.
Would @JoshaHubbers have time to take a look at this?
- piwik_pro.libraries.yml 0 → 100644
added 1 commit
- ee733935 - Issue-piwik_pro-3482342: Added version in libraries, removed hard-coded domain.
added 1 commit
- 455fddda - Issue-piwik_pro-3482342: Solved the Eslint quote error.
- js/piwik_pro_sync.js 0 → 100644
1 (function (window, document, dataLayerName, id) { @JoshaHubbers What do you think about this? Did this code originally come from Piwik PRO or is this custom JS written by you? I am wondering if this should be kept as original as possible or would refactoring this to follow Drupal JS linters make sense.
- js/piwik_pro_sync.js 0 → 100644
1 (function (window, document, dataLayerName, id) { 2 function stgCreateCookie(a, b, c) { This script is deprecating in January 2025 so we basically should remove it completely. There is a task https://www.drupal.org/project/piwik_pro/issues/3486733 which should be handled before this issue can progress.
More information: https://help.piwik.pro/support/tag-manager/sunset-of-synchronous-containers-and-tags/