Disclaimer: This website requires JavaScript to function properly. Some features may not work as expected. Please enable JavaScript in your browser settings for the best experience.

Optimizely will be sunsetting Full Stack Experimentation on July 29, 2024. See the recommended Feature Experimentation migration timeline and documentation.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Track

This topic describes the Track method that tracks a conversion event or logs an error message if the specified event key does not match any existing events.

Tracks a conversion event. Logs an error message if the specified event key does not match any existing events.

Version

SDK v3.0, v3.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 an impression was sent as a result of the Activate or Is Feature Enabled method being called.

The attributes passed to Track are only used for results segmentation.

Parameters

This table lists the required and optional parameters for the PHP SDK.

ParameterTypeDescription
eventKey
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.
userId
required
stringThe ID of the user associated with the event being tracked.

Important: This ID must match the user ID provided to Activate or Is Feature Enabled.
attributes
optional
mapA map of custom key-value string pairs specifying attributes for the user that are used for results segmentation. Non-string values are only supported in the 3.0 SDK and above.
eventTags
optional
mapA 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] (include-event-tags#reserved-tag-keys).

Returns

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

Example

// Track a conversion event for the provided user with attributes
$optimizelyClient->track($eventKey, $userId, $attributes);



var attributes = {
  device: 'iPhone',
  lifetime: 24738388,
  is_logged_in: true,
};

var tags = {
  category: 'shoes',
  count: 2,
};

optimizelyClient.track('my_purchase_event_key', 'user_123', attributes, tags);

Side effects

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

FunctionalityDescription
ConversionsCalling this method records a conversion and attributes it to the variations that the user has seen.

Full Stack 3.x supports retroactive metrics calculation. 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 paragraph Events are always on in the introduction of Events: Tracking clicks, pageviews, and other visitor actions.

Important!
- 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.
ImpressionsTrack does not trigger impressions.
Notification ListenersAccessing this method triggers a call to the TRACK notification listener.

Important! This method will not call the TRACK notification listener when the specified event key is invalid.

Source files

The language/platform source files containing the implementation for PHP is Optimizely.php.