diff --git a/Sources/Amplitude/Plugins/ContextPlugin.swift b/Sources/Amplitude/Plugins/ContextPlugin.swift index 1dd6fdd3..bfb50391 100644 --- a/Sources/Amplitude/Plugins/ContextPlugin.swift +++ b/Sources/Amplitude/Plugins/ContextPlugin.swift @@ -160,13 +160,13 @@ class ContextPlugin: BeforePlugin { if isValidDeviceId(deviceId) { return } - if deviceId == nil { + if deviceId == nil, amplitude?.configuration.trackingOptions.shouldTrackIDFV() ?? false { deviceId = staticContext["idfv"] as? String } if deviceId == nil { deviceId = NSUUID().uuidString } - _ = amplitude?.setDeviceId(deviceId: deviceId) + amplitude?.setDeviceId(deviceId: deviceId) } func isValidDeviceId(_ deviceId: String?) -> Bool { diff --git a/Tests/AmplitudeTests/AmplitudeTests.swift b/Tests/AmplitudeTests/AmplitudeTests.swift index 842cc47d..57155ab8 100644 --- a/Tests/AmplitudeTests/AmplitudeTests.swift +++ b/Tests/AmplitudeTests/AmplitudeTests.swift @@ -141,6 +141,17 @@ final class AmplitudeTests: XCTestCase { XCTAssertNil(lastEvent?.country) } + func testDeviceIdWithDisableIDFV() { + let configuration = Configuration( + apiKey: "testApiKeyDeviceIDWithDisableIDFV", + storageProvider: storage, + trackingOptions: TrackingOptions().disableTrackIDFV()) + + let amplitude = Amplitude(configuration: configuration) + + XCTAssertNotEqual(amplitude.getDeviceId(), VendorSystem.current.identifierForVendor) + } + func testSetUserId() { let amplitude = Amplitude(configuration: configurationWithFakeStorage) XCTAssertEqual(amplitude.getUserId(), nil)