Wordpress Installation

This installation guide works only for sites hosted on wordpress.org or self-hosted WordPress sites. It does not work for sites hosted on wordpress.com.

To install Heap on a WordPress site, complete the steps below.

  1. Login to your WordPress Admin console (generally at /wp-admin on your WordPress site).

  2. Navigate to the Theme Editor

606606
  1. Locate the header.php file
420420
  1. Paste the following code snippet before the line of code that says </head>:
<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.load("YOUR_APP_ID");
</script>

Note that your Heap installation may be affected if you edit a WordPress theme. To avoid this, you should create a child theme and make your changes there. For more tips and best practices for customizing WordPress, see their documentation on customizing a theme.

📘

When using the snippet above, remember to replace YOUR_APP_ID with the ID of the environment to which you want to send data. You can find this ID on the Account > Manage > Projects page.

  1. It should look something like this:
876876

That’s it! You’re ready to begin using Heap with WordPress.