|
| 1 | +--- |
| 2 | +title: Analytics Kotlin Survicate Plugin |
| 3 | +strat: kotlin-android |
| 4 | +--- |
| 5 | + |
| 6 | +[Survicate](https://survicate.com/){:target="_blank"} is an all-in-one customer feedback platform that helps you collect and act on feedback from your customers. With Survicate, you can better understand your customers and improve their experience with your product or service. |
| 7 | + |
| 8 | +Add Survicate device mode support to your applications using [this plugin](https://github.com/segmentio/analytics-kotlin){:target="_blank"} for Analytics-Kotlin. |
| 9 | + |
| 10 | +## Getting started |
| 11 | + |
| 12 | +To get started, you need to provide a Survicate workspace key. |
| 13 | + |
| 14 | +You can do this in two ways: |
| 15 | + |
| 16 | +1. Add the key in the Segment panel. Navigate to **Connections > Destinations** and locate your Android app destination. Click **Settings**, then enter the key inside the Connection Settings as a "Workspace Key". |
| 17 | + |
| 18 | +2. Alternatively, you can add your Survicate workspace key as metadata inside AndroidManifest: |
| 19 | + |
| 20 | + ```xml |
| 21 | + <application |
| 22 | + android:name=".MyApp" |
| 23 | + > |
| 24 | + <!-- ... --> |
| 25 | + <meta-data android:name="com.survicate.surveys.workspaceKey" android:value="YOUR_WORKSPACE_KEY"/> |
| 26 | + </application> |
| 27 | + ``` |
| 28 | + |
| 29 | +## Adding the dependency |
| 30 | + |
| 31 | +To define the Maven repository: |
| 32 | + |
| 33 | +``` |
| 34 | +allprojects { |
| 35 | + repositories { |
| 36 | + // ... |
| 37 | + maven { url 'https://repo.survicate.com' } |
| 38 | + } |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +Add the dependency to your app's build.gradle file: |
| 43 | +``` |
| 44 | +dependencies { |
| 45 | + // ... |
| 46 | + implementation 'com.survicate:survicate-segment-analytics-kotlin:<latest_version>' |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +You can find the current version in the [plugin repository](https://github.com/Survicate/analytics-kotlin-survicate){:target="_blank"}. |
| 51 | + |
| 52 | +## Using the plugin in your app |
| 53 | +In order to activate the Survicate plugin, you have to add a `SurvicateDestination` to the Analytics instance. |
| 54 | + |
| 55 | +```kotlin |
| 56 | +analytics = Analytics(segmentKey, applicationContext) { |
| 57 | + // ... |
| 58 | +} |
| 59 | +analytics.add(SurvicateDestination(applicationContext)) |
| 60 | +``` |
| 61 | + |
| 62 | +Only keep one instance of the `Analytics` (for example, initialize it inside the application's `onCreate` method). This is important because the Survicate SDK underneath can only be initialized once. |
| 63 | + |
| 64 | +Now you can use the Analytics, having the events mapped to the Survicate SDK as described below. |
| 65 | + |
| 66 | +#### Identify |
| 67 | + |
| 68 | +In the SurvicateDestination plugin, the Identify method from Segment is transferred to the `setUserTraits` method of Survicate. You can provide multiple key-value pairs. The `userId` argument of `Analytics.identify` is also set as a user trait with the key "user_id". |
| 69 | + |
| 70 | +#### Track |
| 71 | + |
| 72 | +The Track method from Segment is used as the `invokeEvent` method in Survicate. This means that when you track an event in Segment, it will be invoked in Survicate. |
| 73 | + |
| 74 | +#### Screen |
| 75 | + |
| 76 | +Similarly, the Screen method from Segment is used as the `enterScreen` method in Survicate. This means that when you track a screen in Segment, it will be entered in Survicate. |
| 77 | + |
| 78 | +#### Reset |
| 79 | + |
| 80 | +The Reset method from Segment is used as the reset method in Survicate. This means that when you reset the Segment client, the Survicate client is also reset. |
0 commit comments