Skip to content

Commit 164044f

Browse files
authored
Merge pull request #7141 from segmentio/acharles/traits_update
Update Migration Guides for Swift and Kotlin
2 parents e5c6ec8 + e51aff3 commit 164044f

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/connections/sources/catalog/libraries/mobile/apple/migration.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,5 +359,35 @@ The following options were removed in Analytics-Swift:
359359
| `trackInAppPurchases` | Deprecated |
360360
| `trackPushNotifications` | Deprecated |
361361
362+
### 4.a) Traits are no longer attached to `analytics.track()` events automatically
363+
364+
To prevent sending unwanted or unnecessary PII, traits collected in `analytics.identify()` events are no longer automatically attached to `analytics.track()` events. To achieve this, you can write a `before` plugin:
365+
366+
```swift
367+
import Foundation
368+
import Segment
369+
370+
class InjectTraits: Plugin {
371+
let type = PluginType.enrichment
372+
weak var analytics: Analytics? = nil
373+
374+
func execute<T: RawEvent>(event: T?) -> T? {
375+
if event?.type == "identify" {
376+
return event
377+
}
378+
379+
var workingEvent = event
380+
381+
if var context = event?.context?.dictionaryValue {
382+
context[keyPath: "traits"] = analytics?.traits()
383+
384+
workingEvent?.context = try? JSON(context)
385+
}
386+
387+
return workingEvent
388+
}
389+
}
390+
```
391+
362392
### Conclusion
363-
Once you’re up and running, you can take advantage of Analytics-Swift’s additional features, such as [Destination Filters](/docs/connections/sources/catalog/libraries/mobile/apple/swift-destination-plugins), [Functions](/docs/connections/functions/), and [Typewriter](/docs/connections/sources/catalog/libraries/mobile/apple/swift-typewriter) support.
393+
Once you’re up and running, you can take advantage of Analytics-Swift’s additional features, such as [Destination Filters](/docs/connections/sources/catalog/libraries/mobile/apple/swift-destination-plugins), [Functions](/docs/connections/functions/), and [Typewriter](/docs/connections/sources/catalog/libraries/mobile/apple/swift-typewriter) support.

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,5 +439,40 @@ Properties have been replaced by JsonElement. Since Properties are essentially a
439439
{% endcodeexample %}
440440
### 4.c) Options Support Removed
441441
Options are no longer supported and should be converted into plugins.
442+
443+
444+
### 4.d) Traits are no longer attached to `analytics.track()` events automatically
445+
446+
To prevent sending unwanted or unnecessary PII, traits collected in `analytics.identify()` events are no longer automatically attached to `analytics.track()` events. To achieve this, you can write a `before` plugin:
447+
448+
```kotlin
449+
import com.segment.analytics.kotlin.core.Analytics
450+
import com.segment.analytics.kotlin.core.Plugin
451+
import com.segment.analytics.kotlin.core.PluginType
452+
import com.segment.analytics.kotlin.core.platform.Plugin
453+
import com.segment.analytics.kotlin.core.events.RawEvent
454+
455+
class InjectTraits : Plugin {
456+
457+
override val type: PluginType = PluginType.Enrichment
458+
var analytics: Analytics? = null
459+
460+
override fun <T : RawEvent> execute(event: T?): T? {
461+
if (event?.type == "identify") {
462+
return event
463+
}
464+
465+
var workingEvent = event
466+
val context = event?.context?.toMutableMap()
467+
468+
if (context != null) {
469+
context["traits"] = analytics?.traits()
470+
471+
workingEvent?.context = context
472+
}
473+
return workingEvent
474+
}
475+
}
476+
```
442477
## Conclusion
443478
Once you’re up and running, you can take advantage of Analytics-Kotlin’s additional features, like [Destination Filters](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/kotlin-android-destination-filters/), [Functions](https://segment.com/docs/connections/functions/), and [Typewriter](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/kotlin-android-typewriter/) support.

0 commit comments

Comments
 (0)