Skip to content

Commit

Permalink
fix: Don't use idfv as deviceID if disabled. (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
crleona committed Mar 12, 2024
1 parent 35f253d commit 76ef012
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/Amplitude/Plugins/ContextPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions Tests/AmplitudeTests/AmplitudeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 76ef012

Please sign in to comment.