← Blog

How to add metric tracking to your app with AI

Adding a metric sounds like a one-line change. But you also need to create the metric, keep its key out of your code, find the right place to record the event, and make sure a failed request can't break your app. An AI coding tool can do most of this, as long as it has the right access and clear instructions.

This guide shows how to do it with OpenCode or Claude Code, using Umlogger's MCP server and free skill.

What the MCP server and skill do

  • The MCP server gives your AI tool access. If you allow it, your AI tool can create a metric and get its ingest key.
  • The Umlogger skill tells it how to do the job well. It covers choosing the right metric type, protecting keys, and keeping your app working if tracking fails. It doesn't give your AI tool access to your account.

1. Install the skill

Read the skill on GitHub, then run the command for your tool. It installs the skill for all your projects.

OpenCode

npx skills add hbruce/umlogger-skill --skill umlogger --global --agent opencode

Claude Code

npx skills add hbruce/umlogger-skill --skill umlogger --global --agent claude-code

See the install guide for other options and how to turn off the installer's anonymous usage data.

2. Connect Umlogger

For Claude Code, run the command below in your project. Then start Claude Code, run /mcp, choose umlogger, and sign in. For OpenCode, follow the OpenCode steps.

claude mcp add --transport http umlogger https://data.umlogger.com/mcp

When your browser asks you to approve the connection, check the details. If you want AI to set up tracking without you copying a key:

  1. Choose Read and write.
  2. Tick Let this app get ingest keys for metrics you own.

Both are off by default. An ingest key can only add data to its metric, but it keeps working after you disconnect the app. Your AI provider may also receive it, and it may appear in your tool's history. If you'd rather not share keys, leave the box unticked and copy the key yourself. If you've already connected, disconnect the app in Settings and connect it again to change its access.

3. Ask for the result you want

Say what happened, what counts as success, and that you want the whole job done:

Use Umlogger to track completed signups in this project.
Count a signup only after the new account is saved.
Create the metric, save its key safely, add the code and tests, then tell me what's left to do for production.
Don't send any test data.

“After the new account is saved” is the most important part. If you record a signup when someone clicks the button, failed signups count too.

4. Review the changes

The code will be different in every project. Before you accept the changes, check these:

  • The metric type is right. Use count for events, such as signups, and send 1 for each one. Use value for measurements, such as response time.
  • Only successful events are recorded. Also check whether retries or repeated webhooks could count an event twice. Umlogger doesn't remove duplicates.
  • The key isn't in your code. The code should read it from an environment variable, and Git must ignore the file it's saved in. It shouldn't appear in browser code or logs either.
  • Tracking can't break your app. Requests need a short timeout. If tracking fails or the key is missing, your app should keep working.
  • Tests don't use your real metric. They should use a fake request instead of sending data to Umlogger.

The skill covers all of this, but its instructions aren't security controls. AI can still make mistakes, so review its work.

5. Set up production and check it

A key saved on your computer isn't automatically available in production. Add it to your hosting provider's secrets too. Your AI tool can help if it has access and you agree.

After you deploy, trigger one real signup and check that its value appears in Umlogger. Your app then logs data itself, even when your AI tool isn't running.

If a key leaks

If an app you no longer trust may have the key, disconnect it first. Otherwise, it may be able to get the new key too. If the app uses an access token, revoke the token instead. Then choose Replace key on the metric's page. The old key stops working immediately, so update it everywhere you use it. Your existing data stays the same.

What you can do next

Once you have some data, ask your AI tool to compare two periods or look for deploys before a change. See a full example, from adding a metric to investigating a drop. Or try our prompts for SaaS metrics.