diff --git a/Sources/ODP/OdpManager.swift b/Sources/ODP/OdpManager.swift index a307e0c8..a69242b2 100644 --- a/Sources/ODP/OdpManager.swift +++ b/Sources/ODP/OdpManager.swift @@ -81,6 +81,12 @@ public class OdpManager { completionHandler: completionHandler) } + func sendInitializedEvent(vuid: String) throws { + guard enabled else { throw OptimizelyError.odpNotEnabled } + guard odpConfig.eventQueueingAllowed else { throw OptimizelyError.odpNotIntegrated } + eventManager.sendInitializedEvent(vuid: vuid) + } + func identifyUser(userId: String) { guard enabled else { logger.d("ODP identify event is not dispatched (ODP disabled).") diff --git a/Sources/Optimizely/OptimizelyClient.swift b/Sources/Optimizely/OptimizelyClient.swift index 4b9d300f..b99c9393 100644 --- a/Sources/Optimizely/OptimizelyClient.swift +++ b/Sources/Optimizely/OptimizelyClient.swift @@ -121,13 +121,7 @@ open class OptimizelyClient: NSObject { self.notificationCenter = HandlerRegistryService.shared.injectNotificationCenter(sdkKey: self.sdkKey) if let _vuid = vuid { self.odpManager.vuid = _vuid - try? sendOdpEvent(type: Constants.ODP.eventType, - action: "client_initialized", - identifiers: [ - Constants.ODP.keyForVuid: _vuid - ], - data: [:]) - + sendInitializedEvent(vuid: _vuid) } logger.d("SDK Version: \(version)") } @@ -984,6 +978,10 @@ extension OptimizelyClient { data: data) } + func sendInitializedEvent(vuid: String) { + try? odpManager.sendInitializedEvent(vuid: vuid) + } + func identifyUserToOdp(userId: String) { odpManager.identifyUser(userId: userId) } diff --git a/Tests/OptimizelyTests-APIs/OptimizelyClientTests_ODP.swift b/Tests/OptimizelyTests-APIs/OptimizelyClientTests_ODP.swift index 9299eb11..882aa717 100644 --- a/Tests/OptimizelyTests-APIs/OptimizelyClientTests_ODP.swift +++ b/Tests/OptimizelyTests-APIs/OptimizelyClientTests_ODP.swift @@ -194,9 +194,24 @@ class OptimizelyClientTests_ODP: XCTestCase { XCTAssert(optimizely.vuid!.starts(with: "vuid_")) } - func testVuidDiabled() { - // Default client vuid diabled - XCTAssertNil(optimizely.vuid) + func test_register_vuid_autometically_when_enabled() { + let settings = OptimizelySdkSettings(enableVuid: true) + optimizely = OptimizelyClient(sdkKey: OTUtils.randomSdkKey, settings: settings) + let eventManager = optimizely.odpManager.eventManager! + let evt = eventManager.eventQueue.getFirstItem()! + + XCTAssertEqual("fullstack", evt.type) + XCTAssertEqual("client_initialized", evt.action) + XCTAssertEqual(["vuid": optimizely.vuid], evt.identifiers) + XCTAssertNotNil(optimizely.vuid) + } + + func test_vuid_does_not_register_autometically_when_enabled_but_odp_disabled() { + let settings = OptimizelySdkSettings(disableOdp: true, enableVuid: true) + optimizely = OptimizelyClient(sdkKey: OTUtils.randomSdkKey, settings: settings) + XCTAssertNotNil(optimizely.vuid) + let eventManager = optimizely.odpManager.eventManager + XCTAssertNil(eventManager) } // MARK: - OdpConfig Update