Blog / Guide

How to integrate OttimAI with your product

To track a journey’s metrics, OttimAI needs two connections: one to your coding agent, which adds the tracking events to your code, and one to your product, which sends those events once it’s live. Here is how to set up each, and what to do if you don’t use a coding agent.

Updated November 2026 · 6 min read

Before you start

Tracking starts from a journey your team has approved in OttimAI. Approving the journey approves its metrics too: the tracking plan holds the events each step’s metrics read, and nothing else. The metrics explains what each one measures.

Open the journey and click Start tracking. A card opens in the chat beside the journey and walks you through the setup, one step at a time. The steps below follow that card.

The three keys

Each connection has its own key. You create them in OttimAI, on Start tracking or on the Integrations page, and each one shows only once, when it is created.

Agent key

  • oa_…

For your coding agent. It lets the agent read your workspace’s approved journeys and tracking plans, and report the pull request it opens. It can’t change a journey, see your research or chats, or send events. Each developer creates their own.

Secret key

  • ok_…

Also called the production key, or API key. For your servers: it lets your product send events to OttimAI. Save it in the production environment as OTTIMAI_API_KEY, never in code.

Public key

  • op_…

For web pages and mobile apps. It can only send events and is rate-limited, so it is safe to ship in client code.

With a coding agent

Your coding agent, such as Claude Code, does the integration: it reads the tracking plan, adds the events where they happen in your code and opens a pull request. You review it and merge it.

1. Connect your coding agent

Your coding agent needs two things to work with OttimAI:

  • The OttimAI skill. A text file, SKILL.md, that tells the agent what OttimAI is, how to add the tracking events and which rules to follow, such as never sending message text or personal data. It holds no key.
  • OttimAI’s MCP server. The API your coding agent uses to talk to OttimAI. Through it, the agent reads the journey and its tracking plan, and reports the pull request it opens.

The agent key connects the MCP server to your workspace. Click Create agent key: the card shows two commands with the key already in them. Run them in a terminal, not in your agent’s chat, so the key never enters the conversation.

For Claude Code, this adds the MCP server for you, on this computer:

claude mcp add --scope user --transport http ottimai https://app.ottimai.com/api/v1/mcp --header "Authorization: Bearer oa_…"

Then, in your project, this adds the skill:

npx skills add https://app.ottimai.com/skill/SKILL.md

For another coding agent, add an MCP server over HTTP with the URL https://app.ottimai.com/api/v1/mcp and the header Authorization: Bearer oa_…. Other agents, on the card, shows both.

Start your coding agent again and ask it to list your OttimAI journeys. The card moves on by itself at the agent’s first call.

2. Add the production key

Your product needs its own key to send events to OttimAI. Click Create key: the card shows a secret key once. Save it in your production environment as OTTIMAI_API_KEY, then click I’ve saved it. The code your coding agent writes reads the key from there, so the pull request never contains it.

If your web or mobile code sends events too, create a public key on Integrations and put it in the app’s public configuration.

3. Ask for the pull request

The card shows a request to paste into your coding agent, with the journey’s title and id:

Use the OttimAI skill to add tracking for the journey “Onboarding” (…): pull its tracking plan, add each event where it happens in the code, and open a pull request.

The agent pulls the tracking plan, finds where each event happens, adds one call per event with the OttimAI SDK, opens a pull request and reports it to OttimAI. It never merges the pull request.

4. Review and merge

Review the pull request as you would any other. Its description lists each event, the step it belongs to, the file and function where it fires and the properties it carries, plus anything the agent left out and why. Merge it and deploy. Then click I’ve merged it, or wait: tracking goes live with the first event.

From your second journey on, the coding agent is connected and the production key exists, so Start tracking begins at step 3.

Without a coding agent

You can add the same calls by hand. Your product sends its events with the OttimAI SDK and an API key, as above. What a coding agent does through the MCP server, reading the plan and reporting the event map, you do with two requests from a terminal.

1. Create the keys

On Integrations, create an agent key: you use it to read the tracking plan. Then create a secret key and save it in production as OTTIMAI_API_KEY. If your web or mobile code sends events, create a public key too.

2. Read the tracking plan

The plan lists, for each step, the events to send and the properties each one may carry. Ask for it with your agent key and the journey’s id, the last part of the journey’s link:

curl https://app.ottimai.com/api/v1/mcp \
  -H "Authorization: Bearer oa_…" \
  -H "Accept: application/json, text/event-stream" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "id": 1, "method": "tools/call",
       "params": {"name": "get_tracking_plan",
                  "arguments": {"journey_id": "<journey id>"}}}'

Each metric on the journey map lists its events too. The plan adds what the map doesn’t show: each event’s properties, the plan_id, and needs_map, the events that more than one step reads.

3. Add the events

Install the SDK, ottimai on npm and PyPI, and add one track() call for each event in the plan, where the thing has happened: after a save succeeds, not where it was attempted.

npm install ottimai

import { track } from "ottimai";

track("profile_saved", { field_count: 4 }, { userId: user.id, sessionId });
pip install ottimai

import ottimai

ottimai.track("profile_saved", {"field_count": 4}, user_id=user.id, session_id=session_id)
  • On a server, the SDK reads the secret key from OTTIMAI_API_KEY. In web and mobile code, pass the public key instead: init({ apiKey }).
  • Pass the user id to the SDK, which hashes it before it leaves your product. Never send it as a property, and never send names, emails or message text.
  • Send only the properties the plan lists. Their values are short labels, numbers or booleans.
  • On the events of an AI conversation turn, also pass the conversation id: conversationId, or conversation_id in Python.
  • Scripts and serverless functions can end before the events are sent: call flush() before they return.

In another language, send one OpenTelemetry log record per event with the official OpenTelemetry SDK, with the event’s name as the record’s event name and the user id, hashed with SHA-256, in user.id. These two settings point it at OttimAI:

OTEL_EXPORTER_OTLP_ENDPOINT=https://app.ottimai.com/api/v1/ingestion
OTEL_EXPORTER_OTLP_HEADERS=authorization=Bearer ${OTTIMAI_API_KEY}

4. Report the event map

An event in needs_map, such as step_completed, is read by more than one step, so OttimAI needs to know which step each call stands for. Send it under a name of your own that says which step it is, such as profile_saved, and tell OttimAI what each name stands for, with the plan’s plan_id and the pull request’s link:

curl https://app.ottimai.com/api/v1/mcp \
  -H "Authorization: Bearer oa_…" \
  -H "Accept: application/json, text/event-stream" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "id": 1, "method": "tools/call",
       "params": {"name": "report_pull_request",
                  "arguments": {
                    "plan_id": "<plan id>",
                    "pr_url": "https://github.com/your-org/your-app/pull/12",
                    "event_map": {"profile_saved": [
                      {"step_id": "step-2", "event": "step_completed"}]}}}}'

OttimAI checks the map against the plan and lists every problem at once. An event that only one step reads needs no entry: send it under its plan name.

5. Merge and deploy

Merge and deploy as usual. On Start tracking, click I’ve merged it, or wait: tracking goes live with the first event.

Check that events arrive

Each metric shows No data until its events arrive, and goes live once every event its formulas read has arrived.

OttimAI keeps only the events in the plan, with only the properties its metrics read. Anything else is dropped and counted by name under Dropped events, on Integrations, so you can spot a call that doesn’t match the plan. Nothing is sent automatically: no URLs, headers or request details leave your product, only the events you add.