Web analytics for Codex and OpenAI agents

OpenAI's agent ecosystem is more fragmented than Anthropic's MCP story. Claude Code, Claude Desktop, and Cursor all use MCP as a standard protocol for tool access. OpenAI has Codex CLI (which adopted MCP), the Assistants API (which has its own function calling format), and custom agent frameworks like Agents SDK, each with different integration patterns. This post covers all three paths.

For Codex CLI, connecting web analytics works the same as Claude Code or Cursor: add the server config and your agent gets 42 tools for traffic, sources, funnels, and events. For custom OpenAI agents that don't speak MCP, Lodd has a REST API at api.lodd.dev/v1/ with 28 endpoints and an OpenAPI spec. Both approaches are free up to 2,500 events per month.

How do you set up Lodd in Codex CLI?

Codex CLI reads MCP server configuration from a JSON config file, similar to Claude Code. Add Lodd to your MCP config:

{
  "mcpServers": {
    "lodd": {
      "command": "npx",
      "args": ["-y", "@lodd/mcp-server"],
      "env": {
        "LODD_API_KEY": "your_api_key"
      }
    }
  }
}

Get an API key by signing up at lodd.dev, verifying your email with a 6-digit code, and creating a key from the dashboard. The key starts with ca_ and is shown once.

After adding the config, restart Codex. The 42 MCP tools become available and you can ask questions like "how's traffic today" or "which sources drive the most conversions." The agent picks the right tool and returns structured data.

You'll also need the tracking script on your site. Create a site in the Lodd dashboard, copy the script tag (about 2KB), and add it to your HTML <head>. Tracking starts automatically, no cookies involved.

How do you use the REST API for custom OpenAI agents?

If you're building a custom agent with the OpenAI Assistants API, Agents SDK, or any framework that doesn't support MCP natively, Lodd's REST API gives you the same data through standard HTTP requests. The base URL is https://api.lodd.dev/v1, authenticated with an X-API-Key header.

Here's a curl example to get a traffic snapshot:

curl -H "X-API-Key: ca_your_key_here" \
  "https://api.lodd.dev/v1/sites/example.com/analytics?period=7d"

That returns visitors, pageviews, bounce rate, average duration, and comparison to the previous period. The full API has 28 endpoints covering analytics, breakdowns, funnels, events, performance, actors, annotations, and links. The OpenAPI spec documents all of them, and you can import it directly into your agent's function definitions.

Rate limits are 1,000 requests per hour per key, with standard X-RateLimit headers in every response. For most agent use cases this is more than enough, since analytics queries are infrequent compared to, say, database operations.

How do you wire Lodd into an OpenAI Assistants API agent?

The Assistants API uses function calling for tool access. You define functions that describe what the tool does, and the assistant decides when to call them based on the conversation. To add Lodd analytics, you'd register functions like get_traffic_snapshot, get_top_pages, and get_traffic_sources, then implement them as HTTP calls to the REST API.

A simplified version of the pattern:

// Define the function for the assistant
const tools = [{
  type: "function",
  function: {
    name: "get_traffic_snapshot",
    description: "Get today's traffic compared to yesterday",
    parameters: {
      type: "object",
      properties: {
        site: { type: "string", description: "Domain, e.g. example.com" }
      },
      required: ["site"]
    }
  }
}];

// Handle the function call
async function handleToolCall(name, args) {
  if (name === "get_traffic_snapshot") {
    const res = await fetch(
      `https://api.lodd.dev/v1/sites/${args.site}/snapshot`,
      { headers: { "X-API-Key": process.env.LODD_API_KEY } }
    );
    return await res.json();
  }
}

You could register all 28 API endpoints as functions, but in practice most agents only need 5-8 of the core analytics tools. The OpenAPI spec makes it straightforward to generate the function definitions programmatically if you want the full surface.

What about the @lodd/node SDK for server-side tracking?

If your OpenAI agent runs server-side (which most do), the @lodd/node SDK lets you track events from your agent's backend. This is useful for tracking agent actions, API calls, or any server-side activity that doesn't happen in a browser.

import { Lodd } from "@lodd/node";

const lodd = new Lodd({
  apiKey: process.env.LODD_API_KEY,
  siteId: process.env.LODD_SITE_ID,
});

// Track when your agent completes a task
lodd.track("agent_task_complete", {
  task_type: "code_review",
  duration_ms: 4200,
});

// Track API usage
lodd.track("api_call", {
  endpoint: "/v1/chat/completions",
  tokens: 1847,
});

// Graceful shutdown
await lodd.close();

The SDK batches events and flushes them automatically. Combined with the browser tracking script on your frontend, you get a unified view of both client-side and server-side activity through the same analytics tools. Your agent can then query "show me api_call events from the last hour" and see server-side data alongside pageviews.

How does the MCP approach compare to the REST API approach?

MCP (Codex CLI)REST API (custom agents)
SetupJSON config file, restart CLIHTTP calls in your agent code
AuthenticationAPI key in env varAPI key in X-API-Key header
Tool discoveryAutomatic, agent sees all 42 toolsManual, you define which endpoints to expose
Response formatCompact JSON (shortened keys)Verbose JSON (full key names)
Token cost~55 tokens per snapshot~120 tokens per snapshot (longer keys)
Rate limitShared 1,000/hr per keySame

MCP is simpler if your tool supports it. Codex CLI does, so use that. For anything custom, the REST API gives you the same data with more control over which endpoints you expose and how you handle responses.

What are the limitations?

No dashboard. Lodd was built for agents and APIs, not browser-based visualisation. That said, anyone on your team can ask Claude Desktop "how's our traffic this week" and get a plain-English summary, so the need for a visual dashboard is less clear-cut than it used to be.

The MCP ecosystem outside of Anthropic's tools is still maturing. Codex CLI's MCP support works, but it's newer than Claude Code's, and you may encounter rough edges. The REST API is the safer bet for production custom agents because it's just HTTP and doesn't depend on any protocol implementation.

OpenAI's Agents SDK doesn't natively support MCP at the protocol level the way Claude Code does. You can add MCP support through community adapters, but the REST API is the more straightforward integration path for Agents SDK builds.

Free up to 2,500 events per month, €9.99/month for 100,000. All tools and API endpoints available on both tiers. Hard stop at the limit with a 402 response, not a surprise bill.