Skip to content

Google Analytics

Your agents read where visitors came from and what they did, count each Play’s visitors next to its signups, and build audiences to retarget.

Connect
Sign in once, 2 grants
Runs through
Your account
First run
Read the last 28 days of visits by source, free on your account
Sites
None, it holds your records
Metric.query
You, to your agent

Where did my visitors come from in the last 28 days, and which sources signed up?

curl -X POST "https://api.sb/leaseline.app/metrics/query?mode=try" \
  -H "Authorization: Bearer $SB_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"metric":"visits","shape":"trend","breakdown":"acquisition","window":"28d"}'
npx startup-builder do Metric.query --try --data '{"metric":"visits","shape":"trend","breakdown":"acquisition","window":"28d"}'
{
  "name": "do",
  "arguments": {
    "mode": "try",
    "code": "return await $.Metric.query({ metric: 'visits', shape: 'trend', breakdown: 'acquisition', window: '28d' })"
  }
}
import { $ } from 'startup-builder'

const result = await $.try.Metric.query({ metric: 'visits', shape: 'trend', breakdown: 'acquisition', window: '28d' })
Response
{
  "$type": "Metric",
  "mode": "try",
  "stored": false,
  "metric": "visits",
  "window": "28d",
  "rows": [
    {
      "acquisition": "search",
      "visits": 412,
      "signups": 9
    },
    {
      "acquisition": "ai answer",
      "visits": 61,
      "signups": 4
    },
    {
      "acquisition": "referral",
      "visits": 133,
      "signups": 3
    },
    {
      "acquisition": "direct",
      "visits": 290,
      "signups": 2
    }
  ]
}
Try mode reads, stores nothing and spends nothingAPI referenceIts Nouns

Connect once

  1. Call Integration.connect with system: 'analytics-and-experiments', then open the connectUrl it returns and sign in as a Google account with access to your property.
  2. Pick the property your site reports to.
  3. Name your signup event; the agent marks it as a key event so every readout counts it.
GrantWhat it unlocksScope
Read reportsVisits by source, landing page and key event, and the last 30 minutes in realtimehttps://www.googleapis.com/auth/analytics.readonly
Change settingsMarking key events, and building audiences to retargethttps://www.googleapis.com/auth/analytics.edit
ToDo this
PauseIntegration.pause stops every call through Google at once and keeps the token; Integration.resume picks up from the same cursor.
ReconnectIntegration.reconnect returns a fresh connectUrl that lasts one hour, and keeps the Integration's id and cursor, so nothing imports twice.
DisconnectIntegration.revoke revokes the token with Google; every record it brought in stays in your records.

What your agents do

AskVerbRuns throughPrice
Where did my visitors come from in the last 28 days, and which sources signed up?Metric.queryYour accountFree
Build an audience of people who saw the pricing page and did not sign up.Audience.createYour accountFree
Mark my signup as a key event.Integration.callYour accountFree
Who is on the site right now, and from where?Metric.queryYour accountFree

Calls on your own account are free.

What it holds

NounThe account’s objectWhenWhich side leads
VisitrunReport rowEach day’s visits settleThe account
AudienceaudienceYour agent builds one to retargetYour records

Events and webhooks

DirectionEvent
EmitsMetric.queried, Audience.created

Any Event can wake a Workflow, and a Watch delivers it to your endpoint, signed (Events and webhooks).

Limits

WhatLimitCall
RealtimeCovers the last 30 minutes; anything older reads from the day’s reportsMetric.query
A retargeting audienceFills only from visits after it is built, so build it before the traffic you want to reachAudience.create

Field map

Our fieldGoogle Analytics’s fieldNotesCalls
Metric.breakdowndimensionssessionSource, sessionMedium, landingPage and the restMetric.query
Metric.metricmetricssessions, activeUsers, keyEventsMetric.query
Metric.windowdateRangesNone.Metric.query
Audience.queryaudience filter clausesNone.Audience.create

What try does here

Reads run for real, because a report changes nothing; try stores no rows, builds no audience and marks no event.

How long a connection lasts

A connection lasts until you revoke it in your Google Account; Google also ends a grant left unused for six months, and every call your agents make counts as use.

The platform asks you to reconnect 7 days before it runs out; until you do, a call that needs it refuses with needs-reauth.

Plays and strategies

Used by

No Workflow, agent task or Service acts through it yet: your agents call it directly.

Reference

4 calls, each with its path and price
CallPathPrice
Metric.queryPOST /metrics/queryFree
Audience.createPOST /audiences/createFree
Integration.callPOST /integrations/callFree
Metric.queryPOST /metrics/queryFree

Contents