Prototypr Docs Logo Docs

AI Agents API Endpoints Documentation

The Premium endpoints in this doc have been created to support organizations with AI Agents that can explore, visualize and analyze data.

As a prototypr.ai customer, it is important to provide you with easy access to your data in a variety of formats that you can use. In order to gain access to agents via the prototypr.ai API, you will need to sign up to the Closed GA4 x AI Beta from within the app in addition to generating an API Key, which is accessible on the /home page when you login.

AI Agent Endpoints

As a Premium prototypr.ai customer or member, you have access to the following Agents via the API:

More agent APIs will be available soon! If you have any feedback or feature requests about these APIs, please take the time to fill out this short survey.

AI Agent Use Case: Building a GA4 Chatbot

One of the ways that prototypr.ai is using the fine tuned GA4 GPT agent API is to power a chatbot that enables customers to chat with their Google Analytics data. If you or your company is using Google Analytics 4, then why not consider building a chatbot with this Agent to enable easier access to your data.

Below is a example video of a Google Analytics 4 GPT chatbot in the beta AI Analytics platform, which is prototypr.ai's analytics platform:

Fine Tuned Google Analytics GPT Agent PREVIEW

Purpose

Enable developers to Chat with their Google Analytics data, build Google Analytics 4 API queries and visualize data with ChartJS.

Type: POST

URL: https://www.prototypr.ai/api/v1/agents/ga4-gpt

Headers

  • Authentication: Bearer ${TOKEN}
  • Content-Type: application/json
  • Accept: application/json

Request Body

  • user_id: String

    Your unique prototypr.ai user_id.

  • workspace_id: String

    Connected to your GA4 account. How to connect GA4 guide.

  • messages: Array

    Standardized chat completions message thread.

  • gpt_data_analysis: Boolean

    Setting to True enables deeper analysis on returned data.

Python Request

import requests
import os
import json

messages_thread = []
messages_thread.append({
    "role": "user",
    "content": "how many users visited my site yesterday?"
})

url = "https://www.prototypr.ai/api/v1/agents/ga4-gpt"

payload = {
    "user_id": "your_user_id",
    "workspace_id": "your_workspace_id",
    "messages": messages_thread,
    "gpt_data_analysis": True
}

headers = {
    "Authorization": "Bearer " + os.getenv("API_KEY"),
    "Content-Type": "application/json"
}

response = requests.post(url, data=json.dumps(payload), headers=headers)
print(response.json())

Sample Response

{ "data": {
    "credit_balance": 99,
    "google_analytics_data" : [
      {
        "kind": "analyticsData#runReport",
        "metaData": {
            "currencyCode": "CAD",
            "timeZone": "America/Toronto"
        },
        "metricHeaders": [
            {
                "name": "activeUsers",
                "type": "America/TYPE_INTEGER"
            }
        ],
        "rowCount": 1,
        "rows": [
            {
                "metricValues": [
                    {
                        "value": "89"
                    }
                ]
            }
        ],
        "totals": [
            {
                "metricValues": [
                    {
                        "value": "89"
                    }
                ]
            }
        ]
      }
    ],
    "google_analytics_query" : {
        "dateRanges": [
            {
                "endDate": "yesterday"
                "startDate": "yesterday"
            }
        ],
        "keepEmptyRows": True,
        "metricAggregations": [
            "TOTAL"
        ],
        "metrics": [
            {
                "name": "activeUsers"
            }
        ]
    },
    "gpt_data_analysis": "<div><p class='analysis-copy'>Yesterday, the site attracted a total of 89 active users, indicating stable engagement.</p></div>",
    "request_log": {
        "request_count": "1",
        "request_date": "2024-12-09 11:45:00",
        "request_id": "8e4249ed56d44f543487c4bf8f16b649",
        "service": "/agents/ga4-gpt"
    },
    "messages_thread": [
        {
            "content": "how many users visited my site yesterday",
            "role": "user",
        },
        {
            "content": "{\"metrics\": [{\"name\": \"activeUsers\"}], \"dateRanges\": [{\"startDate\": \"yesterday\", \"endDate\": \"yesterday\"}], \"keepEmptyRows\": true, \"metricAggregations\": [\"TOTAL\"]}",
            "role": "assistant",
        },
        {
            "content": "[{\"metricHeaders\": [{\"name\": \"activeUsers\", \"type\": \"TYPE_INTEGER\"}], \"rows\": [{\"metricValues\": [{\"value\": \"89\"}]}], \"totals\": [{\"metricValues\": [{\"value\": \"89\"}]}], \"rowCount\": 1, \"metadata\": {\"currencyCode\": \"CAD\", \"timeZone\": \"America/Toronto\"}, \"kind\": \"analyticsData#runReport\"}]",
            "role": "assistant",
        },
        {
            "content": "<div><p class='analysis-copy'>Yesterday, the site attracted a total of 89 active users, indicating stable engagement.</p></div>",
            "role": "assistant"
        }
    ],
    "model": "ga4-gpt-ft"
  }
}                           

