Getting Started

Welcome to Agent Analytics! This guide will walk you through creating an account, setting up your first site, installing the tracking snippet, and verifying that everything is working correctly. Whether you're a human developer or an AI agent, you'll be up and running in just a few minutes.

Overview

Agent Analytics is a privacy-first web analytics platform designed for both human developers and AI agents. It provides essential insights about your website traffic without compromising user privacy. No cookies, no tracking across sites, and full GDPR compliance out of the box.

The platform offers multiple integration methods to suit your workflow:

  • Web Dashboard: Visual interface for managing sites and viewing analytics
  • REST API: Programmatic access for automation and integrations
  • MCP Server: Direct integration for AI agents via the Model Context Protocol

Step 1: Create an Account

First, you'll need to create an account. You can sign up through the dashboard at statscontext.com/signup, or programmatically via the API.

Via API (curl)

To create an account programmatically, send a POST request to the signup endpoint with your email:

Create Account
curl -X POST https://api.statscontext.com/api/auth/signup \  -H "Content-Type: application/json" \  -d '{
    "email": "your-email@example.com",
    "name": "My Agent Account"
  }'

The response will include your account details and an API key. Save this key securely - it will not be shown again:

Response
{
  "account": {
    "id": "acc_abc123def456",
    "email": "your-email@example.com",
    "name": "My Agent Account"
  },
  "api_key": "aa_live_xxxxxxxxxxxxxxxx",
  "message": "Store this API key securely. It will not be shown again."
}

Via Dashboard

Alternatively, visit statscontext.com/signup to create your account through the web interface. After signing up, you'll be automatically logged in and redirected to your dashboard.

Step 2: Create a Site

Once you have an account, create a site to track analytics. Each site represents a website or web application you want to monitor. You'll need the domain name (without protocol) for the site you want to track.

Via API (curl)

Use your API key from Step 1 to create a site:

Create Site
curl -X POST https://api.statscontext.com/api/sites \  -H "Content-Type: application/json" \  -H "Authorization: Bearer aa_live_xxxxxxxxxxxxxxxx" \  -d '{
    "domain": "example.com",
    "name": "My Website"
  }'

The response includes your site details, a tracking snippet, and the site.id - a unique identifier you'll use in the tracking snippet and API queries:

Response
{
  "site": {
    "id": "site_xyz789",
    "account_id": "acc_abc123def456",
    "domain": "example.com",
    "name": "My Website",
    "created_at": "2026-02-11T12:05:00Z"
  },
  "snippet": "<script defer data-site-id=\"site_xyz789\" src=\"https://api.statscontext.com/tracker.js\"></script>"
}

Via Dashboard

From your dashboard, click "Add Site" and enter your domain name. The dashboard will generate your tracking snippet automatically and display your site ID for API access.

Step 3: Install the Tracking Snippet

Now that you have a site created, you need to add the tracking snippet to your website. This lightweight JavaScript snippet collects page views and events without impacting your site's performance.

Standard HTML

Add this script tag to the <head> section of your HTML pages. Replace YOUR_SITE_ID with the site ID from Step 2:

HTML Tracking Snippet
<script
  defer
  data-site-id="YOUR_SITE_ID"
  src="https://api.statscontext.com/tracker.js"
></script>

The defer attribute ensures the script loads asynchronously without blocking page rendering, providing zero performance impact on your site.

Next.js (App Router)

For Next.js applications using the App Router, add the tracking script to your root layout using the Script component:

app/layout.tsx
import Script from "next/script";export default function RootLayout({  children,}: {  children: React.ReactNode;}) {  return (    <html lang="en">      <body>        {children}        <Script          src="https://api.statscontext.com/tracker.js"          data-site-id="YOUR_SITE_ID"          strategy="afterInteractive"        />      </body>    </html>  );}

React (Create React App, Vite)

For React applications, add the script to your public/index.html file in the <head> section:

public/index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Your App</title>
    <script
      defer
      data-site-id="YOUR_SITE_ID"
      src="https://api.statscontext.com/tracker.js"
    ></script>
  </head>
  <body>
    <div id="root"></div>
  </body>
</html>

Script Behavior

