Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MT-1688] Fix potential threading issues #344

Merged
merged 9 commits into from
Feb 11, 2025
8 changes: 4 additions & 4 deletions samples/ConsentManagerDemo/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PODS:
- Eureka (5.3.1)
- tealium-swift (2.15.0):
- tealium-swift/TealiumFull (= 2.15.0)
- tealium-swift/TealiumFull (2.15.0)
- tealium-swift (2.15.1):
- tealium-swift/TealiumFull (= 2.15.1)
- tealium-swift/TealiumFull (2.15.1)

DEPENDENCIES:
- Eureka (~> 5.3)
Expand All @@ -18,7 +18,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Eureka: 859877ab1e85661b6b7e810015d430e937d9cc7d
tealium-swift: 3c6d8d7b3b72fb09460f08c303c46eca4dbd5b23
tealium-swift: a7e87d5cc3cba379678bf4e456fa7d32072eeb9b

PODFILE CHECKSUM: a08a1d1cef2344f90eb2215ef34bbdf985d4db40

Expand Down
8 changes: 4 additions & 4 deletions samples/TealiumMediaExample/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PODS:
- tealium-swift (2.15.0):
- tealium-swift/TealiumFull (= 2.15.0)
- tealium-swift/TealiumFull (2.15.0)
- tealium-swift (2.15.1):
- tealium-swift/TealiumFull (= 2.15.1)
- tealium-swift/TealiumFull (2.15.1)

DEPENDENCIES:
- tealium-swift (from `../../`)
Expand All @@ -11,7 +11,7 @@ EXTERNAL SOURCES:
:path: "../../"

SPEC CHECKSUMS:
tealium-swift: 3c6d8d7b3b72fb09460f08c303c46eca4dbd5b23
tealium-swift: a7e87d5cc3cba379678bf4e456fa7d32072eeb9b

PODFILE CHECKSUM: 9f7c4052f5026295b89589ca935de017625dcaf3

Expand Down
16 changes: 8 additions & 8 deletions samples/TealiumSwiftExample/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
PODS:
- tealium-swift (2.15.0):
- tealium-swift/TealiumFull (= 2.15.0)
- tealium-swift/Collect (2.15.0):
- tealium-swift (2.15.1):
- tealium-swift/TealiumFull (= 2.15.1)
- tealium-swift/Collect (2.15.1):
- tealium-swift/Core
- tealium-swift/Core (2.15.0)
- tealium-swift/Lifecycle (2.15.0):
- tealium-swift/Core (2.15.1)
- tealium-swift/Lifecycle (2.15.1):
- tealium-swift/Core
- tealium-swift/TealiumFull (2.15.0)
- tealium-swift/VisitorService (2.15.0):
- tealium-swift/TealiumFull (2.15.1)
- tealium-swift/VisitorService (2.15.1):
- tealium-swift/Core

DEPENDENCIES:
Expand All @@ -22,7 +22,7 @@ EXTERNAL SOURCES:
:path: "../.."

SPEC CHECKSUMS:
tealium-swift: 3c6d8d7b3b72fb09460f08c303c46eca4dbd5b23
tealium-swift: a7e87d5cc3cba379678bf4e456fa7d32072eeb9b

PODFILE CHECKSUM: e9decae1a597032f7b4e373adc4add77507a031d

Expand Down
14 changes: 7 additions & 7 deletions samples/VisitorServiceDemo/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
PODS:
- SCLAlertView (0.8)
- SwiftConfettiView (0.1.0)
- tealium-swift/Collect (2.15.0):
- tealium-swift/Collect (2.15.1):
- tealium-swift/Core
- tealium-swift/Core (2.15.0)
- tealium-swift/Lifecycle (2.15.0):
- tealium-swift/Core (2.15.1)
- tealium-swift/Lifecycle (2.15.1):
- tealium-swift/Core
- tealium-swift/Location (2.15.0):
- tealium-swift/Location (2.15.1):
- tealium-swift/Core
- tealium-swift/TagManagement (2.15.0):
- tealium-swift/TagManagement (2.15.1):
- tealium-swift/Core
- tealium-swift/VisitorService (2.15.0):
- tealium-swift/VisitorService (2.15.1):
- tealium-swift/Core

