Track Event

Tracks a conversion event (in other words, an action a user takes) for a user. Logs an error message if the specified event key doesn't match any existing events.

Version

SDK 3.7 and higher

Description

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.

Parameters

This table lists the required and optional parameters for the Track Event method.

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.

event_tags
optional

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.

Returns

This method sends conversion data to Optimizely. It doesn't provide return values.

Example

user = optimizely.create_user_context("user123", {"logged_in": True})

tags = {
  "category": "shoes",
  "purchase_count": 2,
}

user.track_event("my_purchase_event_key", tags)

Side effects

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

Functionality

Description

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 paragraph Events are always on in the introduction of Events: Tracking clicks, pageviews, and other visitor actions.

Important!

  • This method won't 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 TRACK notification listener.

Important! This method won't call the TRACK notification listener when the specified event key is invalid.

Source files

The language/platform source files containing the implementation for Python is optimizely.py.


Did this page help you?