Skip to content

Commit

Permalink
feat: add reset() to plugin (#15)
Browse files Browse the repository at this point in the history
* update analytics

* clear sessionID on reset()

* fix app open session logic
  • Loading branch information
alanjcharles authored Jan 25, 2024
1 parent 7301ece commit 5356338
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,26 @@
"repositoryURL": "https://github.com/segmentio/analytics-swift",
"state": {
"branch": null,
"revision": "79fb17a5d4abf8f80e6a0935e57c7df7b670a6c0",
"version": "1.4.1"
"revision": "51f56b972de8daee251f18fd2c91fa3a33c8d77e",
"version": "1.5.2"
}
},
{
"package": "JSONSafeEncoder",
"repositoryURL": "https://github.com/segmentio/jsonsafeencoder-swift.git",
"state": {
"branch": null,
"revision": "8b70dc8c01b7b041912e30e29d2b488a43f782ac",
"version": "1.0.1"
}
},
{
"package": "Sovran",
"repositoryURL": "https://github.com/segmentio/Sovran-Swift.git",
"state": {
"branch": null,
"revision": "944c17d7c46bd95fc37f09136cabd172be5b413b",
"version": "1.0.3"
"revision": "64f3b5150c282a34af4578188dce2fd597e600e3",
"version": "1.1.0"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let package = Package(
.package(
name: "Segment",
url: "https://github.com/segmentio/analytics-swift.git",
from: "1.4.1"
from: "1.5.2"
)
],
targets: [
Expand Down
14 changes: 12 additions & 2 deletions Sources/SegmentAmplitude/AmplitudeSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,33 @@ public class AmplitudeSession: EventPlugin, iOSLifecycle {
return event
}

lastEventFiredTime = Date()

var result: T? = event
switch result {
case let r as IdentifyEvent:
result = self.identify(event: r) as? T
lastEventFiredTime = Date()
case let r as TrackEvent:
result = self.track(event: r) as? T
case let r as ScreenEvent:
result = self.screen(event: r) as? T
lastEventFiredTime = Date()
case let r as AliasEvent:
result = self.alias(event: r) as? T
lastEventFiredTime = Date()
case let r as GroupEvent:
result = self.group(event: r) as? T
lastEventFiredTime = Date()
default:
break
}
return result
}

public func track(event: TrackEvent) -> TrackEvent? {
if event.event != "Application Opened" {
lastEventFiredTime = Date()
}

guard let returnEvent = insertSession(event: event) as? TrackEvent else {
return nil
}
Expand Down Expand Up @@ -121,6 +127,10 @@ public class AmplitudeSession: EventPlugin, iOSLifecycle {
return returnEvent
}

public func reset() {
sessionID = nil
}

public func applicationWillEnterForeground(application: UIApplication?) {
if Date().timeIntervalSince(lastEventFiredTime) >= minSessionTime {
sessionID = Date().timeIntervalSince1970
Expand Down

0 comments on commit 5356338

Please sign in to comment.