DEPENDENCIES:
Expand All @@ -35,7 +35,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
SCLAlertView: 6a77bb2edfc65e04dbe57725546cb4107a506b85
SwiftConfettiView: 1bdbc2e6913b6b1c76d8070802b212508ad5c352
tealium-swift: 3c6d8d7b3b72fb09460f08c303c46eca4dbd5b23
tealium-swift: a7e87d5cc3cba379678bf4e456fa7d32072eeb9b

PODFILE CHECKSUM: 52313dad09b407d6fd495d1d95dcfb1ef5c54268

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class MockConnectivityMonitorIsConnectedWifi: ConnectivityMonitorProtocol {
self.config = config
}

var currentConnnectionType: String? = "wifi"
var currentConnectionType: String? = "wifi"

var isConnected: Bool? = true

Expand All @@ -260,7 +260,7 @@ class MockConnectivityMonitorIsConnectedWired: ConnectivityMonitorProtocol {
self.config = config
}

var currentConnnectionType: String? = "wired"
var currentConnectionType: String? = "wired"

var isConnected: Bool? = true

Expand All @@ -285,7 +285,7 @@ class MockConnectivityMonitorIsConnectedCellular: ConnectivityMonitorProtocol {
self.config = config
}

var currentConnnectionType: String? = "cellular"
var currentConnectionType: String? = "cellular"

var isConnected: Bool? = true

Expand All @@ -310,7 +310,7 @@ class MockConnectivityMonitorNotConnected: ConnectivityMonitorProtocol {
self.config = config
}

var currentConnnectionType: String? = "none"
var currentConnectionType: String? = "none"

var isConnected: Bool? = false

Expand Down
2 changes: 1 addition & 1 deletion tealium-swift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Pod::Spec.new do |s|

s.name = "tealium-swift"
s.module_name = "TealiumSwift"
s.version = "2.15.0"
s.version = "2.15.1"
s.summary = "Tealium Swift Integration Library"

# This description is used to generate tags and improve search results.
Expand Down
44 changes: 31 additions & 13 deletions tealium/core/ModulesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,48 +182,64 @@ public class ModulesManager {
}
}