Once installed, the tracking script will automatically:

  • Track page views on initial load and navigation (supports SPAs)
  • Collect referrer information to understand traffic sources
  • Respect Do Not Track (DNT) browser settings
  • Work without cookies or local storage
  • Handle hash-based and history-based routing automatically

For advanced configuration options, custom event tracking, and SPA integration details, see the Tracking Snippet documentation.

Step 4: Verify It Works

After installing the tracking snippet, verify that it's working correctly. There are two methods to confirm your setup:

Check Network Requests

Open your browser's Developer Tools (F12 or right-click → Inspect), navigate to the Network tab, and visit your website. Look for a request to:

text
https://api.statscontext.com/api/event

If you see this request with a 200 OK status, your tracking is working correctly. The request should be sent as a POST with your page view data.

Check the Dashboard

Visit your dashboard at statscontext.com/dashboard, select your site, and you should see your page view appear within a few seconds. The dashboard updates in real-time, so you can watch your analytics data come in as you browse your site.

If you don't see any data after a minute or two:

  • Verify your site ID is correct in the tracking snippet
  • Check the browser console for any JavaScript errors
  • Ensure your ad blocker isn't blocking the tracking script
  • Confirm the domain in your site settings matches your website's domain

Step 5: Query Your Analytics

Now that you're collecting data, you can query your analytics programmatically. This is especially useful for AI agents, integrations, or custom dashboards.

Via API (curl)

Retrieve analytics data for your site using the stats endpoint. Replace YOUR_SITE_ID with your site ID and use your authentication token:

Get Site Statistics
curl "https://api.statscontext.com/api/sites/YOUR_SITE_ID/stats?period=7d&metric=all" \  -H "Authorization: Bearer aa_live_xxxxxxxxxxxxxxxx"

The response includes comprehensive analytics data:

Response
{
  "pageviews": 1247,
  "visitors": 423,
  "sessions": 567,
  "bounce_rate": 42.3,
  "avg_duration": 185000,
  "top_pages": [
    { "page": "/", "pageviews": 543 },
    { "page": "/blog", "pageviews": 234 },
    { "page": "/about", "pageviews": 156 }
  ],
  "referrers": [
    { "referrer": "google.com", "count": 387 },
    { "referrer": "twitter.com", "count": 142 },
    { "referrer": "(direct)", "count": 718 }
  ],
  "countries": [
    { "country": "US", "visitors": 543 },
    { "country": "GB", "visitors": 123 }
  ],
  "devices": [
    { "device_type": "desktop", "visitors": 734 },
    { "device_type": "mobile", "visitors": 456 }
  ],
  "browsers": [
    { "browser": "Chrome", "visitors": 687 },
    { "browser": "Safari", "visitors": 312 }
  ],
  "custom_events": [],
  "timeseries": [
    { "date": "2026-02-04", "pageviews": 178, "visitors": 62 },
    { "date": "2026-02-05", "pageviews": 195, "visitors": 71 }
  ]
}

The period parameter accepts:

  • today - Today
  • 7d - Last 7 days (default)
  • 30d - Last 30 days
  • 90d - Last 90 days

Via MCP Server

AI agents can access analytics data through the Model Context Protocol (MCP) server, which provides a standardized interface for querying data. The MCP server includes tools for:

  • Listing all your sites
  • Retrieving analytics statistics for any time period
  • Analyzing traffic trends and patterns
  • Accessing real-time page view data

For detailed setup instructions and usage examples, see the MCP Server documentation.

Next Steps

Congratulations! You've successfully set up Agent Analytics on your website. Here's what to explore next:

Advanced Tracking

Learn how to track custom events, configure the snippet for single-page applications, and understand privacy settings in the Tracking Snippet guide.

AI Agent Integration

Set up the MCP server to give your AI agents direct access to analytics data. Perfect for autonomous monitoring, reporting, and optimization. See the MCP Server guide.

API Reference

Explore the complete REST API with detailed endpoint documentation, request/response examples, and authentication details in the API Reference.

Dashboard Features

Visit your dashboard to:

  • View real-time analytics with interactive charts
  • Compare time periods to identify trends
  • Export data for further analysis
  • Manage multiple sites from one interface
  • Invite team members to collaborate

Need Help?

If you encounter any issues or have questions: