You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/connections/sources/catalog/libraries/mobile/kotlin-android/migration.md
+136-4Lines changed: 136 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,11 +39,23 @@ If you’re using a different library such as Analytics-Android, follow these st
39
39
3. Modify your initialized instance.
40
40
41
41
<br> Before example:
42
+
{% codeexample %}
43
+
{% codeexampletab Java %}
42
44
```java
43
45
Analytics analytics = new Analytics.Builder(context, "YOUR_WRITE_KEY")
44
46
.trackApplicationLifecycleEvents()
45
47
.build();
46
48
```
49
+
{% endcodeexampletab %}
50
+
{% codeexampletab Kotlin %}
51
+
```kotlin
52
+
val analytics = Analytics.Builder(context, "YOUR_WRITE_KEY")
53
+
.trackApplicationLifecycleEvents()
54
+
.build()
55
+
```
56
+
{% endcodeexampletab %}
57
+
{% endcodeexample %}
58
+
47
59
48
60
<br> After example:
49
61
@@ -77,6 +89,9 @@ If you’re using a different library such as Analytics-Android, follow these st
77
89
<br> As middlewares have the same function as [enrichment plugins](/docs/connections/sources/catalog/libraries/mobile/kotlin-android#plugin-architecture), you need to write an enrichment plugin to add a middleware.
78
90
79
91
<br> Before example:
92
+
93
+
{% codeexample %}
94
+
{% codeexampletab Java %}
80
95
```java
81
96
builder
82
97
.useSourceMiddleware(new Middleware() {
@@ -100,6 +115,32 @@ If you’re using a different library such as Analytics-Android, follow these st
100
115
}
101
116
})
102
117
```
118
+
{% endcodeexampletab %}
119
+
{% codeexampletab Kotlin %}
120
+
```kotlin
121
+
builder
122
+
.useSourceMiddleware(
123
+
Middleware { chain ->
124
+
// Get the payload.
125
+
val payload = chain.payload()
126
+
127
+
// Set the device year class on the context object.
128
+
val year = YearClass.get(getApplicationContext())
129
+
val context = LinkedHashMap<String, Object>(payload.context())
130
+
context.put("device_year_class", year)
131
+
132
+
// Build our new payload.
133
+
val newPayload = payload.toBuilder()
134
+
.context(context)
135
+
.build();
136
+
137
+
// Continue with the new payload.
138
+
chain.proceed(newPayload)
139
+
})
140
+
```
141
+
{% endcodeexampletab %}
142
+
{% endcodeexample %}
143
+
103
144
104
145
<br> After example:
105
146
@@ -149,7 +190,7 @@ If you’re using a different library such as Analytics-Android, follow these st
149
190
150
191
override fun execute(event: BaseEvent): BaseEvent? {
151
192
// Set the device year class on the context object.
152
-
val year = YearClass.get(getApplicationContext());
193
+
val year = YearClass.get(getApplicationContext())
153
194
event.context = updateJsonObject(event.context) {
154
195
it["device_year_class"] = year
155
196
}
@@ -165,6 +206,9 @@ If you’re using a different library such as Analytics-Android, follow these st
165
206
If you don’t need to transform all of your Segment calls, and only want to transform the calls going to specific destinations, use Destination middleware instead of Source middleware. Destination middleware is available for device-mode destinations only.
166
207
167
208
<br> Before example:
209
+
210
+
{% codeexample %}
211
+
{% codeexampletab Java %}
168
212
```java
169
213
builder
170
214
.useDestinationMiddleware("Segment.io", new Middleware() {
@@ -188,6 +232,32 @@ If you’re using a different library such as Analytics-Android, follow these st
188
232
}
189
233
})
190
234
```
235
+
{% endcodeexampletab %}
236
+
{% codeexampletab Kotlin %}
237
+
```kotlin
238
+
builder
239
+
.useDestinationMiddleware(
240
+
"Segment.io",
241
+
Middleware { chain ->
242
+
// Get the payload.
243
+
val payload = chain.payload()
244
+
245
+
// Set the device year class on the context object.
246
+
val year = YearClass.get(getApplicationContext())
247
+
val context = LinkedHashMap<String, Object>(payload.context())
248
+
context.put("device_year_class", year)
249
+
250
+
// Build our new payload.
251
+
val newPayload = payload.toBuilder()
252
+
.context(context)
253
+
.build();
254
+
255
+
// Continue with the new payload.
256
+
chain.proceed(newPayload)
257
+
})
258
+
```
259
+
{% endcodeexampletab %}
260
+
{% endcodeexample %}
191
261
192
262
<br> After example:
193
263
@@ -241,7 +311,7 @@ If you’re using a different library such as Analytics-Android, follow these st
241
311
242
312
override fun execute(event: BaseEvent): BaseEvent? {
243
313
// Set the device year class on the context object.
244
-
val year = YearClass.get(getApplicationContext());
314
+
val year = YearClass.get(getApplicationContext())
245
315
event.context = updateJsonObject(event.context) {
246
316
it["device_year_class"] = year
247
317
}
@@ -285,10 +355,21 @@ If you’re using a different library such as Analytics-Android, follow these st
285
355
Segment previously used Factories to initialize destinations. With Analytics Kotlin, Segment treats destinations similar to plugins and simplifies the process in adding them.
286
356
287
357
<br> Before example:
358
+
359
+
{% codeexample %}
360
+
{% codeexampletab Java %}
288
361
```java
289
362
// Previously we used to use Factories to initialize destinations
363
+
analytics.use(FooIntegration.FACTORY);
364
+
```
365
+
{% endcodeexampletab %}
366
+
{% codeexampletab Kotlin %}
367
+
```kotlin
368
+
// Previously we used to use Factories to initialize destinations
290
369
analytics.use(FooIntegration.FACTORY)
291
370
```
371
+
{% endcodeexampletab %}
372
+
{% endcodeexample %}
292
373
293
374
<br> After example:
294
375
@@ -313,9 +394,20 @@ If you’re using a different library such as Analytics-Android, follow these st
313
394
- Identify
314
395
315
396
<br> Before example:
397
+
398
+
{% codeexample %}
399
+
{% codeexampletab Java %}
316
400
```java
317
401
analytics.identify("a user's id", new Traits().putName("John Doe"), null);
0 commit comments