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.
2
Answers
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:
Technically, yes (from question and comment I gather that this is some sort of page editor that does not allow to include custom JS, but provides GTM access; if you were flat out not allowed to use JS, GTM would not work, either).
Good idea? No, for at least three reasons:
It would probably be easier to change hosts (and/or use some server-side technology to generate the website for you).