HTML DOM Script Appender (programatically)
JS
S
JavaScriptBasic way of programmatically appending a script.
1const pixelAppenderHeap = () => {
2 const script = document.createElement('script')
3 script.type = 'text/javascript';
4 const inlineScript = document.createTextNode(
5 `window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var r=t.forceSSL||"https:"===document.location.protocol,a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=(r?"https:":"http:")+"//cdn.heapanalytics.com/js/heap-"+e+".js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n);for(var o=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["addEventProperties","addUserProperties","clearEventProperties","identify","resetIdentity","removeEventProperty","setEventProperties","track","unsetEventProperty"],c=0;c<p.length;c++)heap[p[c]]=o(p[c])};
6 heap.load("xxxxx");`
7 );
8 script.appendChild(inlineScript);
9 script.onload = () => { }
10 document.head.appendChild(script)
11};Created on 6/1/2018