# Batch

## Why combine Batch and Purchasely?

[Batch](https://batch.com) rests on 3 pillars:

* A comprehensive and real-time end user view
* A set of multi-channel communication and engagement tools
* The possibility to measure and analyse the results of the engagement campaigns

Plugging Purchasely and Batch has 3 advantages:

* [Purchasely transactional events](https://purchasely.gitbook.io/purchasely/analytics/events/webhook-events) can be sent to Batch to complete the end user view with all the transactional data generated by the app stores
* Communication and engagement automations can then be configured based on these transactional events.
* Engagement messages can be linked to Purchasely paywalls using [deeplink automations](https://purchasely.gitbook.io/purchasely/advanced-features/deeplinks-and-automations) to close the loop and manage conversion, upsell or retention campaigns.

### General overview

![](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGgUdOzhqa07uh7nB2iZA%2Fuploads%2FZawuA9DJdXT97zLPVxoB%2Fbatch%20animated.gif?alt=media\&token=790d65fd-830a-4f6e-8479-8a0ac41e3b5d)

### Sample automation

![](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGgUdOzhqa07uh7nB2iZA%2Fuploads%2Fnpwe8XFX6ix6C17YUH5j%2FArchi%20diagrams.001.jpeg?alt=media\&token=1207ce29-8f49-40de-a53f-70c24265ff5d)

## Integrating Purchasely with Batch

{% hint style="danger" %}
The integration of Purchasely and Batch requires the activation of the [Trigger Events API](https://doc.batch.com/api/trigger-events-api/track-events) on Batch side. Please contact directly your Batch account manager to activate the access to this feature.
{% endhint %}

The integration requires 4 steps:

1. Activate the Batch integration in the Purchasely Console
2. Enable the events forwarded to Batch in the Purchasely Console
3. Enable the events in the Batch Dashboard
4. Set Batch SDK Custom User ID

#### 1. Activate the Batch integration in the Purchasely Console

In the Purchasely Console, go to Integration > Batch and enable the integration.

![](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGgUdOzhqa07uh7nB2iZA%2Fuploads%2F8MqIRZZ1ErcQKce2cvoP%2Fimage.png?alt=media\&token=df9a7768-4108-41ad-8a94-fa66869e0d3f)

Then carry the Android / iOS Live / Rest API keys forward from your Batch Dashboard to the Purchasely Console.

These parameters can be found in your Batch Dashboard in the following location:\
Batch Dashboard > You \[iOS / Android] app > Settings > General > API Keys

![Screenshot of the Batch Dashboard (January 2022)](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGgUdOzhqa07uh7nB2iZA%2Fuploads%2FYLmCVeVcNQIQEmhbE94v%2Fimage.png?alt=media\&token=f5eddd5e-b56a-4628-9c38-a54fd23183c7)

#### 2. Enable the events forwarded to Batch in the Purchasely Console

In the Purchasely Console, under the Server Events thumbnail, you can choose with subscription events must be forwarded to Batch.

![](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGgUdOzhqa07uh7nB2iZA%2Fuploads%2F0JTy0Ezyn8sMk38l2b9P%2Fimage.png?alt=media\&token=6f19ad7e-35c6-4ba0-899e-9a6c1aa375b6)

(Optional) Events names can be override to match with your tacking plan.

{% hint style="info" %}
Front events triggered by the Purchasely SDK cannot be forwarded to Batch directly from the Purchasely Console. This has to be done at the app level by intercepting the [SDK events](https://purchasely.gitbook.io/purchasely/analytics/events/sdk-events) and forwarding them to the Batch SDK.
{% endhint %}

#### 3. Enable the events in the Batch Dashboard

Once events have been enabled on Purchasely's side, they must also be enabled on Batch's side as well.

To do so, navigate to the following location:\
Batch Dashboard > You \[iOS / Android] app > Settings > Custom Data > User events

![](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGgUdOzhqa07uh7nB2iZA%2Fuploads%2FqYvnww6Hi8yxXiiYwD9p%2Fimage.png?alt=media\&token=de2ad68f-fbdb-48c6-a803-95ddf99f33a9)

{% hint style="info" %}
Note: Purchasely events must have been received at least once on Batch's side to appear in this list of User events
{% endhint %}

### 4. Set Batch SDK Custom User ID

{% hint style="warning" %}
This step is very important, otherwise events sent by Purchasely will not be properly associated with users
{% endhint %}

Configure Batch SDK with the **same User ID** that is [given](https://purchasely.gitbook.io/purchasely/quick-start-1/sdk-configuration/config-appendices/set-user-id) to Purchasely SDK

For example, if `Purchasely.userLogin` is called with:&#x20;

```
Purchasely.userLogin("john.doe")...
```

Then set Batch SDK with:

<pre><code><strong>Batch.User.editor()
</strong>    .setIdentifier("john.doe")
    .save();
...
</code></pre>

For more details, see Batch documentation:

* [Custom user ID (Android)](https://doc.batch.com/android/custom-data/customid/#setting-up-a-custom-user-id)
* [Custom user ID (iOS)](https://doc.batch.com/ios/custom-data/customid/#setting-up-a-custom-user-id)

## Setting-up your first automation

To configure your automations navigate to the following location in Batch:

Batch > Campaigns

![](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGgUdOzhqa07uh7nB2iZA%2Fuploads%2Ft0FgCuHUWYx2ObteRSiM%2Fimage.png?alt=media\&token=f77ce561-cbc9-4951-8db3-32aea65283f9)

To create an automation triggered by a Purchasely event, choose Trigger in the block When.

![](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGgUdOzhqa07uh7nB2iZA%2Fuploads%2FJQWe9SQkdWlQ6uHOxk49%2Fimage.png?alt=media\&token=aeea6ab0-9e02-4823-bfd3-f7383f2d8b20)

All the events that have already been received at least once by Batch will appear in the list.

You can even add a filter (set of condition) on the [event attributes](https://purchasely.gitbook.io/purchasely/analytics/events/webhook-events/attributes).

![](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGgUdOzhqa07uh7nB2iZA%2Fuploads%2F2sdH6ImVZPzOs8dmfdoB%2Fimage.png?alt=media\&token=2c392052-f3ec-43f6-af4e-639a165ec405)

You can then define the message that will be sent and the deeplink associated to it.

![](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGgUdOzhqa07uh7nB2iZA%2Fuploads%2Fz8DeGKJoaZga8jhHSUOv%2Fimage.png?alt=media\&token=e051dbf9-e725-47ac-8a03-fbcb2137f6aa)

If the deeplink matches a pattern handled by Purchasely, it will allow you to:

* display a specific paywall (for upsell and retention flow)
* display a cancellation survey
* notify users that their credit card has expired and send them to their devices settings

More information in the section [deeplinks automations](https://purchasely.gitbook.io/purchasely/advanced-features/deeplinks-and-automations).

For more information about Batch Dashboard and campaigns configuration, please refer directly to [Batch Documentation](https://doc.batch.com/).
