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 v1.0
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.
The Track function can be used to track events across multiple experiments. It will be counted for each experiment only if Is Feature Enabled or Activate has previously been called for the current user.
As long as the event key is valid (the key appears in the datafile) Optimizely will track events. Use attributes to track events for segmentation purposes.
Important
The Results page only shows events that are tracked after Is Feature Enabled or Activate has been called. If you do not see results on the Results page, make sure that you are evaluating the feature flag before tracking conversion events.
Track events across platforms
For offline event tracking and other advanced use cases, you can also use the Events API.
You can use any of our SDKs to track events, so you can run experiments that span multiple applications, services, or devices. All of our SDKs have the same audience evaluation and targeting behavior, so you'll see the same output from feature experiment evaluation and tracking as long as you are using the same datafile and user IDs.
For example, if you're running feature experiments on your server, you can evaluate them with our Go, Python, Java, Ruby, C#, Node, or PHP SDKs, but track user actions client-side using our JavaScript, Objective-C or Android SDKs.
If you plan to use multiple SDKs for the same project, make sure that all SDKs share the same datafile and user IDs.
For more information, see Multiple languages.
Parameters
This table lists the required and optional parameters for the Go SDK.
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. |
userContext required | entities.UserContext | Holds information about the user, such as the userID and the user's attributes. Important: userID must match the user ID provided to Activate or Is Feature Enabled. |
eventTags 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 does not provide return values.
Example
attributes := map[string]interface{}{
"DEVICE": "iPhone",
"hey": 2,
}
user := entities.UserContext{
ID: "userId",
Attributes: attributes,
}
err := optlyClient.Track("add_to_cart", user)
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 | Calling 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. |
Impressions | Track does not trigger impressions. |
Source files
The language/platform source files containing the implementation for Go is Go.
Updated over 2 years ago