Search code examples
javascripthtmlreactjsheap-analytics

Adding Heap Analytics code in React Project


I am trying to add heap analytics script in my react project but it keeps throwing this error "'heap' is not defined". And I cannot compile the project due to this error.

As far as I know, heap wants their code to run in <head></head> tags. But I can't figure out how to make a code run inside <head></head> in react. The rest of the scripts like GTM and FB pixel code is running fine.

Any help is appreciated.


Solution

  • You should be able to include the heap script under head tag as below (Set right path to script in place of yourHeapScriptPath)

    <script type="text/javascript" src="yourHeapScriptPath.js"></script>