Here's the snippet as of May 2021:
window.heap = window.heap || [], heap.load = function (e, t) {
window.heap.appid = e, window.heap.config = t = t || {};
var r = document.createElement("script");
r.type = "text/javascript", r.async = true, r.src = "https://cdn.heapanalytics.com/js/heap-" + e + ".js";
var a = document.getElementsByTagName("script")[0];
a.parentNode.insertBefore(r, a);
for (var n = function (e) {
return function () {
heap.push([e].concat(Array.prototype.slice.call(arguments, 0)));
};
}, p = ["addEventProperties", "addUserProperties", "clearEventProperties", "identify", "resetIdentity", "removeEventProperty", "setEventProperties", "track", "unsetEventProperty"], o = 0; o < p.length; o++) heap[p[o]] = n(p[o]);
};
heap.load("YOUR_APP_ID");
First, it defines a global heap
object.
Then it defines a heap.load
method. heap.load
first sets your app id e
and options t
to the window.heap
object for future use.
Next, it creates a new script element to load the heap.js tracking script. heap.js sends event data to Heap.
After heap.js starts loading, heap.load
stubs out the following methods so that they can be called before heap.js finishes loading:
heap.addEventProperties
heap.addUserProperties
heap.clearEventProperties
heap.identify
heap.resetIdentity
heap.removeEventProperty
heap.setEventProperties
heap.track
heap.unsetEventProperty
Lastly, the script calls the previously-defined heap.load
with your app id. :)
You can read more on Heap's developer documentation.