Leanplum collects a device ID that uniquely identifies the device in which your user uses your application. The Leanplum SDK is optimized to automatically determine and identify those devices. This happens when the
Leanplum.start() is called for the first time. This cannot be changed unless the user uninstalls/reinstalls your app.
Below is our platform specific methods for setting and identifying those devices.
Select your OS or language below for specific instructions on setup.
More on Variables Implementation for iOS.
More on Variables Implementation for Android.
More on setup for Unity Variables Implementation.
More on Variables Implementation for React Native.
iOS Device ID
On iOS, by default, we use the
identifierForVendor (IDFV) property in iOS to set the device ID in Leanplum. You can choose how the device ID is set the first time start is called on that device by calling one of these before
//Set the device ID to a custom ID using the setDeviceId call. Make sure that your custom ID is unique per device. Leanplum.setDeviceID("customAndUniqueId")
//Sets the device ID to a custom ID. Make sure that your custom ID is unique per device. [Leanplum setDeviceId:@"customAndUniqueId"]
iOS SDK v3.1.0+ Changes To Accommodate iOS 14+ Changes
Deprecated: Starting in iOS SDK 3.1.0, to accommodate changes in iOS 14, we have deprecated the
LEANPLUM_USE_ADVERTISING_IDmacro, which older versions of the SDK used to set IDFA.
New Functionality: Additionally, we have allowed
deviceIdto be set after the first start. When you set the new Device ID, this will create a new device under that user profile. All device fields (including the push token) will be moved from the old device ID to the new device ID and marked as the latest device. This enables you to set the device ID as IDFA at a later stage when the user provides consent.
userIdlogin does not change if the deviceId is changed mid-session or not.
Android Device ID
On Android, by default, we will use the
ANDROID_ID for the Device ID. As you will see below we do support using the
You can choose how the device ID will be set the first time start is called on that device by calling one of these before
//By default Leanplum will use Android_ID Leanplum.setDeviceIdMode(LeanplumDeviceIdMode.ANDROID_ID); //ADVERTISING_ID is also supported Leanplum.setDeviceIdMode(LeanplumDeviceIdMode.ADVERTISING_ID); //Sets the device ID to a custom ID. Make sure that your custom ID is unique per device. Leanplum.setDeviceId("customAndUniqueId");
Whether or not you decide to set a custom Device ID a
DeviceIdMode, the SDK uses the following logic to set the
deviceId (unless you use
//Pseudocode Logic to set Android deviceId if DeviceIdMode == 'ADVERTISING_ID': set deviceId = 'ADVERTISING_ID' else if DeviceIdMode == 'ANDROID_ID': set deviceId = 'ANDROID_ID' else if (Android < 6.0 and `ACCESS_WIFI_STATE` permission): set deviceId = Hash of device MAC Address else if `ANDROID_ID` is available: set deviceId = `ANDROID_ID` else deviceId = random generated device ID
You can view the source code here.
Device ID can only be set Once
deviceIdis set when
Leanplum startruns for the first time on that device. After this, it cannot be changed unless the user completely uninstalls and reinstalls your app.
Unity Device ID
The device ID uniquely identifies the devices and is determined automatically by the SDK. On Unity, we use
SystemInfo.deviceUniqueIdentifier to get the device ID. Refer to the Unity documentation to learn more.
localStorage. You can set a custom device ID instead using
React Native Device ID
The device ID uniquely identifies the devices and is determined automatically by the SDK. In the React Native SDK, we use the platform-specific logic for iOS or Android as covered in detail above. We take that device ID and persist it using
AsyncStorage. You can set a custom device ID instead using
Device ID and Attribution Partners
If you use an external attribution provider, make sure your device ID set matches the device ID in your attribution provider (ex: IDFV -> IDFV). See How to integrate external Attribution services for more.