GuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityLog In
Hey! These docs are for version 2.1, which is no longer officially supported. Click here for the latest version, 3.1!

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.

Parameter

Type

Description

event key
required

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.

user ID
required

string

The ID of the user associated with the event being tracked. This ID must match the user ID provided to activate or isFeatureEnabled.

attributes
optional

map

A map of custom key-value string pairs specifying attributes for the user. For more information see: Define audiences and attributes.

event tags
optional

map

A 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 doesn't 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

SDK

Exception

Meaning

Java

UnknownEventTypeException

The 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.

Functionality

Description

Conversions

Accessing 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 won't track events when the specified user doesn't qualify for any experiments that reference this event (via metrics).

Impressions

Track doesn't trigger impressions.

Notification Listeners

Accessing this method triggers a call to the TRACK notification listener.

If the user doesn't 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/Platform

Source files

Android

OptimizelyClient.java

C#

Optimizely.cs

Java

Optimizely.java

JavaScript

index.js

Node

index.js

Objective-C and Swift

Optimizely.h

PHP

Optimizely.php

Python

optimizely.py

Ruby

optimizely.rb


Did this page help you?