Best way to add a script in a guided landing page

Grégoire_Miche2
Level 10

Re: Best way to add a script in a guided landing page

Found JS injection code from Facebook that can be tuned by a developper.

(function(d, s, id){
  
var js, fjs = d.getElementsByTagName(s)[0];
  
if (d.getElementById(id)){ return; }
  js
= d.createElement(s); js.id = id;
  js
.onload = function(){
  
// remote script has loaded
  
};
  js
.src = "${scriptURI}";
  fjs
.parentNode.insertBefore(js, fjs);
}(document, 'script', '${ScriptID}'));

-Greg

Thorsten
Level 4

Re: Best way to add a script in a guided landing page

Hey,

I am looking for a way to better organize the scripts in our templates. Is the option with the variable and injection still considered best practise? If so, can someone help me come up with a robust injection script? I'm afraid I am too inexperienced to convert the Facebook sample into something suitable and don't want to mess up, the solutions I found on Google seem to be more or less shady 🙂