HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityOptimizely GitHubOptimizely NuGetLog In

Track Event

Describes the track event method, which tracks a conversion event in Optimizely Feature Experimentation.

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

Version

1.0.0-beta or higher

Description

Use this method to track events across multiple flag rules for a user. You should only make one track call per conversion (user action), even if many rules measure 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.

ParameterTypeDescription
eventKey
required
StringThe key of the event to be tracked. This key must match the event key provided when you created the event in the Optimizely app.
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.

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 Feature Experimentation. It does not provide return values.

Example

var attributes = <String, dynamic>{};
attributes["logged_in"] = true;
var user = await flutterSDK.createUserContext("user123", attributes);

var tags = <String, dynamic>{};
tags["category"] = "shoes";
tags["purchase_count"] = 2;

await user!.trackEvent("my_purchase_event_key", tags);

Side effects

The table lists other Optimizely Feature Experimentation functionality using this method may trigger.

FunctionalityDescription
ConversionsCalling this method records a conversion and attributes it to the variations the user saw.

You can create metrics on this conversion event and add metrics to experiments, even after the system tracked the conversion.

For more information, see the support documentation on Event Tracking.

Important!

- This method will not track events when the specified event key is invalid.
- Changing the traffic allocation of running experiments affects how the system records conversions and attributes variations to users.
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 Flutter Android is at Optimizely.java and for Flutter IOS is at OptimizelyClient.swift.