HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityOptimizely GitHubOptimizely NuGetLog In
Hey! These docs are for version 2.1.0-full-stack, which is no longer officially supported. Click here for the latest version, 1.0!

Tracks a conversion event for a user who meets the default audience conditions for an experiment. When the user does not meet those conditions, the events are not sent and consequently not tracked.

This method takes into account the user attributes passed in, to determine if the user is part of the audience that qualifies for the experiment.

Version

SDK v2.1

Description

Use this method to track events across multiple experiments. You should only send one tracking event per conversion, even if many feature tests or A/B tests are measuring it.

📘

Note

Events are counted in an experiment when both conditions apply:

  • An impression was sent as a result of the Activate or Is Feature Enabled method being called.
  • The tracked user is qualified for the experiment at the time of tracking. To ensure this, we recommend that you use the same user ID and attributes in the calls to Track and either Activate or Is Feature Enabled.

Parameter definitions

This section provides general information about the required and optional parameters.
For the specific parameter name in one of Optimizely's supported languages, see Parameter names.

ParameterTypeDescription
event key
required
stringThe key of the event to be tracked. This key must match the event key provided when the event was created in the Optimizely app.
user ID
required
stringThe ID of the user associated with the event being tracked. This ID must match the user ID provided to activate or isFeatureEnabled.
attributes
optional
mapA map of custom key-value string pairs specifying attributes for the user. For more information see: Define audiences and attributes.
event tags
optional
mapA map of key-value string pairs specifying event names and their corresponding event values associated with the event.

Parameter names

This section shows the specific parameter names for each supported language.

eventName
userId 
attributes
eventTags
eventKey
userId
userAttributes
eventTags
eventName
userId 
attributes
eventTags
eventKey
userId
attributes
eventTags
eventKey
userId
attributes
eventTags
eventKey
userId
attributes
eventTags
eventKey
userId
attributes
eventTags
event_key
user_id
attributes
event_tags
event_key
user_id
attributes
event_tags
eventKey
userId
attributes
eventTags

Returns

This method sends conversion data to Optimizely. It does not provide return values.

Examples

This section shows simple examples of how you can use the method.

// Track a conversion event for the provided user with attributes
OptimizelyClient.Track(eventKey, userId, attributes);
// Track a conversion event for the provided user with attributes
optimizelyClient.track(eventKey, userId, attributes);
// Track a conversion event for the provided user with attributes
optimizelyClient.track(eventKey, userId, attributes);
// Track a conversion event for the provided user with attributes
optimizelyClient.track("my_conversion", userId, {
  plan_type: "silver"
});
// Track a conversion event for the provided user with attributes
[optimizely track:@"my_conversion"
           userId:@"user123"
       attributes:attributes];
// Track a conversion event for the provided user with attributes
$optimizelyClient->track($eventKey, $userId, $attributes);
# Track a conversion event for the provided user with attributes
optimizely_client.track(event_key, user_id, attributes)
# Track a conversion event for the provided user with attributes
optimizely_client.track(event_key, user_id, attributes)
// Track a conversion event for the provided user with attributes
optimizely?.track("my_conversion", userId:"user123", attributes:attributes)

Exceptions

SDKExceptionMeaning
JavaUnknownEventTypeExceptionThe event type is malformed or isn't in the datafile.

See also

For more guidance and examples, see Track events.

Side effects

The table lists other other Optimizely functionality that may be triggered by using this method.

FunctionalityDescription
ConversionsAccessing this method triggers conversions for any associated experiments. This conversion event captures a conversion for each experiment that has a metric based on the particular event at the time of calling Track.

Important! This method will not track events when the specified user does not qualify for any experiments that reference this event (via metrics).
ImpressionsTrack does not trigger impressions.
Notification ListenersAccessing this method triggers a call to the TRACK notification listener.

If the user does not qualify for any experiments at the time of the Track call, no event is dispatched, and no event is emitted to the TRACK notification listener.

Notes

The attributes passed to Track can also be used for segmenting results.

Source files

The table lists the language/platform source files containing the implementations.

Language/PlatformSource files
AndroidOptimizelyClient.java
C#Optimizely.cs
JavaOptimizely.java
JavaScriptindex.js
Nodeindex.js
Objective-C and SwiftOptimizely.h
PHPOptimizely.php
Pythonoptimizely.py
Rubyoptimizely.rb