MixpanelOptions

public class MixpanelOptions

Undocumented

  • Undocumented

    Declaration

    Swift

    public let token: String
  • Undocumented

    Declaration

    Swift

    public let flushInterval: Double
  • Undocumented

    Declaration

    Swift

    public let instanceName: String?
  • Undocumented

    Declaration

    Swift

    public let trackAutomaticEvents: Bool
  • Undocumented

    Declaration

    Swift

    public let optOutTrackingByDefault: Bool
  • Undocumented

    Declaration

    Swift

    public let useUniqueDistinctId: Bool
  • Undocumented

    Declaration

    Swift

    public let superProperties: Properties?
  • Undocumented

    Declaration

    Swift

    public let serverURL: String?
  • Undocumented

    Declaration

    Swift

    public let proxyServerConfig: ProxyServerConfig?
  • Undocumented

    Declaration

    Swift

    public let useGzipCompression: Bool
  • Undocumented

    Declaration

    Swift

    public let featureFlagsEnabled: Bool
  • Undocumented

    Declaration

    Swift

    public let featureFlagsContext: [String : Any]
  • A closure that provides a custom device ID.

    Use this to control device ID generation instead of relying on the SDK’s default behavior (random UUID or IDFV based on useUniqueDistinctId).

    Important: Choose your device ID strategy up front. This closure is called:

    • Once during initialization (if no persisted identity exists)
    • On each call to reset()
    • On each call to optOutTracking()

    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)
    • Return nil = Use SDK’s default device ID (useful for error handling)

    Thread Safety: This closure is called synchronously while holding internal locks. Keep implementations fast and non-blocking. For Keychain or network-fetched IDs, retrieve and cache the value at app launch, then return the cached value from the provider.

    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 (cached at launch):

    // Cache the device ID at app launch (before Mixpanel init)
    let cachedDeviceId = MyKeychainHelper.getOrCreatePersistentId()
    
    let options = MixpanelOptions(
        token: "YOUR_TOKEN",
        deviceIdProvider: { cachedDeviceId }  // Return cached value
    )
    

    Example - Ephemeral Device ID (resets each time):

    let options = MixpanelOptions(
        token: "YOUR_TOKEN",
        deviceIdProvider: {
            return UUID().uuidString
        }
    )
    

    Declaration

    Swift

    public let deviceIdProvider: (() -> String?)?
  • Undocumented

    Declaration

    Swift

    public init(
      token: String,
      flushInterval: Double = 60,
      instanceName: String? = nil,
      trackAutomaticEvents: Bool = false,
      optOutTrackingByDefault: Bool = false,
      useUniqueDistinctId: Bool = false,
      superProperties: Properties? = nil,
      serverURL: String? = nil,
      proxyServerConfig: ProxyServerConfig? = nil,
      useGzipCompression: Bool = true,  // NOTE: This is a new default value!
      featureFlagsEnabled: Bool = false,
      featureFlagsContext: [String: Any] = [:],
      deviceIdProvider: (() -> String?)? = nil
    )