Track event method for the Java SDK
Describes thetrackEvent method for the Java SDK, which tracks a conversion event in Optimizely Feature Experimentation.
Tracks a conversion event for a user. In other words, tracks an action a user takes. Logs an error message if the specified event key does not match any existing events. SeeHow Optimizely Experimentation counts conversions.
Version
SDK 3.8 and higher. SeeMinimum version support.
Description
Use this method to track events across multipleflag rules for a user. You should make only onetrackEvent call per conversion (user action), even if many rules measure the conversion.
You call the Track Event method on a user. For information about the user object, seeOptimizelyUserContext for the Java SDK.
🚧
ImportantThe attributes passed to
trackEventareonly used forresults segmentation on theOptimizely Experiment Results page.
Parameters
eventKey(required) – String – The key of the event to be tracked. This key must match the event key provided when the event was created inthe Optimizely app orREST API.eventTags(optional) – Map – A map of key-value pairs specifying thereserved tag keys names and their corresponding values for this particular event occurrence.eventTagsare contextual metadata aboutconversion events. For example, revenue, load time, or total value. The following are available tag keys:revenue– An integer value that is used to track the revenue metric for your experiments, aggregated across all conversion events.revenueis recorded in cents.value– A floating point value that is used to track a custom value for your experiments. Use this to pass the value for numeric metrics.$opt_event_properties– A map of default and custom event properties and their values.
Returns
This method sends conversion data to Optimizely Feature Experimentation. It does not provide return values.
Example
Map<String, Object> attributes = new HashMap<>(); attributes.put("logged_in", true); OptimizelyUserContext user = optimizely.createUserContext("user123", attributes); //Map of event propertiesMap<String, Object> properties = new HashMap<>();properties.put("category", "shoes");properties.put("color", "red");// Map of eventTagsMap<String, Object> tags = new HashMap<>(); tags.put("revenue", 10000); tags.put("value", 100.00); tags.put("$opt_event_properties", properties);//user.trackevent(eventKey (required), eventTag (optional))user.trackEvent("my_purchase_event_key", tags);Side effects
Additional Feature Experimentation functionality 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. SeeHow Optimizely Experimentation counts conversions.
You can createmetrics on this conversion event and add metrics to experiments even after the conversion is tracked. SeeEvents: Tracking clicks, pageviews, and other visitor actions.
❗️
WarningThis method does not track events if the event key is invalid.
Changing the traffic allocation of running experiments affects how conversions are recorded and variations are attributed to users. SeeWhy you should not change a running experiment.
Notification listeners
Accessing this method triggers a call to thetrack notification listener.
❗️
WarningThis method does not call the
TRACKnotification listener if the event key is invalid.
Source files
The language and platform source files containing the Java implementation are available onGitHub.
Updated 17 days ago