From b7236afeea16218668c34751684018ce06c999f6 Mon Sep 17 00:00:00 2001 From: Alan Charles <50601149+alanjcharles@users.noreply.github.com> Date: Mon, 14 Oct 2024 13:39:00 -0400 Subject: [PATCH 1/3] fix: update migration guides for swift and kotlin --- .../libraries/mobile/apple/migration.md | 30 ++++++++++++++++ .../mobile/kotlin-android/migration.md | 35 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/src/connections/sources/catalog/libraries/mobile/apple/migration.md b/src/connections/sources/catalog/libraries/mobile/apple/migration.md index 7794d20c8e..d9a14f5627 100644 --- a/src/connections/sources/catalog/libraries/mobile/apple/migration.md +++ b/src/connections/sources/catalog/libraries/mobile/apple/migration.md @@ -359,5 +359,35 @@ The following options were removed in Analytics-Swift: | `trackInAppPurchases` | Deprecated | | `trackPushNotifications` | Deprecated | +### 4.a) Traits are no longer attached to `analytics.track()` events automatically + +In order to prevent sending unwanted or unnecessary PII, traits collected in `analytics.identify()` events are no longer automatically attached to `analytics.track()` events. In order to achieve this, you can write a simple `before` plugin: + +```swift +import Foundation +import Segment + +class InjectTraits: Plugin { + let type = PluginType.enrichment + weak var analytics: Analytics? = nil + + func execute(event: T?) -> T? { + if event?.type == "identify" { + return event + } + + var workingEvent = event + + if var context = event?.context?.dictionaryValue { + context[keyPath: "traits"] = analytics?.traits() + + workingEvent?.context = try? JSON(context) + } + + return workingEvent + } +} +``` + ### Conclusion 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. \ No newline at end of file diff --git a/src/connections/sources/catalog/libraries/mobile/kotlin-android/migration.md b/src/connections/sources/catalog/libraries/mobile/kotlin-android/migration.md index a8ffb572f8..98fa9f09af 100644 --- a/src/connections/sources/catalog/libraries/mobile/kotlin-android/migration.md +++ b/src/connections/sources/catalog/libraries/mobile/kotlin-android/migration.md @@ -439,5 +439,40 @@ Properties have been replaced by JsonElement. Since Properties are essentially a {% endcodeexample %} ### 4.c) Options Support Removed Options are no longer supported and should be converted into plugins. + + +### 4.d) Traits are no longer attached to `analytics.track()` events automatically + +In order to prevent sending unwanted or unnecessary PII, traits collected in `analytics.identify()` events are no longer automatically attached to `analytics.track()` events. In order to achieve this, you can write a simple `before` plugin: + +```kotlin +import com.segment.analytics.kotlin.core.Analytics +import com.segment.analytics.kotlin.core.Plugin +import com.segment.analytics.kotlin.core.PluginType +import com.segment.analytics.kotlin.core.platform.Plugin +import com.segment.analytics.kotlin.core.events.RawEvent + +class InjectTraits : Plugin { + + override val type: PluginType = PluginType.Enrichment + var analytics: Analytics? = null + + override fun execute(event: T?): T? { + if (event?.type == "identify") { + return event + } + + var workingEvent = event + val context = event?.context?.toMutableMap() + + if (context != null) { + context["traits"] = analytics?.traits() + + workingEvent?.context = context + } + return workingEvent + } +} +``` ## Conclusion 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. From da07ba6ee33fd510190969574c344c1eec5afc65 Mon Sep 17 00:00:00 2001 From: pwseg <86626706+pwseg@users.noreply.github.com> Date: Mon, 14 Oct 2024 23:05:40 -0500 Subject: [PATCH 2/3] rewording --- .../sources/catalog/libraries/mobile/apple/migration.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/connections/sources/catalog/libraries/mobile/apple/migration.md b/src/connections/sources/catalog/libraries/mobile/apple/migration.md index d9a14f5627..fc0b31c2ad 100644 --- a/src/connections/sources/catalog/libraries/mobile/apple/migration.md +++ b/src/connections/sources/catalog/libraries/mobile/apple/migration.md @@ -361,7 +361,7 @@ The following options were removed in Analytics-Swift: ### 4.a) Traits are no longer attached to `analytics.track()` events automatically -In order to prevent sending unwanted or unnecessary PII, traits collected in `analytics.identify()` events are no longer automatically attached to `analytics.track()` events. In order to achieve this, you can write a simple `before` plugin: +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: ```swift import Foundation @@ -390,4 +390,4 @@ class InjectTraits: Plugin { ``` ### Conclusion -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. \ No newline at end of file +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. From e51aff35d4a5ef07a2757183ed8db0c9c2ca7f1d Mon Sep 17 00:00:00 2001 From: pwseg <86626706+pwseg@users.noreply.github.com> Date: Mon, 14 Oct 2024 23:06:18 -0500 Subject: [PATCH 3/3] rewording 2.0 --- .../catalog/libraries/mobile/kotlin-android/migration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connections/sources/catalog/libraries/mobile/kotlin-android/migration.md b/src/connections/sources/catalog/libraries/mobile/kotlin-android/migration.md index 98fa9f09af..7a843d1814 100644 --- a/src/connections/sources/catalog/libraries/mobile/kotlin-android/migration.md +++ b/src/connections/sources/catalog/libraries/mobile/kotlin-android/migration.md @@ -443,7 +443,7 @@ Options are no longer supported and should be converted into plugins. ### 4.d) Traits are no longer attached to `analytics.track()` events automatically -In order to prevent sending unwanted or unnecessary PII, traits collected in `analytics.identify()` events are no longer automatically attached to `analytics.track()` events. In order to achieve this, you can write a simple `before` plugin: +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: ```kotlin import com.segment.analytics.kotlin.core.Analytics