|
| 1 | +--- |
| 2 | +title: Heap |
| 3 | +description: >- |
| 4 | + Learn how to integrate Fern Docs with Heap to track user behavior and |
| 5 | + analytics. |
| 6 | +--- |
| 7 | + |
| 8 | +## Add Heap to your Docs |
| 9 | + |
| 10 | +To add Heap to your Docs, you need to create a custom JavaScript file and configure it in your `docs.yml` file using your Heap environment ID. |
| 11 | + |
| 12 | +### Get your Heap Environment ID |
| 13 | + |
| 14 | +1. Log in to your Heap account. |
| 15 | +2. Navigate to the project you want to track. |
| 16 | +3. Go to **Install Heap** > **Web Installation**. |
| 17 | +4. Copy your **Environment ID** from the installation snippet (it will look like a numeric ID such as `358239876`). |
| 18 | + |
| 19 | +### Integration Steps |
| 20 | + |
| 21 | +1. **Create a scripts folder**: Under your `fern` directory, create a `scripts` folder if it doesn't already exist. |
| 22 | + |
| 23 | +2. **Create the Heap script**: In the `scripts` folder, create a file named `heap.js`. |
| 24 | + |
| 25 | +3. **Add the Heap tracking code**: In your `heap.js` file, add the following script (replace `YOUR_ENVIRONMENT_ID` with your actual environment ID): |
| 26 | + |
| 27 | +<CodeBlock title="fern/scripts/heap.js"> |
| 28 | +```js |
| 29 | +// Heap Analytics Integration |
| 30 | +window.heapReadyCb=window.heapReadyCb||[],window.heap=window.heap||[],heap.load=function(e,t){window.heap.envId=e,window.heap.clientConfig=t=t||{},window.heap.clientConfig.shouldFetchServerConfig=!1;var a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src="https://cdn.us.heap-api.com/config/"+e+"/heap_config.js";var r=document.getElementsByTagName("script")[0];r.parentNode.insertBefore(a,r);var n=["init","startTracking","stopTracking","track","resetIdentity","identify","getSessionId","getUserId","getIdentity","addUserProperties","addEventProperties","removeEventProperty","clearEventProperties","addAccountProperties","addAdapter","addTransformer","addTransformerFn","onReady","addPageviewProperties","removePageviewProperty","clearPageviewProperties","trackPageview"],i=function(e){return function(){var t=Array.prototype.slice.call(arguments,0);window.heapReadyCb.push({name:e,fn:function(){heap[e]&&heap[e].apply(heap,t)}})}};for(var p=0;p<n.length;p++)heap[n[p]]=i(n[p])}; |
| 31 | + |
| 32 | +// Initialize Heap with your environment ID |
| 33 | +heap.load("YOUR_ENVIRONMENT_ID"); |
| 34 | +``` |
| 35 | +</CodeBlock> |
| 36 | + |
| 37 | +4. **Configure your docs.yml**: In your `docs.yml` file, add the JavaScript file configuration: |
| 38 | + |
| 39 | +<CodeBlock title="docs.yml"> |
| 40 | +```yaml |
| 41 | +js: |
| 42 | + - path: ./scripts/heap.js |
| 43 | + strategy: beforeInteractive |
| 44 | +``` |
| 45 | +</CodeBlock> |
| 46 | +
|
| 47 | +### Security Considerations |
| 48 | +
|
| 49 | +Since Heap tracking is implemented using client-side JavaScript, your environment ID will be visible in the browser's source code. This is normal and expected behavior for client-side analytics implementations. Heap environment IDs are designed to be publicly visible and are safe to expose on the client side. |
| 50 | +
|
| 51 | +### Testing Your Integration |
| 52 | +
|
| 53 | +1. **Start your development server**: Run `fern docs dev` to build and start your Fern docs locally (typically on `http://localhost:3000`). |
| 54 | + |
| 55 | +2. **Verify script loading**: Open your browser's developer tools and check the Console and Network tabs to confirm the Heap script is loading correctly. Look for successful requests to `heap-api.com`. |
| 56 | + |
| 57 | +3. **Test event tracking**: Navigate through your docs site and verify that events are being tracked. Heap automatically captures page views, clicks, and form interactions. |
| 58 | + |
| 59 | +4. **Check Heap dashboard**: Go to your Heap project dashboard to verify that events are being received correctly. The setup page should indicate when data is being received. |
| 60 | + |
| 61 | +### What Heap Automatically Tracks |
| 62 | + |
| 63 | +Once integrated, Heap will automatically capture: |
| 64 | + |
| 65 | +- **Page views**: Every page visit with full URL information |
| 66 | +- **Click events**: All button clicks, link clicks, and interactive elements |
| 67 | +- **Form interactions**: Form submissions and field changes |
| 68 | +- **Session data**: User sessions, return visits, and session duration |
| 69 | +- **User behavior**: Scroll depth, time on page, and navigation patterns |
| 70 | + |
| 71 | +### Additional Resources |
| 72 | + |
| 73 | +For more information on Heap's JavaScript SDK and advanced configuration options, visit the [Heap JavaScript SDK documentation](https://developers.heap.io/reference/web). You can also explore [Heap's getting started guide](https://help.heap.io/hc/en-us/categories/13662488537116-Getting-Started) for more comprehensive setup instructions. |
0 commit comments