# mParticle

Automatically extract customer information from conversations and send it to mParticle as user profiles and events. Optionally fetch existing mParticle user data to personalize AI responses.

## Prerequisites

* An mParticle account
* mParticle OAuth credentials (Client ID and Client Secret)

## Getting Your Credentials

**OAuth Credentials (required):**

1. In mParticle, go to **Settings > Credential Management**
2. Create OAuth credentials and copy the **Client ID** and **Client Secret**

**Platform API Credentials (for lead syncing):**

1. In mParticle, go to **Setup > Inputs**
2. Create or select a Custom Feed input
3. Copy the **API Key** and **API Secret**

See [mParticle's documentation](https://docs.mparticle.com/developers/credential-management/) for detailed instructions.

## Setup

### Step 1: Connect mParticle

1. In Alhena, go to **Settings > Integrations**
2. Find **mParticle** and click **Enable**
3. Enter your **Client ID** and **Client Secret**
4. Click **Connect**

### Step 2: Add Platform API Credentials (for lead syncing)

To sync extracted leads to mParticle, add your Platform API credentials:

1. Click **Show advanced options**
2. Enter your **API Key** and **API Secret**
3. Select your **Region** (us1, us2, or eu1)
4. Click **Connect** again to save

Without these credentials, Alhena can extract lead attributes from conversations but won't sync them to mParticle.

### Step 3: Configure Attributes to Extract

Define what information to extract from conversations and send to mParticle:

1. Click **Add attribute**
2. Enter the **Attribute name** (the mParticle user attribute key, e.g., `email`, `$FirstName`, `company_size`)
3. Add a **Description** to help the AI identify this information in conversations
4. Optionally add **Examples** of values (up to 4)

Default attributes (pre-configured):

* `email` - User's email address
* `$FirstName` - User's first name
* `$LastName` - User's last name

When a conversation ends, Alhena uses AI to extract these attributes from the chat and sends them to mParticle as a `lead_generated` event.

***

## User Profile Personalization (Optional)

Fetch existing user data from mParticle to personalize AI responses.

### Requirements

To enable personalization, you need:

1. **Org ID**, **Account ID**, and **Workspace ID** from mParticle
2. The user's **MPID** passed via the Alhena SDK

### Setup

1. In the mParticle settings, click **Show advanced options**
2. Enter your **Org ID**, **Account ID**, and **Workspace ID**
3. Under **User Attributes to Fetch**, add the mParticle attributes you want to use for personalization (e.g., `$FirstName`, `loyalty_tier`, `favorite_category`)

### Passing MPID via SDK

Include the user's mParticle ID in your widget configuration:

```html
<script>
document.gleenConfig = {
    company: 'your-company-key',
    apiBaseUrl: 'https://app.alhena.ai',
    userMetadata: {
        mpid: '1234567890'  // User's mParticle ID
    }
};
</script>
```

When an MPID is provided, Alhena fetches the configured user attributes from mParticle and includes them in the AI's context for personalized responses.

***

## Enabled Agents

When you connect mParticle, lead capture is enabled for the lead generation agent:

| Agent                     | Description                                                                   |
| ------------------------- | ----------------------------------------------------------------------------- |
| **Lead generation agent** | Extracts configured attributes from conversations and syncs them to mParticle |

You can configure this agent in **AI Settings > Agents**.

***

## Credential Reference

| Credential                       | Purpose                                             |
| -------------------------------- | --------------------------------------------------- |
| **Client ID / Secret**           | OAuth authentication (required to connect)          |
| **API Key / Secret**             | Lead syncing via Events API and user identification |
| **Org / Account / Workspace ID** | Fetching user profiles for personalization          |
| **Region**                       | Your mParticle data region for Events API           |

***

## Disconnecting

To disconnect mParticle:

1. Go to **Settings > Integrations > mParticle**
2. Click **Disconnect**
3. Confirm the disconnection


---

# 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://alhena.gitbook.io/docs/integrations/marketing/integrating-mparticle-with-alhena-ai.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.
