# Use event data with mParticle

> mParticle allows you to capture event data and use an event output to send the data to Talon.One in close to real time.

> For the complete documentation index, see [llms.txt](https://docs.talon.one/llms.txt).

For example, if customers click a button on your website, you can collect the event data
using mParticle, and forward it to Talon.One.

Then, in Talon.One, you can create coupon codes to offer everyone who clicked the button
a discount for their next purchase.

:::important
In this tutorial, we assume you are using mParticle's original UI. To enable it, sign in to mParticle and click **Settings** > **Go to Classic Experience**.
:::

## Talon.One requirements

- You are an [admin](/docs/product/account/account-settings/manage-roles.md#admin-role) user.
- You have an [Application](/docs/product/applications/create-and-manage-applications.md) set up.
- Your Application contains a running [campaign](/docs/product/campaigns/create-and-manage-campaigns.md) with the **Coupons** feature
  [enabled](/docs/product/campaigns/settings/manage-campaign-features.md).
- You have created an
  [mParticle-specific API key](/docs/product/applications/manage-third-party-api-keys.md).

## mParticle requirements

- You are an [admin](/docs/product/account/account-settings/manage-roles.md#admin-role) user.

## Set up the integration

<StepsContainer>

### Create the feed input

[Feed inputs](https://docs.mparticle.com/guides/get-started/create-an-input/) allow you
to send data to mParticle. In this tutorial, we'll use a custom feed input to send the click
event data from your website to mParticle.

:::note
You can also use a [Talon.One feed input](mparticle-enable-integration.md#set-up-a-feed-input) for this.
However, because we're not sending data from Talon.One, a custom feed is more appropriate.
:::

To create the feed input:

1. In mParticle, open **Setup** > **Inputs** and switch to the **Feeds** page.
1. If there's a **Custom Feed** section with existing feeds, open it and click **+**. Otherwise, click **Add Feed Input** and select **Custom Feed**.
1. In the **Input: Feed Configuration** window, configure the following parameters:
   - **Configuration Name**: Type a configuration name.
   - **Feed Status**: Select **Active**.
   - **Input Protection Level**: Select **Create & Update Profiles**.
1. Click **Save**.
1. Save the **Server to Server Key** and **Server to Server Secret** values for later use. We'll need them for [testing](#test-the-connection).

### Create the event output

With an [event output](https://docs.mparticle.com/guides/get-started/connect-an-event-output/), you can send data from mParticle to Talon.One.
In this tutorial, we'll use an event output to forward the click event data.

To create the event output:

1. In mParticle, open **Setup** > **Outputs**.
1. If there's a **Talon.One Default Group** section with existing outputs, open it and click **+**. Otherwise, click **Add Event Output** and select **Talon.One**.
1. In the **Output: Event Configuration** window, configure the following parameters:
   - **Configuration Name**: Type a configuration name.
   - **Use same settings for Development & Production**: Select this option.
   - **API Key**: Paste the API key you [created](#talonone-requirements).
   - **Deployment URL**: Type the base URL of your Talon.One deployment, for example, `mycompany.europe-west1.talon.one`.
   - **User ID**: Select the user identity to map with Talon.One as the customer's user ID. In this tutorial, we'll use **Customer ID**.
   - **Run Rule Engine**: Select this option.
1. Click **Save**.

### Create the connection

Let's connect the feed input and event output, so that the click event data flows from your website via mParticle to Talon.One.

To create the connection:

1. In mParticle, open **Connections** > **Connect**.
1. Click the custom feed input you [created](#create-the-feed-input).
1. Click **Connect Output**.
1. In the **Connect Output** window, select the event output you [created](#create-the-event-output).
1. Set **Connection Status** to **Active**.
1. Click **Add Connection**.

### Enable data forwarding

After creating the connection, mParticle's [Data Filter](https://docs.mparticle.com/guides/platform-guide/data-filter/) feature may prevent data from being forwarded.

To enable data forwarding:

1. In mParticle, open **Connections** > **Feed Filters**.
1. At the top of the page, select the feed input you [created](#create-the-feed-input).
1. Select the [**Send new data points by default**](https://docs.mparticle.com/guides/platform-guide/data-filter/#new-data-points) checkbox.
1. Enable all data points:
   1. On the **Events** page, in the **Events Data Type Filter** section, click **...** > **Turn ON all data points**.
   1. On the **Users** page, in the **Users Data Type Filter** section, click **...** > **Turn ON all data points**.
1. Click **Save**.

:::info
It takes a few minutes for the changes to take effect.
:::

### Build the rule in Talon.One

To act on events sent via mParticle, create a [rule](/docs/product/rules/overview.md) in your Talon.One [campaign](/docs/product/campaigns/overview.md) with the following logic:

| What           | Name                                               | Properties                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| -------------- | -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Conditions** | Check for event typesand custom event values | Event type: <code>mparticle_event</code>If the event type does not exist, see [Troubleshooting](#troubleshooting).<Attribute name="mparticle_event (Event)" type="custom" /> is equal to <code>YOUR_EVENT_NAME</code>,where <code>YOUR_EVENT_NAME</code> is equal to the value of `event_name` in your [requests](#test-the-connection).In this tutorial, we use <code>click_event</code>. |
| **Effects**    | Create coupon code                                 | Set your desired coupon settings.                                                                                                                                                                                                                                                                                                                                                                                                                                            |

When Talon.One receives an event with the given name, the rule is triggered, and a coupon code is created.

</StepsContainer>

## Test the connection

Let's test our setup using the [Events API](https://docs.mparticle.com/developers/apis/http/) provided by mParticle.

To test the connection:

1. Use curl or a similar tool to send the following request, where:
   - `FEED_INPUT_KEY` and `FEED_INPUT_SECRET` are the key and secret values of the feed input you [created](#create-the-feed-input).
   - `YOUR_CUSTOMER_ID` is a customer ID of your choice, for example, `John Doe`.

   ```js
   curl --location 'https://s2s.mparticle.com/v2/events' --user 'FEED_INPUT_KEY:FEED_INPUT_SECRET' --header 'Content-Type: application/json' --data '{
     "schema_version": 2,
     "environment": "development",
     "user_identities": {
       "customer_id": "YOUR_CUSTOMER_ID"
     },
     "events": [
       {
         "data": {
           "event_name": "click_event",
           "custom_event_type": "other"
         },
         "event_type": "custom_event"
       }
     ]
   }'
   ```

   :::note
   This request is for testing purposes only. You should [customize it for your actual setup](https://docs.mparticle.com/developers/apis/http/#upload-event-data).
   :::

1. In mParticle, open **Data Master** > **Live Stream** and check whether mParticle has received the request.
1. In **Live Stream**, set **Message Direction** to **Outbound** and check whether mParticle has forwarded the request.
1. In Talon.One:
   1. Open your Application, click <Events className="icon"/> **Events**, and check whether an `mparticle_event` event has been received.
   1. Open your campaign, click <Coupons className="icon"/> **Coupons**, and check whether a coupon has been generated for the given customer ID.

## Troubleshooting

When you [build a rule](#build-the-rule-in-talonone), if the `mparticle_event`
event type does not yet exist, send the following test request to Talon.One, where:

- `YOUR_API_KEY` is the API key you [created](#talonone-requirements).
- `YOUR_DEPLOYMENT_URL` is the base URL of your Talon.One deployment.

```js
curl --location 'https://integration.talon.one/mparticle' --header 'Content-Type: application/json' --data '{
  "type": "event_processing_request",
  "account": {
    "account_settings": {
      "apiKey": "YOUR_API_KEY",
      "deploymentURL": "YOUR_DEPLOYMENT_URL",
      "userIdField": "mpid"
    }
  },
  "events": [
    {
      "type": "custom_event",
      "name": "test_event"
    }
  ],
  "mpid": "12345"
}'
```
