# Loops

[Loops](https://loops.so) is an email platform for SaaS companies for sending marketing and transactional emails from the same platform.

{{< info >}}
This integration is built by the Loops team. [Contact the Loops support team](mailto:help@loops.so) for any assistance.
{{< /info >}}

Find the open source transformer code for this destination in the [GitHub repository](https://github.com/rudderlabs/rudder-transformer/tree/develop/src/cdk/v2/destinations/loops).

## Connection compatibility

{{< destination-config >}}

## Get started

Once you have confirmed that the platform supports sending events to Loops, follow these steps:

1. From your [RudderStack dashboard](https://app.rudderstack.com/), add the source. Then, from the list of destinations, select **Loops**.
2. Assign a name to your destination and click **Continue**.

### Connection settings

| Setting | Description |
|---------|-------------|
| API Key | Specify your [Loops API key](#faq). |

## Identify

You can use the [`identify`]({{< ref "event-spec/standard-events/identify.md" >}}) event to create or update contacts in Loops.

A sample `identify` call is as shown:

```javascript
rudderanalytics.identify("1hKOmRA4GRlmr123", {
  email: "alex@example.com", // Required for new contacts
  name: "Alex Keener",
  country: "United States",
})
```

Make sure to pass the unique user identifier as the first parameter in your `identify` call. 

Note that: 

- `email` is a **required** field for adding new contacts in Loops.
- The existing contacts are updated in Loops based on the provided `userId` property. If an existing contact in Loops doesn't have a `userId`, Loops attempts to match based on the provided `email`. 
- The `identify` traits are automatically added to the contact record as properties.

### Manage mailing list subscriptions

To manage a contact's mailing list subscriptions, add a `mailingLists` property to match the expected [API format](https://loops.so/docs/api-reference/update-contact#param-mailing-lists):

```javascript
rudderanalytics.identify("1hKOmRA4GRlmr123", {
  email: "alex@example.com",
  name: "Alex Keener",
  country: "United States",
  mailingLists: {
    clxf1nxlb000t0ml79ajwcsj0: true,
    clxf2q43u00010mlh12q9ggx1: false
  },
})
```

In the above example, the contact with the identifier `1hKOmRA4GRlmr123` is added to the mailing list with the ID `clxf1nxlb000t0ml79ajwcsj0` and unsubscribed from the mailing list with the ID `clxf2q43u00010mlh12q9ggx1`.

## Track

You can use the [`track`]({{< ref "event-spec/standard-events/track.md" >}}) event to send user actions to Loops, which in turn are used to trigger [loops](https://loops.so/docs/loop-builder).

The event name should match the name of the event in Loops. Data sent in the `properties` object will be sent as [event properties](https://loops.so/docs/events/properties) to Loops, for use in your emails.

Create events and define their expected properties in [Settings > Events](https://app.loops.so/settings?page=events) in your Loops dashboard.

A sample `track` call sent to Loops is shown below:

```javascript
rudderanalytics.track("Signup", {
  firstName: "Alex",
  email: "alex@example.com",
  plan: "Pro"
})
```

Note that:

- You should identify the contact before sending a `track` event so that the event can be associated with a specific contact in Loops.
- RudderStack persists any values in `context.traits` from your previous `identify` call in the `track` event properties and updates the contact record in Loops accordingly.

## FAQ

#### Where can I find the Loops API key?

1. Go to your [Loops API Settings page](https://app.loops.so/settings?page=api).
2. Generate or use an existing API key.
3. Copy the key and paste it in the **API Key** field in the RudderStack dashboard.

<br />


