My host does not allow to publish code with javascript and I would like to know if it is possible to use GTM for this. In this case I will create a static page with a div and check the ID in GTM, if true I will run the script.
if (document.getElementById("id")) {
// the script here
}
Does this idea make sense?
I'm asking before testing, because the page in this case is an e-commerce, and every time I publish a new version in GTM the performance drops drastically.
Yes it's possible, but is considered a bad practice, according to a deleted comment, the scripts need to run after full loaded page.
Something like this:
document.addEventListener('DOMContentLoaded', function() {
if (document.getElementById("id")) {
// the script here
}
}, false);