# CleverTap Destination

## Destination Info

* Accepts [Page](/docs/segment/connections/spec/page), [Alias](/docs/segment/connections/spec/alias), [Identify](/docs/segment/connections/spec/identify), [Track](/docs/segment/connections/spec/track) calls.
* Refer to it as **CleverTap** in the [Integrations object.](/docs/segment/guides/filtering-data/#filtering-with-the-integrations-object)

### Components

* [Browser](https://github.com/segment-integrations/analytics.js-integration-clevertap)
* [iOS](https://github.com/CleverTap/clevertap-segment-ios)
* [Android](https://github.com/CleverTap/clevertap-segment-android)

## Connection Modes

[Learn more about connection modes.](/docs/segment/connections/destinations/#connection-modes)

### Device-Mode

* web: yes
* mobile: yes
* server: no

### Cloud-Mode

* web: no
* mobile: yes
* server: yes

## Getting Started

Once the Segment library is integrated, toggle CleverTap on in your Segment destinations, and add your CleverTap Account ID and CleverTap Account Token which you can find in the CleverTap Dashboard under Settings.

CleverTap supports the Identify, Track, Page (server-side only), and Screen (iOS and server-side only) methods.

You can integrate CleverTap using a server-side or mobile destination (iOS or Android). If you are interested in using CleverTap's push notifications or in-app notifications products, you should use the mobile destinations.

For server-side destination requests, CleverTap requires both the Segment `anonymousId` and `userId` in the payload.

CleverTap maintains the server-side and mobile integrations:

* [Android](https://github.com/CleverTap/clevertap-segment-android)
* [iOS](https://github.com/CleverTap/clevertap-segment-ios)

For any issues with the server-side and mobile integrations, [contact the CleverTap Support team](https://help.clevertap.com/hc/en-us/requests/new).

## Identify

When you identify a user, Segment passes that user's information to CleverTap with userId as CleverTap's Identity value. A number of Segment's special traits map to CleverTap's standard user profile fields. You'll pass the key on the left into Segment and Segment transforms it to the key on the right before sending to CleverTap.

* `name` maps to `Name`
* `birthday` maps to `DOB`
* `avatar` maps to `Photo`
* `gender` maps to `Gender`
* `phone` maps to `Phone`
* `email` maps to `Email`

All other traits will be sent to CleverTap as custom attributes. The default logic will lower case and snake\_case any user traits - custom or special - passed to CleverTap.

> \[!NOTE]
>
> In cloud mode, CleverTap uses Segment anonymous ID as the CleverTap ID.
> In device mode, CleverTap ignores the anonymous ID and CleverTap injects its own ID.

## Alias

> \[!WARNING]
>
> Alias is supported by Device-mode Web connections

When you send an Alias call to CleverTap, CleverTap updates the user's profile with the contents of the Alias call.

## Track

When you `track` an event, Segment sends that event to CleverTap as a custom event. CleverTap requires Identify traits like `userId` or `email` to record and associate the Track event. Without these traits, the Track event does not appear in CleverTap.

CleverTap does not support arrays or nested objects for custom Track event properties.

The default logic for the cloud mode connection to CleverTap will lower case and snake\_case any event properties passed from Segment's servers to CleverTap. The device mode connection will not lower case or snake\_case any event properties passed directly to CleverTap from the client.

### Order Completed

When you `track` an event using the server-side destination with the name `Order Completed` using the [e-commerce tracking API](/docs/segment/connections/spec/ecommerce/v2/), Segment maps that event to CleverTap's [Charged](https://support.clevertap.com/docs/working-with-events.html#recording-customer-purchases) event.

## Page

When you send a `page` event using the server-side destination, Segment sends that event to CleverTap as a Web Page Viewed event.

## Screen

When you send a `screen` event using the server-side destination or the iOS bundled SDK, Segment sends that event to CleverTap as an App Screen Viewed event.

## Android

### Integrating

1. Add the CleverTap Segment Destination dependency to your app build.gradle:

   `compile 'com.clevertap.android:clevertap-segment-android:+'`

   **Note**: The group Id is `com.clevertap.android`, not `com.segment.analytics.android.integrations`.
2. Next, declare CleverTap's destination in your Analytics instance:

   ```java
   Analytics analytics = new Analytics.Builder(context, "YOUR_WRITE_KEY_HERE")
     .use(CleverTapIntegration.FACTORY)
     ...
     .build();
   ```

### Integrating Push

1. In your AndroidManifest.xml, register the following CleverTap services.

   ```xml
   <service
       android:name="com.clevertap.android.sdk.FcmTokenListenerService">
       <intent-filter>
           <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
       </intent-filter>
   </service>

   <service
       android:name="com.clevertap.android.sdk.FcmMessageListenerService">
       <intent-filter>
           <action android:name="com.google.firebase.MESSAGING_EVENT"/>
       </intent-filter>
   </service>
   ```
2. For more in-depth information, visit CleverTap's [Android push integration documentation](https://developer.clevertap.com/docs/android).

### In-App Notifications

1. In your AndroidManifest.xml, add the CleverTap InAppNotificationActivity.

   ```xml
   <activity
           android:name="com.clevertap.android.sdk.InAppNotificationActivity"
           android:configChanges="orientation|keyboardHidden"
           android:theme="@android:style/Theme.Translucent.NoTitleBar" />
   ```

   No further action is required to integrate in-app notifications, which are registered for and requested by default by the CleverTap Segment integration.

### Sample App

CleverTap has created a sample Android application that integrates CleverTap using Segment. Check it out at the [GitHub repository](https://github.com/CleverTap/clevertap-segment-android-example).

## iOS

### Integrating

1. Add the CleverTap Segment Pod to your Podfile:

   ```objc
   `pod 'Segment-CleverTap'`
   ```

   Use the latest version on [CocoaPods](https://cocoapods.org/pods/Segment-CleverTap) since it will contain the most up to date features and bug fixes.
2. Next, declare CleverTap's integration in your app delegate instance:

   ```objc
   SEGAnalyticsConfiguration *config = [SEGAnalyticsConfiguration configurationWithWriteKey:@"YOUR_WRITE_KEY_HERE"];
   [config use:[SEGCleverTapIntegrationFactory instance]];
   [SEGAnalytics setupWithConfiguration:config];
   ```

### Integrating Push

1. Follow the directions to register for push at: [/docs/connections/sources/catalog/libraries/mobile/ios/#how-do-i-use-push-notifications](/docs/segment/connections/sources/catalog/libraries/mobile/ios/#how-do-i-use-push-notifications).
2. In your application's application:didReceiveRemoteNotification: method, add the following:

   `[[SEGAnalytics sharedAnalytics] receivedRemoteNotification:userInfo];`
3. If you integrated the application:didReceiveRemoteNotification:fetchCompletionHandler: in your app, add the following to that method:

   `[[SEGAnalytics sharedAnalytics] receivedRemoteNotification:userInfo];`
4. If you implemented handleActionWithIdentifier:forRemoteNotification:, add the following to that method:

   `[[SEGAnalytics sharedAnalytics] handleActionWithIdentifier:identifier forRemoteNotification:userInfo];`

### In-App Notifications

No further action is required to integrate in-app notifications, which are registered for and requested by default by the CleverTap Segment integration.

### Sample App

CleverTap has created a sample iOS application that integrates CleverTap using Segment. Check it out at the [GitHub repository](https://github.com/CleverTap/clevertap-segment-ios/tree/master/Example).

## Server-Side

### Push Tokens

If you chose not to bundle the CleverTap Mobile SDK, then you will have to implement your own Push Message processors (and you won't have access to CleverTap's In-App feature).

If you decide to implement your own Push Message processors, then you can pass push tokens to CleverTap using the server-side destination. You can do this by sending it inside context.device.token.

## Troubleshooting

### Verbose Logging

When using Web Device-mode, you can enable verbose logging of all communication with CleverTap servers by setting the `theWZRK_D` variable in `sessionStorage`. In the developer console of your browser, enter `sessionStorage['WZRK_D'] = '';`, you'll see error messages and warnings logged. See the [CleverTap Web Quickstart Guide](https://developer.clevertap.com/docs/web-quickstart-guide#debugging) for more details.

## Engage

You can send computed traits and audiences generated using [Engage](/docs/segment/engage) to this destination as a **user property**. To learn more about Engage, schedule a [demo](https://segment.com/contact/demo).

For user-property destinations, an [identify](/docs/segment/connections/spec/identify/) call is sent to the destination for each user being added and removed. The property name is the snake\_cased version of the audience name, with a true/false value to indicate membership. For example, when a user first completes an order in the last 30 days, Engage sends an Identify call with the property `order_completed_last_30days: true`. When the user no longer satisfies this condition (for example, it's been more than 30 days since their last order), Engage sets that value to `false`.

When you first create an audience, Engage sends an Identify call for every user in that audience. Later audience syncs only send updates for users whose membership has changed since the last sync.

> \[!NOTE]
>
> Real-time audience syncs to CleverTap  may take six or more hours for the initial sync to complete. Upon completion, a sync frequency of two to three hours is expected.

## Settings

Segment lets you change these destination settings from the Segment app without having to touch any code.

| Field         | Description                                                                                                        | Required | Type   |
| ------------- | ------------------------------------------------------------------------------------------------------------------ | -------- | ------ |
| Account ID    | Add your CleverTap Account ID which you can find in the CleverTap Dashboard under Settings.                        | Yes      | string |
| Account Token | \*\*Mobile Only:\*\*Add your CleverTap Account Token which you can find in the CleverTap Dashboard under Settings. | No       | string |
| Region        | \*\*Server Only\*\*: Your dedicated Clevertap region.                                                              | No       | select |
