# Bluecore

[Bluecore](https://www.bluecore.com/) is an AI-powered retail marketing platform that helps brands personalize their campaigns by analyzing customer data. It enables targeted email and messaging campaigns, aiming to enhance engagement, boost sales, and improve marketing efficiency.

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

## Setup

1. In your [RudderStack dashboard](https://app.rudderstack.com/), go to **Directory** > **Destinations** > **Cloud Destinations**  and search for **Bluecore**.
2. Connect your source and click **Continue**.

### Connection settings

Configure the following settings to set up Bluecore as a destination in RudderStack:

- **Name**: Assign a name to uniquely identify the destination.
- **Bluecore namespace**: Enter your [Bluecore token]({{< ref "#faq" >}}) from the Bluecore dashboard.

### Connection mode

{{< destination-config >}}

### Configuration settings

After completing the initial setup, configure the following settings to receive your data in Bluecore correctly:

- **Consent management settings**: Configure the consent management settings for the specified source by choosing the **Consent management provider** from the dropdown and entering the relevant consent category IDs. See [Consent Management in RudderStack]({{< ref "data-governance/consent-management/overview.md" >}}) for more information on this feature.

### Mappings

**Event mappings**: Click **Set-up mapping** to map the RudderStack events to [Bluecore standard ecommerce events](https://help.bluecore.com/en/articles/6786828-events-service#h_ead2fa8c16). RudderStack also provides the JSON mapper to set these mappings.

{{< image src="images/event-stream-destinations/bluecore-event-mapping.webp" alt="Bluecore event mapping" >}}

RudderStack maps the following events to the Bluecore standard ecommerce events by default:

| RudderStack event | Bluecore event | 
| :-----| :----| 
| Product Viewed  | `viewed_product` | 
| Products Searched  | `search` | 
| Product Added | `add_to_cart` | 
| Product Removed| `remove_from_cart` | 
| Product Added to WIshlist | `wishlist` | 
| Order Completed  | `purchase` | 

## Identify 

You can use the [`identify`]({{< ref "event-spec/standard-events/identify.md" >}}) call to create a new customer or link an email ID to an existing customer in Bluecore.

RudderStack sends this information to Bluecore by leveraging their [REST API endpoint](https://help.bluecore.com/en/articles/6786828-events-service#h_188a59bb5b).

A sample `identify` call to create a new customer in Bluecore:

```javascript
rudderanalytics.identify("27340af5c8819", {
  firstName: "Alex Keener",
  logins: 2
})
```

You can [link an email ID with an existing customer](https://help.bluecore.com/en/articles/6786828-events-service#h_b4ed19062c) by sending the following attributes for the customer's `distinct_id` (unique identifier for the customer):
- `email`
- custom field `message.traits.action` with `identify` value

```javascript
rudderanalytics.identify("27340af5c8819", {
  firstName: "Alex Keener",
  logins: 2,
  action: 'identify',
  email: 'alex@example.com'
})
```

You can also send the `distinct_id` for a customer in the `externalId` object as shown:

```javascript
context: {
  externalId: [{
    type: 'bluecoreExternalId',
    id: '54321'
  }],
}
```

{{< info >}}
Note that any customer attributes or product properties you send in the RudderStack `identify` or `track` calls (for example, `first_name`) are permanently created in Bluecore if they do not exist already. To avoid excess or redundant attributes, only send the attributes critical to your campaigns and ensure their syntax remains the same throughout.
{{< /info >}}

### Property mappings

RudderStack maps the following properties to the Bluecore properties:

| RudderStack property | Bluecore property | 
| :-----| :----| 
| `externalId` <br/> `email` <br/> `userId` <br/> `anonymousId` <br/> <span style="color: #4D4DFF;font-size:12px;">Required</span> | `distinct_id` | 
| `name`  | `customer.name` | 
| `age` | `customer.age` | 
| `sex` | `customer.sex` | 
| `address` | `customer.address` | 
| `email`  | `customer.email` | 
| `context.app.version` | `client` | 
| `context.device.model` | `device` | 
| `destination.Config.token` | `token` | 

## Track

You can use the RudderStack [`track`]({{< ref "event-spec/standard-events/track.md" >}}) call to track the user behavior along with any associated properties.

A sample `track` call is shown below:

```javascript
rudderanalytics.track("Product Viewed", {
  product_id: "622c6f5d5cf86a4c77358033",
  sku: "8472-998-0112",
  category: "Games",
  name: "Cones of Dunshire",
  brand: "Wyatt Games",
  variant: "exapansion pack",
  price: 49.99,
  quantity: 5,
  coupon: "PREORDER15",
  currency: "USD",
  position: 1,
  url: "https://www.website.com/product/path",
  image_url: "https://www.website.com/product/path.webp",
})
```

{{< info >}}
Note that any customer attributes or product properties you send in the RudderStack `identify` or `track` calls (for example, `first_name`) are permanently created in Bluecore if they do not exist already. To avoid excess or redundant attributes, only send the attributes critical to your campaigns and ensure their syntax remains the same throughout.
{{< /info >}}

### Opt-in and unsubscribe users

You can also send `track` events to [opt-in or unsubscribe users](https://help.bluecore.com/en/articles/6786828-events-service#h_66485dc4cd) in Bluecore.

- For opting-in a customer email, send a `subscription_event` event with the `channelConsents` object, where `email` is set to `true`:

```javascript
rudderanalytics.track("subscription_event", {
  channelConsents: {
    email: true
  }
})
```

- For unsubscribing a customer email, set the `email` field to `false`:

{{< info >}}
It may take up to 24 hours for the user to be included in the unsubscribe list. See the [Bluecore documentation](https://help.bluecore.com/en/articles/3550418-unsubscribes) for more information.
{{< /info >}}

```javascript
rudderanalytics.track("subscription_event", {
  channelConsents: {
    email: false
  }
})
```

### Other custom events

If you have created any custom events in the Bluecore dashboard, you can send them as `track` calls via RudderStack without mapping them in the RudderStack dashboard. RudderStack sends the custom events  as is.

### Property mappings

RudderStack maps the following properties to the Bluecore fields:

| RudderStack property | Bluecore property | 
| :-----| :----| 
| `userId` <br/> `anonymousId` <br/> `email`  |  `distinct_id` |
| `name`  | `customer.name` | 
| `age` | `customer.age` | 
| `sex` | `customer.sex` | 
| `address` | `customer.address` | 
| `email` | `customer.email` | 
| `properties.query` <br/> <span style="color: #4D4DFF;font-size:12px;">Required for Search events.</span> | `search_term`  |
| `properties.order_id` <br/> <span style="color: #4D4DFF;font-size:12px;">Required for Purchase events.</span> | `order_id` |
| `properties.total` <br/> <span style="color: #4D4DFF;font-size:12px;">Required for Purchase events.</span> | `total` |
| `context.app.version` | `client` |
| `context.device.model` | `device` |
| `properties.products[#idx].id`/`product_id`/`sku`  | `products[#idx].id` |
| `properties.products[#idx].name` | `products[#idx].name` |
| `properties.products[#idx].price` |   `products[#idx].price` |

The following property mappings are applicable for the `subscription_event` event:

| RudderStack property | Bluecore property | 
| :-----| :----| 
| `userId` <br/> `anonymousId` <br/> `email`  |  `distinct_id` |
| `email` | `email` |
| `context.app.version` | `client` |
| `context.device.model` | `device` |

Note that:

- All the standard [RudderStack Ecommerce Events]({{< ref "event-spec/ecommerce-events-spec/_index.md" >}}) **require** `products` array except the [Products Searched](https://www.rudderstack.com/docs/event-spec/ecommerce-events-spec/browsing/#products-searched) event or any custom event mapped to Bluecore's standard `search` ecommerce event.
-  Any custom event mapped to Bluecore's standard `purchase` ecommerce event also **requires** `products` array, along with the `order_id`, `total`, and customer information (which RudderStack maps from the `traits` or `context.traits` object).
- RudderStack maps the `id` for the `products` array either from the `product_id`, `sku`, or `id`. Further, RudderStack eliminates the `product_id`, `sku`, or `id` fields after computing the `id` of the `products` object before sending it to Bluecore.

## FAQ

#### Where can I find the Bluecore namespace?

1. Log in to the [Bluecore dashboard](https://app.bluecore.com/login).
2. From the left sidebar, go to **Account** > **Integration Guide**.

{{< image src="images/event-stream-destinations/account-bluecore.webp" alt="Bluecore namespace" >}}

You can find the Bluecore namespace in the JavaScript code snippet:

{{< image src="images/event-stream-destinations/bluecore-namespace.webp" alt="Bluecore namespace" >}}