Google Analytics MCP Agent

Alternatively, if you would rather access this fine tuned Analytics Agent, you can connect with it via our custom Agent MCP Server.

In order to access this Agent, you will need to generate a prototypr.ai API key and fill out the information below.

{
  "mcpServers": {
    "ga4_agent": {
      "url": "https://www.prototypr.ai/mcp/agents/ga4",
      "displayName": "Google Analytics Agent",
      "headers": {
        "Authorization": "Bearer INSERT_PROTOTYPR_AI_API_KEY",
        "X-User-Id": "INSERT_USER_ID",
        "X-Workspace-Id": "INSERT_WORKSPACE_ID"
      }
    }
  }
}

How to Install: In your AI Workspace, click on MCP Tools, then Add Server. Paste the JSON config above and save.

GA4 API MCP FAQ

How do I connect Google Analytics 4 to a prototypr.ai workspace?

1. Sign up to the Closed GA4 x AI Beta from the /home page. Click on the Analytics icon and register.

2. Once approved, visit the GA4 connection guide to authenticate via OAuth.

How much does it cost to access the GA4 Agent via API or MCP?

Currently, access to the API and MCP client in prototypr.ai requires a $29/month Plus membership subscription. Prices are expected to increase, so subscribe today to keep that price.

Why is prototypr.ai API / MCP a premium feature?

To cover the costs of serving leading LLMs such as ChatGPT and Google Gemini with data analysis baked in, prototypr.ai needs to charge for MCP access. It's with your support that prototypr.ai is able to bring new MCP capabilities to market.

AB Testing and Optimization Agent PREVIEW

Purpose

Scrape URLs to uncover SEO and A/B testing opportunities, automate test plan creation, and retrieve historical experiment data.

Type: POST

URL: https://www.prototypr.ai/api/v1/agents/ai-optimizer

Request Body

  • user_id: String

  • workspace_id: String

  • messages: Array

Python Request

import requests

messages_thread = [{
    "role": "user",
    "content": "Create a test plan for: Personalizing onboarding..."
}]

url = "https://www.prototypr.ai/api/v1/agents/ai-optimizer"
payload = {
    "user_id": "your_id",
    "workspace_id": "your_ws",
    "messages": messages_thread
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())

Optimization Agent FAQ

How can I scrape a webpage with this Optimization Agent?

Prompt the agent to visit a specific URL. Example:

Prompt: "What are some opportunities I could explore to improve the content at prototypr.ai/docs/api/agents?"

What are some of this agent's capabilities?

Currently, the Optimization agent can help you build new test plans, scrape web urls and retrieve your current library of experiments and learnings.

Rate Limits and API Usage Stats

Currently there are rate limits of 25 requests/day across all API endpoints. This will grow over time as more endpoints are added.

If you need more, please connect with Gareth Cull, the creator of prototypr.ai.