Skip to content

Commit 4a14d66

Browse files
committed
complete before examples
1 parent a33f6d8 commit 4a14d66

File tree

1 file changed

+136
-4
lines changed
  • src/connections/sources/catalog/libraries/mobile/kotlin-android

1 file changed

+136
-4
lines changed

src/connections/sources/catalog/libraries/mobile/kotlin-android/migration.md

Lines changed: 136 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,23 @@ If you’re using a different library such as Analytics-Android, follow these st
3939
3. Modify your initialized instance.
4040
4141
<br> Before example:
42+
{% codeexample %}
43+
{% codeexampletab Java %}
4244
```java
4345
Analytics analytics = new Analytics.Builder(context, "YOUR_WRITE_KEY")
4446
.trackApplicationLifecycleEvents()
4547
.build();
4648
```
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+
4759
4860
<br> After example:
4961
@@ -77,6 +89,9 @@ If you’re using a different library such as Analytics-Android, follow these st
7789
<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.
7890
7991
<br> Before example:
92+
93+
{% codeexample %}
94+
{% codeexampletab Java %}
8095
```java
8196
builder
8297
.useSourceMiddleware(new Middleware() {
@@ -100,6 +115,32 @@ If you’re using a different library such as Analytics-Android, follow these st
100115
}
101116
})
102117
```
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+
103144
104145
<br> After example:
105146
@@ -149,7 +190,7 @@ If you’re using a different library such as Analytics-Android, follow these st
149190
150191
override fun execute(event: BaseEvent): BaseEvent? {
151192
// Set the device year class on the context object.
152-
val year = YearClass.get(getApplicationContext());
193+
val year = YearClass.get(getApplicationContext())
153194
event.context = updateJsonObject(event.context) {
154195
it["device_year_class"] = year
155196
}
@@ -165,6 +206,9 @@ If you’re using a different library such as Analytics-Android, follow these st
165206
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.
166207
167208
<br> Before example:
209+
210+
{% codeexample %}
211+
{% codeexampletab Java %}
168212
```java
169213
builder
170214
.useDestinationMiddleware("Segment.io", new Middleware() {
@@ -188,6 +232,32 @@ If you’re using a different library such as Analytics-Android, follow these st
188232
}
189233
})
190234
```
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 %}
191261
192262
<br> After example:
193263
@@ -241,7 +311,7 @@ If you’re using a different library such as Analytics-Android, follow these st
241311
242312
override fun execute(event: BaseEvent): BaseEvent? {
243313
// Set the device year class on the context object.
244-
val year = YearClass.get(getApplicationContext());
314+
val year = YearClass.get(getApplicationContext())
245315
event.context = updateJsonObject(event.context) {
246316
it["device_year_class"] = year
247317
}
@@ -285,10 +355,21 @@ If you’re using a different library such as Analytics-Android, follow these st
285355
Segment previously used Factories to initialize destinations. With Analytics Kotlin, Segment treats destinations similar to plugins and simplifies the process in adding them.
286356
287357
<br> Before example:
358+
359+
{% codeexample %}
360+
{% codeexampletab Java %}
288361
```java
289362
// 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
290369
analytics.use(FooIntegration.FACTORY)
291370
```
371+
{% endcodeexampletab %}
372+
{% endcodeexample %}
292373
293374
<br> After example:
294375
@@ -313,9 +394,20 @@ If you’re using a different library such as Analytics-Android, follow these st
313394
- Identify
314395
315396
<br> Before example:
397+
398+
{% codeexample %}
399+
{% codeexampletab Java %}
316400
```java
317401
analytics.identify("a user's id", new Traits().putName("John Doe"), null);
318402
```
403+
{% endcodeexampletab %}
404+
{% codeexampletab Kotlin %}
405+
```kotlin
406+
analytics.identify("a user's id", Traits().putName("John Doe"), null)
407+
```
408+
{% endcodeexampletab %}
409+
{% endcodeexample %}
410+
319411
320412
<br> After example:
321413
@@ -368,9 +460,19 @@ If you’re using a different library such as Analytics-Android, follow these st
368460
- Track
369461
370462
<br> Before example:
371-
```kotlin
463+
464+
{% codeexample %}
465+
{% codeexampletab Java %}
466+
```java
372467
analytics.track("Product Viewed", new Properties().putValue("name", "Moto 360"));
373468
```
469+
{% endcodeexampletab %}
470+
{% codeexampletab Kotlin %}
471+
```kotlin
472+
analytics.track("Product Viewed", Properties().putValue("name", "Moto 360"))
473+
```
474+
{% endcodeexampletab %}
475+
{% endcodeexample %}
374476
375477
<br> After example:
376478
@@ -427,7 +529,7 @@ If you’re using a different library such as Analytics-Android, follow these st
427529
productName = "Moto 360",
428530
brand = "Motorola",
429531
category = "smart watch",
430-
price = 300.00
532+
price = 300.00,
431533
currency = "USD"
432534
)
433535
)
@@ -449,9 +551,19 @@ If you’re using a different library such as Analytics-Android, follow these st
449551
450552
- Group
451553
<br> Before example:
554+
555+
{% codeexample %}
556+
{% codeexampletab Java %}
452557
```java
453558
analytics.group("a user's id", "a group id", new Traits().putEmployees(20));
454559
```
560+
{% endcodeexampletab %}
561+
{% codeexampletab Kotlin %}
562+
```kotlin
563+
analytics.group("a user's id", "a group id", Traits().putEmployees(20))
564+
```
565+
{% endcodeexampletab %}
566+
{% endcodeexample %}
455567
456568
<br> After example:
457569
@@ -498,9 +610,19 @@ If you’re using a different library such as Analytics-Android, follow these st
498610
499611
- Screen
500612
<br> Before example:
613+
614+
{% codeexample %}
615+
{% codeexampletab Java %}
501616
```java
502617
analytics.screen("Feed", new Properties().putValue("Feed Length", "26"));
503618
```
619+
{% endcodeexampletab %}
620+
{% codeexampletab Kotlin %}
621+
```kotlin
622+
analytics.screen("Feed", Properties().putValue("Feed Length", "26"))
623+
```
624+
{% endcodeexampletab %}
625+
{% endcodeexample %}
504626
505627
<br> After example:
506628
@@ -550,9 +672,19 @@ If you’re using a different library such as Analytics-Android, follow these st
550672
- Alias
551673
552674
<br> Before example:
675+
676+
{% codeexample %}
677+
{% codeexampletab Java %}
553678
```java
554679
analytics.alias("new id");
555680
```
681+
{% endcodeexampletab %}
682+
{% codeexampletab Kotlin %}
683+
```kotlin
684+
analytics.alias("new id")
685+
```
686+
{% endcodeexampletab %}
687+
{% endcodeexample %}
556688
557689
<br> After example:
558690

0 commit comments

Comments
 (0)