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
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' })
{
"$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
}
]
}
Connect once
- Call
Integration.connectwithsystem:, then open the'analytics-and-experiments' connectUrlit returns and sign in as a Google account with access to your property. - Pick the property your site reports to.
- Name your signup event; the agent marks it as a key event so every readout counts it.
| Grant | What it unlocks | Scope |
|---|---|---|
| Read reports | Visits by source, landing page and key event, and the last 30 minutes in realtime | https:/ |
| Change settings | Marking key events, and building audiences to retarget | https:/ |
| To | Do this |
|---|---|
| Pause | Integration.pause stops every call through Google at once and keeps the token; Integration.resume picks up from the same cursor. |
| Reconnect | Integration.reconnect returns a fresh connectUrl that lasts one hour, and keeps the Integration's id and cursor, so nothing imports twice. |
| Disconnect | Integration.revoke revokes the token with Google; every record it brought in stays in your records. |
What your agents do
| Ask | Verb | Runs through | Price |
|---|---|---|---|
| Where did my visitors come from in the last 28 days, and which sources signed up? | Metric.query | Your account | Free |
| Build an audience of people who saw the pricing page and did not sign up. | Audience.create | Your account | Free |
| Mark my signup as a key event. | Integration.call | Your account | Free |
| Who is on the site right now, and from where? | Metric.query | Your account | Free |
Calls on your own account are free.
What it holds
| Noun | The account’s object | When | Which side leads |
|---|---|---|---|
| Visit | runReport row | Each day’s visits settle | The account |
| Audience | audience | Your agent builds one to retarget | Your records |
Events and webhooks
| Direction | Event |
|---|---|
| Emits | Metric.queried, Audience.created |
Any Event can wake a Workflow, and a Watch delivers it to your endpoint, signed (Events and webhooks).
Limits
| What | Limit | Call |
|---|---|---|
| Realtime | Covers the last 30 minutes; anything older reads from the day’s reports | Metric.query |
| A retargeting audience | Fills only from visits after it is built, so build it before the traffic you want to reach | Audience.create |
Field map
| Our field | Google Analytics’s field | Notes | Calls |
|---|---|---|---|
Metric.breakdown | dimensions | sessionSource, sessionMedium, landingPage and the rest | Metric.query |
Metric.metric | metrics | sessions, activeUsers, keyEvents | Metric.query |
Metric.window | dateRanges | None. | Metric.query |
Audience.query | audience filter clauses | None. | 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
| Kind | Where |
|---|---|
| Plays | Retargeting, Promote winners, Editorial SEO, Paid search, Paid social |
| Strategies | Hands-on, Paid, Launch and search |
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
| Call | Path | Price |
|---|---|---|
Metric.query | POST / | Free |
Audience.create | POST / | Free |
Integration.call | POST / | Free |
Metric.query | POST / | Free |