Package com.mixpanel.android.mpmetrics
Class MixpanelOptions.Builder
java.lang.Object
com.mixpanel.android.mpmetrics.MixpanelOptions.Builder
- Enclosing class:
- MixpanelOptions
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds and returns aMixpanelOptionsinstance with the configured settings.deviceIdProvider(DeviceIdProvider deviceIdProvider) Sets a custom device ID provider.featureFlagsContext(org.json.JSONObject featureFlagsContext) Sets the context to be used for evaluating feature flags.featureFlagsEnabled(boolean featureFlagsEnabled) Enables or disables the Mixpanel feature flags functionality.instanceName(String instanceName) Sets the distinct instance name for the MixpanelAPI.optOutTrackingDefault(boolean optOutTrackingDefault) Sets the default opt-out tracking state.Sets a custom server URL for Mixpanel API requests.serverURL(String serverURL, ProxyServerInteractor proxyServerInteractor) Sets a custom server URL with aProxyServerInteractorfor advanced proxy handling.superProperties(org.json.JSONObject superProperties) Sets the super properties to be sent with every event.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
instanceName
Sets the distinct instance name for the MixpanelAPI. This is useful if you want to manage multiple Mixpanel project instances.- Parameters:
instanceName- The unique name for the Mixpanel instance.- Returns:
- This Builder instance for chaining.
-
optOutTrackingDefault
Sets the default opt-out tracking state. If true, the SDK will not send any events or profile updates by default. This can be overridden at runtime.- Parameters:
optOutTrackingDefault- True to opt-out of tracking by default, false otherwise.- Returns:
- This Builder instance for chaining.
-
superProperties
Sets the super properties to be sent with every event. These properties are persistently stored.- Parameters:
superProperties- A JSONObject containing key-value pairs for super properties. The provided JSONObject will be defensively copied.- Returns:
- This Builder instance for chaining.
-
featureFlagsEnabled
Enables or disables the Mixpanel feature flags functionality.- Parameters:
featureFlagsEnabled- True to enable feature flags, false to disable.- Returns:
- This Builder instance for chaining.
-
featureFlagsContext
Sets the context to be used for evaluating feature flags. This can include properties like distinct_id or other custom properties.- Parameters:
featureFlagsContext- A JSONObject containing key-value pairs for the feature flags context. The provided JSONObject will be defensively copied.- Returns:
- This Builder instance for chaining.
-
deviceIdProvider
Sets a custom device ID provider.Use this to control device ID generation instead of relying on the SDK's default behavior (random UUID).
Important: The device ID strategy is an architectural decision that should be made at project inception, not retrofitted later. Adding a provider to an existing app may cause identity discontinuity.
Controlling Reset Behavior:
- Return the same value each time = Device ID never changes
- Return a different value each time = Device ID changes on reset
- Parameters:
deviceIdProvider- The provider to use, or null for default behavior.- Returns:
- This Builder instance for chaining.
- See Also:
-
serverURL
Sets a custom server URL for Mixpanel API requests.Use this to route data to a different Mixpanel region or your own proxy server. Defaults to
https://api.mixpanel.com.// Mixpanel regional server (e.g., EU) .serverURL("https://api-eu.mixpanel.com") // Custom proxy server .serverURL("https://my-proxy.example.com")- Parameters:
serverURL- The base URL for API requests.- Returns:
- This Builder instance for chaining.
-
serverURL
public MixpanelOptions.Builder serverURL(@NonNull String serverURL, @Nullable ProxyServerInteractor proxyServerInteractor) Sets a custom server URL with aProxyServerInteractorfor advanced proxy handling.Use this when your proxy server requires custom request headers or you need to listen to API responses.
.serverURL("https://my-proxy.example.com", new ProxyServerInteractor() { @Override public Map<String, String> getProxyRequestHeaders() { Map<String, String> headers = new HashMap<>(); headers.put("Authorization", "Bearer " + token); return headers; } @Override public void onProxyResponse(String url, int responseCode) { // Handle response } })- Parameters:
serverURL- The base URL for the proxy server.proxyServerInteractor- Handler for custom headers and response callbacks.- Returns:
- This Builder instance for chaining.
-
build
Builds and returns aMixpanelOptionsinstance with the configured settings.- Returns:
- A new
MixpanelOptionsinstance.
-