Skip to content

Commit

Permalink
Fix rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
mfclarke-cnx committed Feb 5, 2024
1 parent 89a371e commit 38d15b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions PostHog/PostHogSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ private let sessionChangeThreshold: TimeInterval = 1800
storage?.setString(forKey: .sessionId, contents: newValue)
}

private func getSessionlastTimestamp() -> TimeInterval? {
storage?.getDouble(forKey: .sessionlastTimestamp)
private func getSessionLastTimestamp() -> TimeInterval? {
storage?.getDouble(forKey: .sessionLastTimestamp)
}

private func setSessionlastTimestamp(_ newValue: TimeInterval) {
storage?.setDouble(forKey: .sessionlastTimestamp, contents: newValue)
private func setSessionLastTimestamp(_ newValue: TimeInterval) {
storage?.setDouble(forKey: .sessionLastTimestamp, contents: newValue)
}

// register is a reserved word in ObjC
Expand Down Expand Up @@ -382,8 +382,6 @@ private let sessionChangeThreshold: TimeInterval = 1800
guard let queue = queue else {
return
}

rotateSessionIdIfRequired()

queue.add(PostHogEvent(
event: event,
Expand Down Expand Up @@ -606,8 +604,8 @@ private let sessionChangeThreshold: TimeInterval = 1800
}

private func rotateSessionIdIfRequired() {
let sessionId = storage?.getString(forKey: .sessionId)
let sessionLastTimestamp = storage?.getDouble(forKey: .sessionlastTimestamp)
let sessionId = getSessionId()
let sessionLastTimestamp = getSessionLastTimestamp()

guard let _ = sessionId, let sessionLastTimestamp = sessionLastTimestamp else {
rotateSession()
Expand All @@ -621,10 +619,10 @@ private let sessionChangeThreshold: TimeInterval = 1800

private func rotateSession() {
let sessionId = UUID()
let sessionlastTimestamp = Date()
let sessionLastTimestamp = Date()

setSessionId(sessionId.uuidString)
setSessionlastTimestamp(sessionlastTimestamp.timeIntervalSince1970)
setSessionLastTimestamp(sessionLastTimestamp.timeIntervalSince1970)
}

@objc public func optIn() {
Expand Down
2 changes: 1 addition & 1 deletion PostHog/PostHogStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PostHogStorage {
case registerProperties = "posthog.registerProperties"
case optOut = "posthog.optOut"
case sessionId = "posthog.sessionId"
case sessionlastTimestamp = "posthog.sessionlastTimestamp"
case sessionLastTimestamp = "posthog.sessionLastTimestamp"
}

private let config: PostHogConfig
Expand Down

0 comments on commit 38d15b2

Please sign in to comment.