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

Implementation of new attributes types #4

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions Example/BasicExample/BasicExample/BasicExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ struct BasicExampleApp: App {
}

extension Analytics {
static var main: Analytics {
let analytics = Analytics(configuration: Configuration(writeKey: "<YOUR WRITE KEY>")
static var main: Analytics = {
.flushAt(3)
.trackApplicationLifecycleEvents(true))
analytics.add(plugin: SurvicateDestination())
return analytics
}
}()
}
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ let package = Package(
.package(
name: "Segment",
url: "https://github.com/segmentio/analytics-swift.git",
from: "1.4.0"
from: "1.5.2"
),
.package(
name: "Survicate",
url: "https://github.com/Survicate/survicate-ios-sdk",
from: "3.0.2"
from: "4.1.0"
)
],
targets: [
Expand Down
20 changes: 14 additions & 6 deletions Sources/SurvicateDestination/SurvicateDestination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,22 @@ public class SurvicateDestination: DestinationPlugin {
SurvicateSdk.shared.setUserTrait(withName: "user_id", value: userId)
}

if let traits = event.traits?.dictionaryValue {
traits.forEach { key, value in
guard let value = value as? String else { return }

SurvicateSdk.shared.setUserTrait(withName: key, value: value)
if let dictionary = event.traits?.dictionaryValue {
let traits: [UserTrait] = dictionary.compactMap { key, value in
switch value {
case let value as String:
return UserTrait(withName: key, value: value)
case let value as Bool:
return UserTrait(withName: key, value: value)
case let value as Double:
return UserTrait(withName: key, value: value)
default:
return nil
}
}

SurvicateSdk.shared.setUserTraits(traits: traits)
}

return event
}

Expand Down
Loading