Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion fern/products/docs/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ navigation:
path: ./pages/integrations/analytics/segment.mdx
- page: Mixpanel
path: ./pages/integrations/analytics/mixpanel.mdx
- page: Heap
path: ./pages/integrations/analytics/heap.mdx
- section: Support
contents:
- page: Intercom
Expand All @@ -224,4 +226,4 @@ navigation:
path: ./pages/developer-tools/view-markdown.mdx
- changelog: ./pages/changelog
icon: fa-regular fa-clock-rotate-left


63 changes: 63 additions & 0 deletions fern/products/docs/pages/integrations/analytics/heap.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a card for this page to the overview? https://buildwithfern.com/learn/docs/integrations/overview

Also, is the part in the overview about adding environment variables to docs.yml relevant to Heap? If so, I would explicitly show that on the Heap page.

title: Heap
description: >-
Learn how to integrate Fern Docs with Heap to track user behavior and
analytics.
---

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest adding a brief sentence or two that describes the use case i.e. why someone would want to add Heap to Fern Docs. The description in the frontmatter is a good start (though that's not visible directly on the page), but I'd want the intro to be slightly more specific.

## Add Heap to your Docs

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.

### Get your Heap Environment ID

1. Log in to your Heap account.
2. Navigate to the project you want to track.
3. Go to **Install Heap** > **Web Installation**.
4. Copy your **Environment ID** from the installation snippet (it will look like a numeric ID such as `123456789`).

### Integration Steps

1. **Create a scripts folder**: Under your `fern` directory, create a `scripts` folder if it doesn't already exist.

2. **Create the Heap script**: In the `scripts` folder, create a file named `heap.js`.

3. **Add the Heap tracking code**: In your `heap.js` file, add the following script (replace `YOUR_ENVIRONMENT_ID` with your actual environment ID):

<CodeBlock title="fern/scripts/heap.js">
```js
// Heap Analytics Integration
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])};

// Initialize Heap with your environment ID
heap.load("YOUR_ENVIRONMENT_ID");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extreme nit, but the Mixpanel doc uses single quotes for a placeholder text like this ('YOUR_PROJECT_TOKEN'). I actually think the double quotes is more readable but either way probably good to be consistent!

```
</CodeBlock>

4. **Configure your docs.yml**: In your `docs.yml` file, add the JavaScript file configuration:

<CodeBlock title="docs.yml">
```yaml
js:
- path: ./scripts/heap.js
strategy: beforeInteractive
```
</CodeBlock>

### Security Considerations

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.

### Testing Your Integration

1. **Start your development server**: Run `fern docs dev` to build and start your Fern docs locally (typically on `http://localhost:3000`).

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.

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.

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.

### Additional Resources

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.