From cf3702dd62a3944ea22a93a09c33cf92b204549d Mon Sep 17 00:00:00 2001 From: Chris Leonavicius Date: Mon, 9 Sep 2024 19:24:07 -0700 Subject: [PATCH] fix: notify plugins of internal sessionId changes --- Sources/Amplitude/Amplitude.swift | 1 - Sources/Amplitude/Sessions.swift | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/Amplitude/Amplitude.swift b/Sources/Amplitude/Amplitude.swift index b995bd5..077d1fc 100644 --- a/Sources/Amplitude/Amplitude.swift +++ b/Sources/Amplitude/Amplitude.swift @@ -304,7 +304,6 @@ public class Amplitude { } else { sessionEvents = self.sessions.endCurrentSession() } - self.timeline.onSessionIdChanged(sessionId) self.sessions.assignEventId(events: sessionEvents).forEach { e in self.timeline.processEvent(event: e) } diff --git a/Sources/Amplitude/Sessions.swift b/Sources/Amplitude/Sessions.swift index a73ea5a..46fc1d1 100644 --- a/Sources/Amplitude/Sessions.swift +++ b/Sources/Amplitude/Sessions.swift @@ -4,6 +4,7 @@ public class Sessions { private let configuration: Configuration private let storage: Storage private let logger: (any Logger)? + private let timeline: Timeline private var _sessionId: Int64 = -1 private(set) var sessionId: Int64 { get { _sessionId } @@ -14,6 +15,7 @@ public class Sessions { } catch { logger?.warn(message: "Can't write PREVIOUS_SESSION_ID to storage: \(error)") } + timeline.onSessionIdChanged(_sessionId) } } @@ -47,6 +49,7 @@ public class Sessions { configuration = amplitude.configuration storage = amplitude.storage logger = amplitude.logger + timeline = amplitude.timeline self._sessionId = amplitude.storage.read(key: .PREVIOUS_SESSION_ID) ?? -1 self._lastEventId = amplitude.storage.read(key: .LAST_EVENT_ID) ?? 0 self._lastEventTime = amplitude.storage.read(key: .LAST_EVENT_TIME) ?? -1