# Clevertap

## Why combine CleverTap and Purchasely?

### Pre-requisites

The minimal version of the Purchasely SDK supporting this integration is v3.2.0. If the Purchasely SDK integrated in your app is under the minimal version, please update it.

The CleverTap SDK also needs to be integrated inside the app.

### Subscription events

### General overview

[CleverTap](https://clevertap.com/) is an all-in-one platform combines the best analytics, segmentation, and engagement tools so that companies can build valuable, long-term relationships with their customers.

This integration will allow you to get all the available Purchasely events to CleverTap and get a better and deeper understanding of your subscription business and customer behavior. In addition you will be able to trigger automated communication based on those events, messages that could be linked to a Purchasely powered paywall to engage, upsell, retain customers.

Purchasely provides a unified dataset to track the subscription events for all stores. These events are generated by the Purchasely Backend and can be sent to CleverTap .

![](https://1658765766-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGgUdOzhqa07uh7nB2iZA%2Fuploads%2FwQTVpgo0uU1ixEAG2Frr%2Fimage.png?alt=media\&token=189f338a-efc1-4651-8c4e-297f81768b59)

Subscription events generated by Purchasely will be sent to CleverTap using a server-to-server integration. As a result, you will be able to see all the subscription events in your CleverTap Dashboard and map them with your acquisition campaigns.

#### Events

The following events are the main ones that can be sent to CleverTap by Purchasely. See the full list [here](https://purchasely.gitbook.io/purchasely/3.4/analytics/events/webhook-events/subscription-events).

| Event                           | Description                                                                                                              |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| SUBSCRIPTION\_STARTED           | Sent when the user purchased a product wether it is the start of a trial or a regular purchase of a consumable product.  |
| SUBSCRIPTION\_RENEWED           | Sent when a subscription renews                                                                                          |
| SUBSCRIPTION\_EXPIRED           | Sent when the subscription actually ends                                                                                 |
| SUBSCRIPTION\_REACTIVATED       | Sent when an expired subscription is reactivated. This event is particularly useful for win-back & retargeting campaigns |
| SUBSCRIPTION\_REFUNDED\_REVOKED | Sent when the subscription actually ends                                                                                 |
| RENEWAL\_DISABLED               | Sent when the user deactivates the renewal of a subscription wether it is in trial period or not.                        |
| RENEWAL\_ENABLED                | Sent when the user reactivates                                                                                           |
| TRIAL\_STARTED                  | Sent when a trial starts                                                                                                 |
| TRIAL\_CONVERTED                | Sent when a user converts from a free trial to a normal paid-period                                                      |
| TRIAL\_NOT\_CONVERTED           | Sent when a user finishes it's trial period without renewing to a paid-period                                            |

The names of events sent to CleverTap can be overriden when setting up the integration.

## Integrating Purchasely with CleverTap

The integration requires 2 steps:

1. Associate the user to events by providing the `CleverTap Distinct ID` to the Purchasely SDK
2. Activate the CleverTap integration in the Purchasely Console

### 1. Associating users to events

See the [CleverTap Documentation](https://help.mixpanel.com/hc/en-us/articles/115004509406-Distinct-IDs-) for more information

{% tabs %}
{% tab title="Swift" %}

```swift
CleverTap.autoIntegrate()
if let clevertapId = CleverTap.sharedInstance()?.profileGetID() {
    Purchasely.setAttribute(.clevertapId, value: clevertapId)
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val cleverTap = CleverTapAPI.getDefaultInstance(applicationContext)
cleverTap?.cleverTapID?.let {
    Purchasely.setAttribute(Attribute.CLEVER_TAP_ID, it)
}
```

{% endtab %}

{% tab title="Java" %}

```java
CleverTapAPI cleverTap = CleverTapAPI.getDefaultInstance(getApplicationContext());
if(cleverTap.getCleverTapID() != null) {
    Purchasely.setAttribute(Attribute.CLEVER_TAP_ID, cleverTap.getCleverTapID());
}
```

{% endtab %}

{% tab title="React Native" %}

```jsx
CleverTap.getCleverTapID((err, res) => {
    Purchasely.setAttribute(Attributes.CLEVER_TAP_ID, res);
});
```

{% endtab %}
{% endtabs %}

***

### 2. Activating the CleverTap integration

The activation requires 3 steps:

1. Retrieving your account's region from the CleverTap Dashboard
2. Retrieving your account's ID and passcode from the CleverTap Dashboard
3. Enabling the CleverTap integration in the Purchasely Console

#### a. Retrieving your account's region from the CleverTap Dashboard

1. Follow [the CleverTap documentation](https://developer.clevertap.com/docs/get-campaigns-api#base-url) and retrieve your account's region.
2. Write down your account's region

#### b. Retrieving your account's id and passcode from the CleverTap Dashboard

1. Follow [the CleverTap documentation](https://developer.clevertap.com/docs/api-quickstart-guide#get-clevertap-account-credentials-to-authenticate-api-requests) and retrieve your account's ID and passcode
2. Write down your account's ID and passcode

#### c. Enabling the CleverTap integration in the Purchasely Consolec

1. Go in the "External integrations" section, and open the edition form for CleverTap :

![](https://1658765766-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGgUdOzhqa07uh7nB2iZA%2Fuploads%2Fgit-blob-08fa30c22ef2539bb4e673ff7ceb269396fbfa95%2FScreenshot%202022-05-09%20at%2014.22.38.png?alt=media)

2\. Enable the integration

3\. Set your CleverTap region. (Note that if you are in the `EU` region, you should put `EU1`)

4\. Set your CleverTap account ID

5\. Set your CleverTap account passcode

6\. Enable the events you want to be sent to CleverTap

7\. (Optional) Override the names of the events that will be sent to CleverTap

![](https://1658765766-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGgUdOzhqa07uh7nB2iZA%2Fuploads%2Fgit-blob-b7a45fe6749c7de346748c9c3cabc090b88625b7%2FScreenshot%202022-05-09%20at%2014.24.01.png?alt=media)

8\. Save
