Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Migration Guides for Swift and Kotlin #7141

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
import Segment

class InjectTraits: Plugin {
let type = PluginType.enrichment
weak var analytics: Analytics? = nil

func execute<T: RawEvent>(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.
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.
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
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 <T : RawEvent> 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.
Loading