frankiehayward
9/5/2019 - 7:38 PM

Generic Script Injection

Setup script to injection javascript in the head tag.

VariableDescriptionExample
'src'Path to the file'google.com/api/gtm.js'
'id'Script identifier'gtm-container'
'VenderTrack'Vendor's name'GoogleTagManager'
(function(a,b,c,d,e,f,g,h){
  if(typeof a['VendorTrack'] !== 'undefined') { return; }
  a['VendorTrack'] = e;
  g = b.getElementsByTagName(c)[0];
  f = b.createElement(c);
  f.type = 'text/javascript';
  f.async = true;
  f.src = '//' + d ;
  f.id = e;
  g.parentNode.insertBefore(f, g);
})(window,document,'script','src','id');