spotny-sdk 1.0.16 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -21,7 +21,6 @@ public typealias SpotnyEventCallback = @convention(block) (_ name: String, _ bod
|
|
|
21
21
|
|
|
22
22
|
private struct CampaignData {
|
|
23
23
|
let campaignId: Int? // nil when no active campaign
|
|
24
|
-
let sessionId: String? // set after campaign fetch response
|
|
25
24
|
let inQueue: Bool // campaign is queued — skip impressions
|
|
26
25
|
let major: Int
|
|
27
26
|
let minor: Int
|
|
@@ -96,6 +95,8 @@ public class SpotnyBeaconScanner: NSObject {
|
|
|
96
95
|
private var campaignFetchInProgress: [String: Bool] = [:]
|
|
97
96
|
private var campaignFetched: [String: Bool] = [:]
|
|
98
97
|
private var campaignFetchCooldown: [String: Date] = [:] // backoff after failed fetch
|
|
98
|
+
// session_id returned by /proximity NEARBY response — sent with every /track heartbeat
|
|
99
|
+
private var beaconSessionIds: [String: String] = [:]
|
|
99
100
|
|
|
100
101
|
// MARK: - Init
|
|
101
102
|
|
|
@@ -638,7 +639,7 @@ public class SpotnyBeaconScanner: NSObject {
|
|
|
638
639
|
return
|
|
639
640
|
}
|
|
640
641
|
if let cid = campaign.campaignId { payload["campaign_id"] = cid }
|
|
641
|
-
if let sid =
|
|
642
|
+
if let sid = beaconSessionIds[key] { payload["session_id"] = sid }
|
|
642
643
|
} else {
|
|
643
644
|
if let cid = activeCampaigns[key]?.campaignId { payload["campaign_id"] = cid }
|
|
644
645
|
}
|
|
@@ -646,8 +647,16 @@ public class SpotnyBeaconScanner: NSObject {
|
|
|
646
647
|
post(endpoint: endpoint, payload: payload) { [weak self] result in
|
|
647
648
|
guard let self = self else { return }
|
|
648
649
|
switch result {
|
|
649
|
-
case .success(let (status,
|
|
650
|
+
case .success(let (status, data)):
|
|
650
651
|
if 200...299 ~= status {
|
|
652
|
+
// Capture backend-generated session_id from the NEARBY proximity response
|
|
653
|
+
if eventType == "NEARBY",
|
|
654
|
+
let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
|
|
655
|
+
let dataObj = json["data"] as? [String: Any],
|
|
656
|
+
let sid = dataObj["session_id"] as? String, !sid.isEmpty {
|
|
657
|
+
self.beaconSessionIds[key] = sid
|
|
658
|
+
print("✅ SpotnySDK: NEARBY session_id stored — \(sid)")
|
|
659
|
+
}
|
|
651
660
|
print("✅ SpotnySDK: \(eventType) — \(String(format: "%.2f", distance))m")
|
|
652
661
|
self.logToFile("\(eventType) beacon \(key) @ \(String(format: "%.2f", distance))m")
|
|
653
662
|
} else if status == 429 {
|
|
@@ -684,17 +693,15 @@ public class SpotnyBeaconScanner: NSObject {
|
|
|
684
693
|
let dObj = json["data"] as? [String: Any] else { return }
|
|
685
694
|
|
|
686
695
|
var campaignId: Int?
|
|
687
|
-
var sessionId: String?
|
|
688
696
|
var inQueue = false
|
|
689
697
|
|
|
690
698
|
if let campaignObj = dObj["campaign"] as? [String: Any] {
|
|
691
699
|
campaignId = campaignObj["id"] as? Int
|
|
692
|
-
sessionId = campaignObj["session_id"] as? String
|
|
693
700
|
inQueue = campaignObj["inQueue"] as? Bool ?? false
|
|
694
701
|
}
|
|
695
702
|
|
|
696
703
|
self.activeCampaigns[key] = CampaignData(
|
|
697
|
-
campaignId: campaignId,
|
|
704
|
+
campaignId: campaignId,
|
|
698
705
|
inQueue: inQueue, major: major, minor: minor
|
|
699
706
|
)
|
|
700
707
|
self.campaignFetched[key] = true
|
|
@@ -738,6 +745,7 @@ public class SpotnyBeaconScanner: NSObject {
|
|
|
738
745
|
campaignFetchInProgress.removeValue(forKey: key)
|
|
739
746
|
campaignFetched.removeValue(forKey: key)
|
|
740
747
|
campaignFetchCooldown.removeValue(forKey: key)
|
|
748
|
+
beaconSessionIds.removeValue(forKey: key)
|
|
741
749
|
print("🧹 SpotnySDK: Cleaned up \(key)")
|
|
742
750
|
}
|
|
743
751
|
|