I'm trying to add Heap Analytics as a tracking tool to my Craft site. From Heap's installation docs, I need to add this code snippet before the closing tag. I'm pretty new to using Craft, can someone please explain how to go about doing this?

Code snippet:

<script type="text/javascript">
    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","removeEventProperty","setEventProperties","track","unsetEventProperty"],c=0;c<p.length;c++)heap[p[c]]=o(p[c])};

Heap installation instructions: https://docs.heapanalytics.com/docs/installation


All of the HTML that Craft uses to render your site lives in your craft/templates folder.

In one of the files in that folder, you're presumably defining your <head></head> tags.

You'd want to find where that is and insert your JavaScript analytics tracking code before the closing head as per the Head Analytics installation docs.

Probably worth a read through the Craft does to familiarize yourself with Craft concepts as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.