# Heap Destination

## Destination Info

* Accepts [Identify](/docs/segment/connections/spec/identify), [Track](/docs/segment/connections/spec/track) calls.
* Refer to it as **Heap** in the [Integrations object.](/docs/segment/guides/filtering-data/#filtering-with-the-integrations-object)

### Components

* [Browser](https://github.com/segment-integrations/analytics.js-integration-heap)
* Server

## Connection Modes

[Learn more about connection modes.](/docs/segment/connections/destinations/#connection-modes)

### Device-Mode

* web: yes
* mobile: no
* server: no

### Cloud-Mode

* web: yes
* mobile: yes
* server: yes

[Heap](https://heapanalytics.com/?utm_source=segmentio\&utm_medium=docs\&utm_campaign=partners) automatically captures every user interaction with no extra code. This includes clicks, taps, gestures, form submissions, page views, and more. The Heap Destination is open-source. You can browse the code [on GitHub](https://github.com/segment-integrations/analytics.js-integration-heap).

## Getting Started

1. From the Segment web app, click **Catalog**.
2. Search for "Heap" in the Catalog, select it, and choose which of your sources to connect the destination to.
3. In the destination settings, enter your Heap "App ID" into the connection settings.
4. Remove Heap's snippet from your page if you're using Segment's client-side Analytics.js library to load Heap. With the Analytics.js library, Segment asynchronously loads Heap's JavaScript library onto your page. All native functionality of Heap, including auto-capturing of all events, is available to you.

## Identify

If you're not familiar with the Segment Specs, take a look to understand what the [Identify method](/docs/segment/connections/spec/identify/) does. An example call would look like:

```javascript
analytics.identify('userId123');
```

When you call `identify`, Segment calls [Heap's identify method](https://developers.heap.io/docs/using-identify) with the `userId` and `traits` you provide.

If one of your `traits` is of the date property type, we will convert it into an ISO string.

## Track

If you're not familiar with the Segment Specs, take a look to understand what the [Track method](/docs/segment/connections/spec/track/) does. An example call would look like:

```javascript
analytics.track('Clicked Button');
```

When you call `track` from `analytics.js`, Segment calls Heap's [track function](https://developers.heap.io/reference/track) with the same parameters. Calling `track` from one of Segment's mobile SDKs or server-side sources records a [Heap Custom Event](https://docs.heapanalytics.com/reference#track-1) with the same event name and properties.

If one of your `properties` is of the date property type, we will convert it into an ISO string.

## Troubleshooting

### Anonymous traffic not showing up from server-side source

Ensure that you are specifying a `user_id` in your event calls. The Heap API will reject any server-side events without a `user_id`.

### Nested Objects and Arrays

Heap does not accept nested properties, so we will flatten and stringify them before sending to Heap. For example:

```javascript
analytics.track('Signed Up', {
  foo: {
    bar: {
      cheese: 'american',
      prop: [1, 2, 3],
      products: [{"A": "Jello"}, {"B": "Peanut"}]
    }
  }
});
```

The properties would be sent as:

```javascript
foo.bar.cheese: 'american'
foo.bar.prop: '[1,2,3]'
foo.bar.products: "[{'A': 'Jello'},{'B': 'Peanut'}]"
```

## Engage

You can send computed traits and audiences generated using [Engage](/docs/segment/engage) to this destination as a **user property**. To learn more about Engage, schedule a [demo](https://segment.com/contact/demo).

For user-property destinations, an [identify](/docs/segment/connections/spec/identify/) call is sent to the destination for each user being added and removed. The property name is the snake\_cased version of the audience name, with a true/false value to indicate membership. For example, when a user first completes an order in the last 30 days, Engage sends an Identify call with the property `order_completed_last_30days: true`. When the user no longer satisfies this condition (for example, it's been more than 30 days since their last order), Engage sets that value to `false`.

When you first create an audience, Engage sends an Identify call for every user in that audience. Later audience syncs only send updates for users whose membership has changed since the last sync.

> \[!NOTE]
>
> Real-time audience syncs to Heap  may take six or more hours for the initial sync to complete. Upon completion, a sync frequency of two to three hours is expected.

## Settings

Segment lets you change these destination settings from the Segment app without having to touch any code.

| Field  | Description                                                                                                                                                                             | Required | Type   |
| ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------ |
| App ID | You can find the snippet containing your app ID in Heap's \[QuickStart docs]\(https://heapanalytics.com/docs#quickstart). It's inside the \`heap.load('YOUR\_APP\_ID')\` function call. | Yes      | string |
