Interface DeviceIdProvider

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface DeviceIdProvider
Interface for providing custom device IDs to the Mixpanel SDK.

Use this to control device ID generation instead of relying on the SDK's default behavior (random UUID).

Important: Choose your device ID strategy up front. This callback is invoked:

Controlling Reset Behavior:

  • Return the same value each time = Device ID never changes (persistent identity)
  • Return a different value each time = Device ID changes on reset (ephemeral identity)

Warning: Adding a DeviceIdProvider to an existing app that previously used the default device ID may cause identity discontinuity. The SDK will log a warning if the provider returns a value different from the persisted anonymous ID.

Example - Persistent Device ID:


 MixpanelOptions options = new MixpanelOptions.Builder()
     .deviceIdProvider(() -> MyKeychainHelper.getOrCreatePersistentId())
     .build();
 

Example - Ephemeral Device ID (resets each time):


 MixpanelOptions options = new MixpanelOptions.Builder()
     .deviceIdProvider(() -> UUID.randomUUID().toString())
     .build();
 
  • Method Summary

    Modifier and Type
    Method
    Description
    Provides a device ID for Mixpanel tracking.
  • Method Details

    • getDeviceId

      String getDeviceId()
      Provides a device ID for Mixpanel tracking.

      This method may be called from a background thread. Implementations should be thread-safe and should not perform long-running operations.

      Returns:
      A non-empty string to use as the device ID, or an empty string to fall back to the SDK's default behavior (random UUID).