Skip to content

Insert HEAP Script into header

If you want to insert your HEAP analytics into your WordPress website then you want to read this blog.  This is simple and the code can either be inserted into the functions.php or your own plugin (Basic).

I assume you already signup for HEAP and ready to integrate it with your website. I create my own basic plugin for this but you can put it in your functions.php file. It really doesn’t matter, why I did it in a plugin is because I want to build the plugin into something more.

Please change the values “Your name” and “Your ID”.

You will find “Your ID” at the bottom of your script. After that, you are all set and ready to go. Activate the plugin or save functions.php file.

Plugin Name: Heap
Description: Insert heap Javascript into header.
Version: 1.0
Author: Your name

 if ( ! defined( 'ABSPATH' ) ) {
    header( 'Status: 403 Forbidden' );
    header( 'HTTP/1.1 403 Forbidden' );
function heap_script() { ?>
<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:")+"//"+e+".js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n);for(var o=function(e){return function(){heap.push([e].concat(,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 ID");
<?php }
add_action( 'wp_head', 'heap_script', 10 );


The Next Gen of Managed WordPress Service You deserve more than just a Hosting company! Hosting, Maintenance, Secure, Content updates and Cloud Backups

We are more than just a Hosting company!

AdminWP Host, Maintain (Site-care), Secure and Backup WordPress websites.