# Mixpanel Reference

## Destination Info

* Accepts [Track](https://documentation.freshpaint.io/developer/freshpaint-sdk-reference#track), [Group](https://documentation.freshpaint.io/developer/freshpaint-sdk-reference#group), and [Identify](https://documentation.freshpaint.io/developer/freshpaint-sdk-reference#identify) calls
* Supports [HIPAA mode](https://documentation.freshpaint.io/hipaa-mode)
* Connection Modes:

<table><thead><tr><th align="right"> </th><th data-type="checkbox">Client-side</th><th data-type="checkbox">Server-side</th></tr></thead><tbody><tr><td align="right">Web</td><td>true</td><td>true</td></tr><tr><td align="right">Mobile</td><td>false</td><td>true</td></tr><tr><td align="right">Server</td><td>false</td><td>true</td></tr></tbody></table>

## Identify

It is important to first [identify ](https://documentation.freshpaint.io/developer/freshpaint-sdk-reference#identify)your users so Mixpanel knows who they are and associates events to their user record in Mixpanel:

<figure><img src="/files/2WIkMEYMIND7IeVd2v8A" alt=""><figcaption></figcaption></figure>

Here is an example of an identify call:

```javascript
freshpaint.identify("ada.lovelace@example.com", {
    /* user properties */
    "email": "ada.lovelace@example.com",
    "name": "Ada Lovelace",
    "role": "mathematician",
    "specialty": "computer languages"
});
```

{% hint style="warning" %}
freshpaint.identify is not identical to the "[Identify](https://docs.mixpanel.com/docs/tracking-methods/id-management/identifying-users)" event in Mixpanel. This call will always update profile values provided to it, but an Identify event will only show up in Mixpanel if the Mixpanel project is set to use the Original ID Merge API and the call includes a device\_id and user\_id to associate with each other.

If you care about independently tracking the action that triggers an identify call, it is highly recommended that you send a freshpaint.track call for this purpose and not rely exclusively on the identify call to be visible in Mixpanel.
{% endhint %}

### Client-Side Connection Mode

When you call [freshpaint.identify](https://documentation.freshpaint.io/developer/freshpaint-sdk-reference#identify), Freshpaint will create or update a user profile in Mixpanel by calling Mixpanel's [identify method](https://developer.mixpanel.com/docs/javascript-full-api-reference#mixpanelidentify). Any user properties you pass in will be forwarded directly to Mixpanel.

{% hint style="info" %}
By default, any properties set in an Identify call will be passed on as Super Properties in the Mixpanel cookie and in subsequent event properties while using **client-side connection mode**.
{% endhint %}

In client-side connection mode, you may want to enable the Use Freshpaint ID for Device ID option in order to make the Mixpanel javascript web SDK use the Freshpaint device ID. This improves data consistency. You can read more about that [here](https://documentation.freshpaint.io/destinations/apps/mixpanel#use-freshpaint-id-for-device-id).

When the Merge Anonymous option is enabled, Freshpaint will send a server-side identify call to Mixpanel using their [Create Identify](https://developer.mixpanel.com/reference/create-identity) endpoint. To set an anonymous id with an identify call, you can specify a value for the [`$device_id`](https://documentation.freshpaint.io/developer/http-api#server-side-identify) property.

### Server-Side Connection Mode

When you call [freshpaint.identify](https://documentation.freshpaint.io/developer/freshpaint-sdk-reference#identify), Freshpaint will create or update a user profile in Mixpanel by sending a call to [Mixpanel's identity endpoint](https://developer.mixpanel.com/reference/create-identity) at: <https://api.mixpanel.com/track#create-identity>. To set an anonymous id with an identify call, you can specify a value for the [`$device_id`](https://documentation.freshpaint.io/developer/http-api#server-side-identify) property.

## Events

### Seeing Freshpaint Events in Mixpanel

Once the Mixpanel integration is enabled, you can now set it as an event destination:

![](/files/IIpGgma4xRdEnxo4PBPV)

Events sent from Freshpaint to Mixpanel will show up as standard Mixpanel events. From there you can use your events in any of the Mixpanel reports. You can view them by navigating to Events and looking at recent events, or by searching for a specific event.

<figure><img src="/files/M7M1qGz4yrhSMA0kHu7N" alt=""><figcaption></figcaption></figure>

### UTM Parameters

As Freshpaint's client-side javascript library loads Mixpanel's javascript library in the background, any UTM parameters captured as built-in event properties are passed into Mixpanel as UTM properties.

![](/files/lpbpVj2oGsJlmzeM67pe)

When using server-side connection mode, UTM parameters will need to be explicitly passed in as an event property, for example:

```javascript
freshpaint.track("Test Event", {
    "UTM Campaign": "testing",
    "UTM Source": "testing",
    "UTM Medium": "web",
    "UTM Term": "testing",
    "UTM Content": "testing"
});
```

## Configuration Options

### Group Analytics

If you plan on using Mixpanel's [Group Analytics](https://help.mixpanel.com/hc/en-us/articles/360025333632-Group-Analytics) feature, you should set up a group key in Mixpanel by clicking *Add Group Key* and entering in the name of the property you want to use (e.g. *company\_name*). Then, copy the name of the group key you are using into Freshpaint as the *Group Identifier Trait*.

![](/files/MZbhQybkyUbaYSTBN0ho)

[Learn more](https://documentation.freshpaint.io/destinations/apps/mixpanel#group-analytics) about setting Group profiles using the `freshpaint.group()` method.

### Cross-Subdomain Cookie

Enable this option if your application has multiple subdomains and you want the Mixpanel cookie to persist across those subdomains. This allows the user to be tracked across subdomains. This setting is not enabled by default.

### Use Local Storage

Use Local Storage instead of a Cookie to persist Mixpanel SDK state. Local Storage can support more User Property data than a cookie. This setting is not enabled by default.

{% hint style="warning" %}
Please note that users cannot be tracked across Subdomains when using Local Storage.
{% endhint %}

### Enable EU Endpoint

When enabled, Freshpaint will send your events to Mixpanel's [EU endpoint](https://developer.mixpanel.com/docs/implement-mixpanel#section-implementing-mixpanel-in-the-european-union-eu). In Mixpanel, be sure to enable Data Residency under **Project Settings** > **Data Residency.** Make sure you've followed [Mixpanel's help article](https://help.mixpanel.com/hc/en-us/articles/360039135652-Data-Residency-in-EU) to set up EU data. This setting is not enabled by default.

### Secure Cookie

Enabling this option will utilize a secure cookie that will only be transmitted over HTTPS. This setting is not enabled by default.

### Consolidate Page Calls

This will send a **Loaded a Page** event to Mixpanel for all [`page()`](https://documentation.freshpaint.io/developer/freshpaint-sdk-reference#page) method calls. The Page call is transformed to Mixpanel events. This setting is not enabled by default.

{% hint style="info" %}
This option only applies to Freshpaint's client-side SDKs and do not affect events originating from other sources such as React Native, Android, iOS, or when server-side connection mode is enabled.
{% endhint %}

### Ignore DNT

When enabled, Mixpanel will track all events, regardless of if the browser has "Do Not Track" enabled. [Learn More About DNT](https://www.eff.org/issues/do-not-track) and how it relates to [GDPR](https://www.w3.org/blog/2018/06/do-not-track-and-the-gdpr/) and [CCPA](https://www.oag.ca.gov/system/files/attachments/press_releases/CCPA%20Fact%20Sheet%20\(00000002\).pdf) policies. This setting is enabled by default.

### Merge Anonymous

This setting merges anonymous users with identified users when a [server-side identify call](https://documentation.freshpaint.io/developer/http-api#server-side-identify) is performed. This setting is enabled by default.

### Use Freshpaint ID for Device ID

Enable this setting to make the Mixpanel javascript web SDK use the Freshpaint device ID. This improves data consistency - you'll see the same device id for data streamed from your customers' web browsers as for data backfilled from Freshpaint's servers. This setting is not enabled by default.

{% hint style="warning" %}
Changing this setting for an existing project will break historical data, so only enable this if you're setting up a new Mixpanel project.
{% endhint %}

### Enable Default Identify Transformations

Enable this setting to apply a default set of transformations from Freshpaint User Properties to Mixpanel Properties when making Identify call's.

| Freshpaint User Property | Mixpanel Property |
| ------------------------ | ----------------- |
| email                    | $email            |
| first\_name              | $first\_name      |
| last\_name               | $last\_name       |
| phone\_number            | $phone            |
| state                    | $region           |
| city                     | $city             |

{% hint style="warning" %}
Changing this setting will break historical data, so only enable this if you're setting up a new Mixpanel project.
{% endhint %}

### Event Transformations

Set up transformations to modify your data before it's sent to your destination. Read more about transformations [here](https://documentation.freshpaint.io/transformations).

<figure><img src="/files/aOKkpLvEjEmGXuzLhTCA" alt=""><figcaption></figcaption></figure>

### Connection Mode Settings

#### Client-Side Connection Mode

Events user's web browser will be sent directly to Mixpanel. Events from other sources, including mobile and server, will be sent first to Freshpaint's servers and then on to Mixpanel.

When available, geo-location data is appended to an identified user's record in Mixpanel.

#### Server-Side Connection Mode

All events will be sent to Mixpanel from Freshpaint's servers. Your website will not send data directly to Mixpanel. Instead, your website and all other sources will send data to Freshpaint, which is translated then sent to Mixpanel. As mentioned above, [sources](https://app.freshpaint.io/sources) such as React Native, Android, and iOS send data server-side.

By default, Freshpaint will provide the IP address of the browser to Mixpanel. You can also provide a custom IP address by providing a `$ip` property.

[Learn more](https://documentation.freshpaint.io/faqs/what-is-the-difference-between-client-side-and-server-side-connection-mode#which-one-should-i-choose) about which connection mode to choose.

## Geo Information

Geo location information is derived from the IP address of the original agent, the web SDK, or embedded SDK. That IP address is then passed through to Mixpanel where it is resolved to a geo location.

## Group Analytics

When you call [freshpaint.group](https://documentation.freshpaint.io/developer/freshpaint-sdk-reference#group), Freshpaint will create or update a group profile in Mixpanel. Unlike other destinations, Mixpanel supports multiple group keys. That means one user can belong to multiple groups and the group a user is counted towards changes depending on which group key you are using. As an example, for the `company_name` group key, a user could belong to the group `Google`, while at the same time for the `department_name` group key, the user belongs to `Software Engineering`. Due to Mixpanel's support of multiple groups per user, there are some slight differences when using Mixpanel group compared to other destinations.

Before using Mixpanel Group Analytics, you will need to configure the *Group Identifier Trait* in Freshpaint. The setting can be found in the configuration options for the Mixpanel integration.

![](/files/gwiz4kNuhMOtXkqv1FmP)

The *Group Identifier Trait* is the name of the group key you want to use. When calling `freshpaint.group` you will need to pass in the group key and the corresponding group id as group properties. As an example, if you are using *company\_name* as your *Group Identifier Trait*, you'll want to call `freshpaint.group` like so:

```javascript
freshpaint.group("Google", {
    "company_name": "Google"
});
```

Additionally, for events to be attributed to the right group, you'll need to pass in the group key as an event property with the group id as the value. This can be done by using [freshpaint.addEventProperties](https://documentation.freshpaint.io/developer/freshpaint-sdk-reference#addeventproperties). For this reason, we recommend after calling `freshpaint.group`, you also make a call to `freshpaint.addEventProperties` with the group key and group id like so:

```javascript
freshpaint.addEventProperties({
    "company_name": "Google",
    "department_name": "Software Engineering"
});
```

This will automatically attach the group key and group id to all events going forward.

## Mixpanel Sessions

In Freshpaint, sessions are terminated after 30 minutes of inactivity by default. You can read more about that [here](https://documentation.freshpaint.io/faqs/how-does-freshpaint-determine-session-count).&#x20;

There are a variety of ways sessions can be defined in Mixpanel. By default, Mixpanel will create events at query time based on how far apart events are for a specific user. This can sometimes lead to discrepancies between Freshpaint's data and Mixpanel's data.  For example, if a user has two sessions according to Freshpaint, and an event is triggered and sent to Mixpanel in between those two sessions, this could be counted in Mixpanel as one session.

Another example of a discrepancy is if a user changes multiple devices around the same time, this would be counted as multiple sessions in Freshpaint, while it would only be counted as one in Mixpanel.

There are multiple ways you can define sessions in Mixpanel. Since Mixpanel and Freshpaint define sessions differently, session count will not always match between the two tools. You can read more about how you can define sessions in Mixpanel [here](https://help.mixpanel.com/hc/en-us/articles/115004695223-Sessions#event-based-sessions) and decide which method works best for your use cases.&#x20;

If you have any questions on which method is right for you, you can reach out to us at <support@freshpaint.io>.&#x20;

## Deduplication in Mixpanel

Mixpanel considers events with the same `event, time, distinct_id, and $insert_id` to be duplicates. Mixpanel will deduplicate based on these parameters. You can read more about that [here](https://developer.mixpanel.com/docs/data-structure-deep-dive) in Mixpanel's documentation.&#x20;

For most events, Freshpaint sends each of these parameters to Mixpanel in order for deduplication to occur. If you are sending [SQL scheduled events](https://documentation.freshpaint.io/events/sql-scheduled-event-definitions) to Mixpanel, you would have to make sure these parameters were included in the event prior to sending to Mixpanel in order for deduplication to occur.

If you are sending data to Mixpanel with a [backfill](https://documentation.freshpaint.io/readme/guides/time-machine), Freshpaint will send a `fp_backfill_id` property with each event that can also be used for deduplication. If for some reason the data is duplicated during a backfill, the duplicated events can be ignored by filtering out this `fp_backfill_id` value.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.freshpaint.io/integrations/destinations/apps/mixpanel/mixpanel-reference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
