mirror of
https://github.com/aptabase/aptabase-swift.git
synced 2026-01-18 22:21:17 +01:00
Use new session id format
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'Aptabase'
|
||||
s.version = '0.3.3'
|
||||
s.version = '0.3.4'
|
||||
s.summary = 'Swift SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps'
|
||||
s.homepage = 'https://aptabase.com'
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
## 0.3.4
|
||||
|
||||
* Use new session id format
|
||||
|
||||
## 0.3.3
|
||||
|
||||
* Added Privacy Manifest (PrivacyInfo.xcprivacy)
|
||||
|
||||
@@ -19,7 +19,7 @@ let package = Package(
|
||||
...
|
||||
dependencies: [
|
||||
...
|
||||
.package(name: "Aptabase", url: "https://github.com/aptabase/aptabase-swift.git", from: "0.3.3"),
|
||||
.package(name: "Aptabase", url: "https://github.com/aptabase/aptabase-swift.git", from: "0.3.4"),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
@@ -39,7 +39,7 @@ Use this [guide](https://developer.apple.com/documentation/xcode/adding-package-
|
||||
Aptabase is also available through CocoaPods. To install it, simply add the following line to your Podfile:
|
||||
|
||||
```ruby
|
||||
pod 'Aptabase', :git => 'https://github.com/aptabase/aptabase-swift.git', :tag => '0.3.3'
|
||||
pod 'Aptabase', :git => 'https://github.com/aptabase/aptabase-swift.git', :tag => '0.3.4'
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import Foundation
|
||||
|
||||
class AptabaseClient {
|
||||
private static let sdkVersion = "aptabase-swift@0.3.3"
|
||||
private static let sdkVersion = "aptabase-swift@0.3.4"
|
||||
// Session expires after 1 hour of inactivity
|
||||
private static let sessionTimeout: TimeInterval = 1 * 60 * 60
|
||||
|
||||
private var sessionId = UUID()
|
||||
private var sessionId = newSessionId()
|
||||
private var lastTouched = Date()
|
||||
private var flushTimer: Timer?
|
||||
private let dispatcher: EventDispatcher
|
||||
@@ -22,7 +22,7 @@ class AptabaseClient {
|
||||
public func trackEvent(_ eventName: String, with props: [String: AnyCodableValue] = [:]) {
|
||||
let now = Date()
|
||||
if lastTouched.distance(to: now) > AptabaseClient.sessionTimeout {
|
||||
sessionId = UUID()
|
||||
sessionId = AptabaseClient.newSessionId()
|
||||
}
|
||||
lastTouched = now
|
||||
|
||||
@@ -58,6 +58,12 @@ class AptabaseClient {
|
||||
public func flush() async {
|
||||
await dispatcher.flush()
|
||||
}
|
||||
|
||||
private static func newSessionId() -> String {
|
||||
let epochInSeconds = UInt64(Date().timeIntervalSince1970)
|
||||
let random = UInt64.random(in: 0...99999999)
|
||||
return String(epochInSeconds * 100000000 + random)
|
||||
}
|
||||
|
||||
@objc private func flushSync() {
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
|
||||
@@ -2,7 +2,7 @@ import Foundation
|
||||
|
||||
struct Event: Encodable {
|
||||
var timestamp: Date
|
||||
var sessionId: UUID
|
||||
var sessionId: String
|
||||
var eventName: String
|
||||
var systemProps: SystemProps
|
||||
var props: [String: AnyCodableValue]?
|
||||
|
||||
Reference in New Issue
Block a user