> ## Documentation Index
> Fetch the complete documentation index at: https://confidence.spotify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Send Product Events to Confidence

> Send a product event from your app with a Confidence SDK, create its event definition, verify that it arrives, and use it in metrics.

By the end of this guide, your web app sends a `checkout-completed` event to Confidence,
Confidence stores it, and you can build metrics on it.

Events are the main way to record data for [Confidence Cloud](/docs/start/confidence-cloud).
Event tracking has two parts:

1. **Send events to Confidence.** Your app calls `track` on a Confidence SDK.
2. **Set up an event schema.** Confidence stores an event only when an event definition with a
   matching name and schema exists.

You can define the schema in advance, or send events first and then review and create the event
from the schema that Confidence detects. After you create the event, Confidence records the events.

The guide has these steps:

1. [Define the event schema](#define-the-event-schema), or skip this step and create the event later.
2. [Send events from your app](#send-events-from-your-app).
3. [Create the event and verify arrival](#create-the-event-and-verify-arrival).
4. [Use events in metrics](#use-events-in-metrics).

Each step shows how to do it with AI first, then in the Confidence app.

<Tip>
  **Do it with AI.** Connect the [Confidence MCP servers](/docs/guides/build-with-an-ai-assistant)
  to your AI assistant, then set up the event with one prompt:

  ```text theme={null}
  Create a Confidence event definition called "checkout-completed" with a string
  field context.targeting_key that references the User entity, a double field
  value, a string field currency, and an integer field item_count. Then show me
  how to send it from my web app with the OpenFeature provider.
  ```
</Tip>

## Before You Begin

* You need a [Confidence](https://app.confidence.spotify.com) account.
* You need the client secret of a [client](/docs/capabilities/flags/clients). Events authenticate
  with the same client credentials that the SDK uses to resolve flags. To create a client, see
  [Create a client](/docs/guides/add-a-feature-flag#create-a-client).
* You need a Confidence SDK that supports `track`. This guide uses the
  [JavaScript (Web)](/docs/reference/sdks/client/javascript) OpenFeature provider. For other SDKs,
  see [SDK support](/docs/reference/sdks/events#sdk-support).
* For the AI path, [set up Confidence for your AI assistant](/docs/guides/build-with-an-ai-assistant).
  The Flags MCP server manages event definitions and reports event usage.

## Define the Event Schema

An event definition names an event type and describes its payload with a schema. The event name
in `track` must match the definition name. Names use lowercase letters, digits, and hyphens, and
are 4 to 63 characters long.

Define `checkout-completed` with these fields:

* `context.targeting_key`: a string that identifies the user, with semantic type Entity
* `value`: a number
* `currency`: a string
* `item_count`: an integer

Every event needs at least one entity field. Without one, Confidence generates no fact table for
the event.

To skip this step, send the event first and create it from the detected schema in
[Create the Event and Verify Arrival](#create-the-event-and-verify-arrival).

<Tabs>
  <Tab title="With AI">
    ```text theme={null}
    Create a Confidence event definition called "checkout-completed" with a
    string field context.targeting_key that references the User entity, a
    double field value, a string field currency, and an integer field
    item_count.
    ```

    The assistant uses the Flags MCP tool `createEventDefinition`. To check existing definitions
    first, it uses `listEventDefinitions`.
  </Tab>

  <Tab title="In the App">
    <Steps>
      <Step title="In the sidebar, select Events and click Create">
        The **Create event** dialog opens.
      </Step>

      <Step title="Enter the event name">
        Enter `checkout-completed`.
      </Step>

      <Step title="Edit the schema">
        Add the fields. Set `context.targeting_key` to type String with semantic type Entity.
      </Step>
    </Steps>
  </Tab>
</Tabs>

## Send Events from Your App

Call `track` on the same OpenFeature client that you use for flags. Tracking requires
`@openfeature/web-sdk` 1.3.0 or later and `@spotify-confidence/openfeature-web-provider` 0.3.22
or later.

```javascript theme={null}
import { OpenFeature } from '@openfeature/web-sdk';
import { createConfidenceWebProvider } from '@spotify-confidence/openfeature-web-provider';

const provider = createConfidenceWebProvider({
  clientSecret: 'your-client-secret',
  region: 'eu', // or 'us'; omit to use the global endpoint
  timeout: 1000,
});

await OpenFeature.setContext({ targetingKey: 'user-123' });
await OpenFeature.setProviderAndWait(provider);

const client = OpenFeature.getClient();

client.track('checkout-completed', {
  value: 42.5,
  currency: 'SEK',
  item_count: 3,
});
```

The provider adds the evaluation context under a `context` field and renames `targetingKey` to
`targeting_key`. The tracking details become top-level fields. See
[Event payload](/docs/reference/sdks/events#event-payload).

`track` returns immediately and doesn't report whether Confidence accepted the event. The SDK
queues events in memory and sends them in batches. See
[Batches and delivery](/docs/reference/sdks/events#batches-and-delivery).

For Swift, Kotlin, and Flutter examples, see [Track events](/docs/reference/sdks/events).

## Create the Event and Verify Arrival

If you skipped the schema step, Confidence rejects the events, detects a schema from the payload,
and lists the event in the **Events** table as **Sent but not stored**. Create the event so that
Confidence stores events of this type from then on.

<Tabs>
  <Tab title="With AI">
    ```text theme={null}
    Show me the hourly usage of the "checkout-completed" event for the last day.
    ```

    The assistant uses the Flags MCP tool `queryEventsUsage`, which returns hourly publish and
    validation failure counts for the last 1 to 7 days. `getEventDefinition` returns the schema
    and publish count.

    No MCP tool creates an event from a detected schema. To create the event with AI, ask the
    assistant to call `createEventDefinition` with the full schema. To add fields to an existing
    event, it uses `updateEventDefinition`. You can't change the type of an existing field.
  </Tab>

  <Tab title="In the App">
    <Steps>
      <Step title="Go to Events">
        Each event type shows a status icon for when it last received data.
      </Step>

      <Step title="Create the event if needed">
        For an event marked **Sent but not stored**, click the outlined **Create** in its
        row. Review the schema, set at least one String field to semantic type Entity, and click
        **Create**.
      </Step>

      <Step title="Open the event and check the Usage chart">
        The chart shows hourly counts of published events and validation failures.
      </Step>
    </Steps>
  </Tab>
</Tabs>

Watch for these problems:

* **Missing fields.** Confidence drops fields that aren't in the schema, and the event page shows a
  warning. Click **Update** in the warning to add the fields. Confidence doesn't recover values it dropped before the update.
* **Validation failures.** Confidence rejects events with wrong field types. You can't change a
  field's type after you save it. Create a new event definition instead.

## Use Events in Metrics

On Confidence Cloud, Confidence creates a fact table for each event that references an entity.
Numeric fields become measurements, and other fields become dimensions. Build a metric on the fact
table with [Create your first metric](/docs/guides/create-your-first-metric).

On Warehouse Native, also create an event connection so that Confidence writes event data to your
warehouse. The Flags MCP tool `createEventConnection` creates it. See
[Event connectors](/docs/reference/api/how-to-guides/connectors/events).

## Related Resources

* [Track events](/docs/reference/sdks/events): SDK calls, payload format, and schema rules
* [Fact tables](/docs/capabilities/metrics/fact-tables): turn event data into metric sources
* [MCP servers](/docs/reference/agent/mcp-servers): event tools on the Flags MCP server
* [Confidence Cloud](/docs/start/confidence-cloud): how data reaches the managed warehouse
