This topic describes the track event method, which tracks a conversion event in Optimizely Feature Experimentation.
Tracks a conversion event (in other words, an action a user takes) for a user. Logs an error message if the specified event key does not match any existing events.
SDK 3.7 and higher
Use this method to track events across multiple flag rules for a user. You should only make one track call per conversion (i.e., user action), even if many rules are measuring the conversion.
You call the Track Event method on a user. For more information about the user object, see OptimizelyUserContext.
The attributes passed to Track Event are only used for results segmentation.
This table lists the required and optional parameters for the Track Event method.
|String||The key of the event to be tracked. This key must match the event key provided when the event was created in the Optimizely app.|
|Map||A map of key-value pairs specifying tag names and their corresponding tag values for this particular event occurrence. Values can be strings, numbers, or booleans.|
These can be used to track numeric metrics, allowing you to track actions beyond conversions, for example: revenue, load time, or total value. See details on reserved tag keys.
This method sends conversion data to Optimizely Feature Experimentation. It does not provide return values.
val attributes = hashMapOf<String, Any>("logged_in" to true) val user = optimizelyClient.createUserContext("user123", attributes) val tags = hashMapOf<String, Any>("category" to "shoes", "purchase_count" to 2) user?.trackEvent("my_purchase_event_key", tags)
Map<String, Object> attributes = new HashMap<>(); attributes.put("logged_in", true); OptimizelyUserContext user = optimizelyClient.createUserContext("user123", attributes); Map<String, Object> tags = new HashMap<>(); tags.put("category", "shoes"); tags.put("purchase_count", 2); user.trackEvent("my_purchase_event_key", tags);
The table lists other Optimizely Feature Experimentation functionality that may be triggered by using this method.
|Conversions||Calling this method records a conversion and attributes it to the variations that the user has seen.|
You can create metrics on this conversion event and add metrics to experiments even after the conversion has been tracked.
For more information, see the support documentation on Events: Tracking clicks, pageviews, and other visitor actions.
- This method will not track events when the specified event key is invalid.
- Changing the traffic allocation of running experiments affects how conversions are recorded and variations are attributed to users.
|Notification Listeners||Accessing this method triggers a call to the |
Important! This method will not call the
The language/platform source files containing the implementation for Android are at Optimizely.java.
Updated about 2 months ago