Created
February 21, 2018 00:58
-
-
Save heff/c8ef25d2ece3ac0d8ef2d78bf23b4f12 to your computer and use it in GitHub Desktop.
Adding/Integrating Heap Analytics in GatsbyJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implement Gatsby's Browser APIs in this file. | |
* | |
* See: https://www.gatsbyjs.org/docs/browser-apis/ | |
*/ | |
// You can delete this file if you're not using it | |
// This is how we've implemented it on Mux.com. Open to other suggestions. | |
exports.onClientEntry = () => { | |
if (process.env.NODE_ENV === 'production') { | |
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_HEAP_KEY"); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment