Skip to content

Commit

Permalink
♻️ Use unique device ID for every app install
Browse files Browse the repository at this point in the history
  • Loading branch information
iujames committed Sep 17, 2024
1 parent 7154721 commit 3c46a8e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Sources/AppcuesKit/Appcues+Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public extension Appcues {
var logger: Logging = OSLog.disabled

var anonymousIDFactory: () -> String = {
UIDevice.identifier
(UIDevice.current.identifierForVendor ?? UUID()).appcuesFormatted
}

var sessionTimeout: UInt = 300 // 5 minutes by default
Expand Down
15 changes: 0 additions & 15 deletions Sources/AppcuesKit/Data/Extensions/UIDevice+Custom.swift

This file was deleted.

18 changes: 14 additions & 4 deletions Sources/AppcuesKit/Data/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal protocol DataStoring: AnyObject {
internal class Storage: DataStoring {

private enum Key: String {
case deviceID
case deviceIDv2
case userID
case isAnonymous
case lastContentShownAt
Expand All @@ -51,10 +51,10 @@ internal class Storage: DataStoring {

internal var deviceID: String {
get {
return read(.deviceID, defaultValue: "")
return read(.deviceIDv2, defaultValue: "")
}
set {
write(.deviceID, newValue: newValue)
write(.deviceIDv2, newValue: newValue)
}
}

Expand Down Expand Up @@ -114,7 +114,17 @@ internal class Storage: DataStoring {

init(container: DIContainer) {
self.config = container.resolve(Appcues.Config.self)
self.deviceID = UIDevice.identifier

if self.deviceID.isEmpty {
// set the device ID once upon first install

// note: we cannot use UIDevice.current.identifierForVendor
// for this use case, as we need each app install to have a unique
// device_id in the Appcues system (even if from same vendor),
// to be able to correctly target push notification content to the
// correct devices
self.deviceID = UUID().appcuesFormatted
}
}

private func read<T>(_ key: Key, defaultValue: T) -> T {
Expand Down

0 comments on commit 3c46a8e

Please sign in to comment.