Skip to content

Commit

Permalink
Add Screen Event Support (#35)
Browse files Browse the repository at this point in the history
* Add screen event support

* bump version

* Add example app functions
  • Loading branch information
earlsprig committed Dec 11, 2023
1 parent cacc130 commit 1ec1235
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Example/BasicExample/BasicExample/BasicExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct BasicExampleApp: App {

extension Analytics {
static var main: Analytics {
let analytics = Analytics(configuration: Configuration(writeKey: "<YOUR WRITE KEY>")
let analytics = Analytics(configuration: Configuration(writeKey: "<SEGMENT_WRITE_KEY>")
.flushAt(3)
.trackApplicationLifecycleEvents(true))
analytics.add(plugin: SprigDestination())
Expand Down
15 changes: 15 additions & 0 deletions Example/BasicExample/BasicExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,24 @@ struct ContentView: View {
HStack {
Button(action: {
Analytics.main.track(name: "Track", properties: ["age": 3, "item": "cookies"])
}, label: {
Text("Track with Props")
}).padding(6)
Button(action: {
Analytics.main.track(name: "Track")
}, label: {
Text("Track")
}).padding(6)
Button(action: {
Analytics.main.screen(title: "iOS Segment Screen", properties: ["segmentActionsiOS": true, "deviceType": "iOS"])
}, label: {
Text("Screen with props")
}).padding(6)
Button(action: {
Analytics.main.screen(title: "iOS Segment Screen")
}, label: {
Text("Screen")
}).padding(6)
Button(action: {
Analytics.main.track(name: "Signed Out")
}, label: {
Expand Down
16 changes: 16 additions & 0 deletions Sources/SegmentSprig/SprigDestination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ public class SprigDestination: DestinationPlugin {
return event
}

public func screen(event: ScreenEvent) -> ScreenEvent? {
guard let eventName = event.name else {return event}
let properties: [String: Any?] = event.properties?.dictionaryValue as? [String: Any?] ?? [:]
Sprig.shared.track(eventName: eventName,
userId: event.userId,
partnerAnonymousId: event.anonymousId,
properties: properties) { surveyState in
guard surveyState == .ready else { return }
if let vc = UIApplication.shared.topViewController() {
Sprig.shared.presentSurvey(from: vc)
}
}
return event
}

// switch to a new user id
public func alias(event: AliasEvent) -> AliasEvent? {
guard let userId = event.userId else { return event }
Expand Down Expand Up @@ -133,6 +148,7 @@ extension UIApplication {
return topViewController
}
}

private struct SprigSettings: Codable {
let envId: String
}
2 changes: 1 addition & 1 deletion Sources/SegmentSprig/Version.swift
Original file line number Diff line number Diff line change
@@ -1 +1 @@
internal let __destination_version = "1.2.4"
internal let __destination_version = "1.2.5"

0 comments on commit 1ec1235

Please sign in to comment.