func sendTrack(_ request: TealiumTrackRequest) {
private func refreshSettings() {
if self.config.shouldUseRemotePublishSettings == true {
self.remotePublishSettingsRetriever?.refresh()
}
guard config.isEnabled != false else { return }
}

private func enrichRequest(_ request: TealiumTrackRequest) -> TealiumTrackRequest {
let requestData = gatherTrackData(for: request.trackDictionary)
let newRequest = TealiumTrackRequest(data: requestData)
return newRequest
}

private func updateCachedTrackData(_ request: TealiumTrackRequest) {
cachedTrackData = request.trackDictionary
}

private func enrichAndTrack(_ request: TealiumTrackRequest) {
let newRequest = enrichRequest(request)
dispatchManager?.processTrack(newRequest)
cachedTrackData = newRequest.trackDictionary
updateCachedTrackData(newRequest)
}

func sendTrack(_ request: TealiumTrackRequest) {
refreshSettings()
guard config.isEnabled != false else { return }
enrichAndTrack(request)
}

func allTrackData(retrieveCachedData: Bool) -> [String: Any] {
if retrieveCachedData, let cachedData = self.cachedTrackData {
return cachedData
}
let data = gatherTrackData(for: TealiumTrackRequest(data: [:]).trackDictionary)
var request = TealiumTrackRequest(data: data)
var request = enrichRequest(TealiumTrackRequest(data: [:]))
_ = dispatchManager?.checkShouldQueue(request: &request)
cachedTrackData = request.trackDictionary
updateCachedTrackData(request)
return request.trackDictionary
}

func gatherTrackData(for data: [String: Any]?) -> [String: Any] {
let allData = Atomic(value: [String: Any]())
var allData = [String: Any]()
self.collectors.forEach {
guard let data = $0.data else {
return
}
allData.value += data
allData += data
}

allData.value[TealiumDataKey.enabledModules] = modules.sorted { $0.id < $1.id }.map { $0.id }
allData[TealiumDataKey.enabledModules] = modules.sorted { $0.id < $1.id }.map { $0.id }

sessionManager?.refreshSession()
if let dataLayer = dataLayerManager?.all {
allData.value += dataLayer
allData += dataLayer
}

if let data = data {
allData.value += data
allData += data
}
return allData.value
return allData
}

func disableModule(id: String) {
Expand Down Expand Up @@ -367,7 +383,9 @@ extension ModulesManager: ModuleDelegate {
}

public func requestDequeue(reason: String) {
self.dispatchManager?.handleDequeueRequest(reason: reason)
TealiumQueues.backgroundSerialQueue.async {
self.dispatchManager?.handleDequeueRequest(reason: reason)
}
}

public func processRemoteCommandRequest(_ request: TealiumRequest) {
Expand Down
2 changes: 1 addition & 1 deletion tealium/core/TealiumConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum Dispatchers {}

public enum TealiumValue {
public static let libraryName = "swift"
public static let libraryVersion = "2.15.0"
public static let libraryVersion = "2.15.1"
// This is the current limit for performance reasons. May be increased in future
public static let maxEventBatchSize = 10
public static let defaultMinimumDiskSpace: Int32 = 20_000_000
Expand Down
4 changes: 2 additions & 2 deletions tealium/core/connectivity/ConnectivityModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ protocol ConnectivityMonitorProtocol {
init(config: TealiumConfig,
completion: @escaping ((Result<Bool, Error>) -> Void))
var config: TealiumConfig { get set }
var currentConnnectionType: String? { get }
var currentConnectionType: String? { get }
var isConnected: Bool? { get }
var isExpensive: Bool? { get }
var isCellular: Bool? { get }
Expand All @@ -24,7 +24,7 @@ public class ConnectivityModule: Collector, ConnectivityDelegate {
public var id: String = ModuleNames.connectivity

public var data: [String: Any]? {
if let connectionType = self.connectivityMonitor?.currentConnnectionType {
if let connectionType = self.connectivityMonitor?.currentConnectionType {
return [ConnectivityKey.connectionType: connectionType,
]
} else {
Expand Down
6 changes: 3 additions & 3 deletions tealium/core/connectivity/LegacyConnectivityMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SystemConfiguration
#endif

class LegacyConnectivityMonitor: ConnectivityMonitorProtocol {
var currentConnnectionType: String? {
var currentConnectionType: String? {
#if os(watchOS)
return TealiumValue.unknown
#else
Expand All @@ -30,7 +30,7 @@ class LegacyConnectivityMonitor: ConnectivityMonitorProtocol {
return false
#else
let connected = isConnectedToNetwork()
if config.wifiOnlySending == true, currentConnnectionType != ConnectivityKey.connectionTypeWifi {
if config.wifiOnlySending == true, currentConnectionType != ConnectivityKey.connectionTypeWifi {
return false
} else {
return connected
Expand All @@ -43,7 +43,7 @@ class LegacyConnectivityMonitor: ConnectivityMonitorProtocol {
}

var isCellular: Bool? {
currentConnnectionType == ConnectivityKey.connectionTypeCell
currentConnectionType == ConnectivityKey.connectionTypeCell
}

var isWired: Bool? {
Expand Down
2 changes: 1 addition & 1 deletion tealium/core/connectivity/NWPathMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Network
#if !os(watchOS)
class TealiumNWPathMonitor: ConnectivityMonitorProtocol {

var currentConnnectionType: String? {
var currentConnectionType: String? {
guard isConnected == true else {
return ConnectivityKey.connectionTypeNone
}
Expand Down
Loading