Events

Events and impressions play a crucial role in feature flag systems like FlagSync, serving as the foundation for tracking user interactions, gathering data, and measuring the impact of features and Experiments.

By capturing relevant events, such as feature usage, user actions, and conversions, FlagSync enables teams to gain insights into feature performance and experiment outcomes.

Events

Events are manually sent to FlagSync when the track function is called from the SDK. They are critical for tracking how feature rollouts affect user behavior. And apart from providing real-time insights, events can be linked to metrics and experiments.

Impressions

Flag impressions are automatically sent to FlagSync when the flag function is called from the SDK; this function returns the applicable flag variant for the user context. Impressions are often used in conjunction with metrics to calculate the success criteria of experiments.


track

When you call the track function to submit events, you can optionally provide key-value properties or a numeric eventValue.

We'll discuss the differences below, and when you might choose one over the other.

const eventKey: string;
const eventValue: number | null | undefined;
const properties: Record<string, any> | null | undefined;

client.track(eventKey, eventValue, properties);

Example (Page Load Time)

Say you're releasing a new feature and want to ensure page load times have not degraded. Or, you're testing some optimizations and want to validate that they've had a positive effect.

We'll use the eventValue for this type of event.

First, you'll start by submitting an Event.

client.track('page_load_time', 1.42);

Later on, you may create a Metric called "Average Page Load Time" from the page_load_time event to harvest the values.

Finally, you may link this metric with a feature flag in an Experiment to prove your hypothesis.

Learn about Metrics to see how they work alongside events.

Example (Purchase Events)

Say you're releasing a feature that you believe will increase the purchase amounts of your customers. Or, you're testing different discount amounts that you believe will increase the overall number of purchases.

You'll most likely want to track purchase events within your application along with the item purchased.

We'll use properties for this type of event.

const item: Product = { 
  productId: '0x123', 
  price: 49.99,
  discount: 0.20,
  isReturnCustomer: true,
  ...
}

client.track('purchase_event', null, item);

Later on, you may create a Metric called "Average Purchase Price per User" to harvest the price of items submitted with the purchase_event.

Or, you may create a Metric called "Count of Discounts" to track the discount value.

Finally, you may link these metrics with a feature flag in an Experiment to prove your hypothesis.

Learn about Metrics to see how they work alongside events.


flag

A flag impression is automatically registered whenever the flag function is called from the SDK. This function returns the applicable flag variant value for the requesting user context.

const flagKey: string;
const value = client.flag<string>(flagKey);

Say you have a flag, register-button-copy, that serves the following variants:

  1. Register

  2. Join Now

  3. Sign Up

When the flag value is retrieved with the flag function, an impression is registered. This notifies FlagSync that User ABC was served Register, Join Now, or Sign Up.

const value = client.flag<string>('register-button-copy');

Last updated