> ## Documentation Index
> Fetch the complete documentation index at: https://loops.so/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# RudderStack

> Connect Loops to hundreds of apps to manage contacts and send emails.

<Info>
  Our RudderStack integration lets you:

  * Create and update contacts
  * Send events to trigger workflows
</Info>

## Configuring the destination

In RudderStack, go to [Destinations](https://app.rudderstack.com/destinations) and click **New destination**. Search for "Loops" and select it.

<img src="https://mintcdn.com/loops/W7EWSDUW0GR-XWrp/images/rudderstack-add.png?fit=max&auto=format&n=W7EWSDUW0GR-XWrp&q=85&s=2ca6bcb528520950b2a699349899c1d3" alt="Adding Loops in RudderStack" width="2280" height="1520" data-path="images/rudderstack-add.png" />

Select the source you want to connect Loops to.

On the next page you need to add a Loops API key. You can generate a new one on the [Loops API Settings page](https://app.loops.so/settings?page=api) and paste it into the **API Key** field.

<img src="https://mintcdn.com/loops/W7EWSDUW0GR-XWrp/images/rudderstack-configure.png?fit=max&auto=format&n=W7EWSDUW0GR-XWrp&q=85&s=ceb627402bd0b4c93a7a93c34f319ab1" alt="Configuring the destination" width="2280" height="1520" data-path="images/rudderstack-configure.png" />

Click **Continue** at the bottom of the page to finish the setup.

## Create or update a contact

To send contact data to Loops, use RudderStack's [`identify` call](https://www.rudderstack.com/docs/event-spec/standard-events/identify/).

Identify users with a unique user ID from your source. You can include contact properties in the traits object, like `firstName` and `lastName` in this example.

<Warning>
  For new contacts, make sure to include an email address, otherwise the call will fail. If the contact has already been sent to Loops with its user ID, you can omit the email address unless you want to update that value. In general, we recommend to always include an email address.
</Warning>

```javascript theme={"dark"}
rudderanalytics.identify(userId, {
  email: "test@example.com",
  firstName: "Adrian",
  lastName: "Brown"
});
```

To manage [mailing list](/contacts/mailing-lists) subscriptions, add a `mailingLists` object to the traits object. The key is the ID of the mailing list and the value is a boolean indicating whether the contact should be subscribed or unsubscribed.

```javascript theme={"dark"}
rudderanalytics.identify(userId, {
  email: "test@example.com",
  firstName: "Adrian",
  lastName: "Brown",
  mailingLists: {
    cly2xnjqn002z0mmn68uog1wk: true,
  },
});
```

## Send an event

You can trigger emails from RudderStack by triggering [events](/events) via [`track` calls](https://www.rudderstack.com/docs/event-spec/standard-events/track/).

You should add and define your events in [Settings -> Events](https://app.loops.so/settings?page=events) including any expected [event properties](/events/properties).

The event name in your `track` call must match the name of the event in Loops. Data sent in the properties object will be sent as event properties to Loops, for use in your emails.

<Warning>
  Make sure to call `identify` before `track` so the event is associated with a specific contact.
</Warning>

```javascript theme={"dark"}
rudderanalytics.track("newUser", {
  plan: "Pro Annual",
  accountType: "Facebook"
});
```

## Testing

### In RudderStack

RudderStack includes features to help you test your integration.

First of all you can see all `identify` and `track` calls coming in from your sources. Click on a source and select the **Events tab**.

<img src="https://mintcdn.com/loops/Z7viZoAUCPxaqCl2/images/rudderstack-source.png?fit=max&auto=format&n=Z7viZoAUCPxaqCl2&q=85&s=d40af9f050e9ee6e98bde724bcaa80e6" alt="Source events chart" width="2280" height="2547" data-path="images/rudderstack-source.png" />

Click on the **Live events** button in the top right to view details of events as they come in.

You can also see all of the calls being sent from RudderStack to your destinations. Click on a destination and then the **Events** tab. At the bottom of this page you will see a table showing events. Click on these to see any errors that have occurred when sending data to Loops.

<img src="https://mintcdn.com/loops/W7EWSDUW0GR-XWrp/images/rudderstack-destination.png?fit=max&auto=format&n=W7EWSDUW0GR-XWrp&q=85&s=db7e43f2bdf0c2920517e5df3644ecb8" alt="Destination events" width="2280" height="2154" data-path="images/rudderstack-destination.png" />

### In Loops

You can verify contact updates have happened in Loops from the [Audience page](https://app.loops.so/audience), and you can see all incoming events from the [Events page](https://app.loops.so/settings?page=events).

Click on individual events in the **Event Log** table to view the payload that Loops processed.

<img src="https://mintcdn.com/loops/aOtgyczWtTw7x5Xz/images/events-page.png?fit=max&auto=format&n=aOtgyczWtTw7x5Xz&q=85&s=c3466d116c399b364967953b56f25a0f" alt="Events page" width="2280" height="1520" data-path="images/events-page.png" />
