Repository navigation
Description
Problem
Phase 2 (#694) maps each brand to a GA4 property. Nothing reads that property yet, so the connection still produces no data.
This is the phase where the product stops describing visibility and starts reporting its consequences. Every AI-visibility tool can say "you appear in 12% of answers"; none of them can finish the sentence, because they have no access to the customer's analytics. Once a GA4 property is mapped, we can: "...and that visibility brought 46 sessions, 3 orders and 4,200 in revenue."
Everything downstream — the traffic surface, and the prompt suggestions in Phase 4 — needs this data to exist first, so this issue is the pipeline only.
Proposal
A daily sync per mapped brand, mirroring the shape of the Search Console sync (#644): a table, a sync function, a call from the daily cycle, and a manual trigger for testing.
Primary report — keyed by URL.
dimensions: date, sessionSource, landingPagePlusQueryString
metrics: sessions, engagedSessions, keyEvents, totalUsers,
transactions, purchaseRevenue
The landing page is the join key. Citations are already URL-level, content opportunities are URL-level, and the site crawler can read any of those URLs — so keying the traffic table the same way makes every later feature a join instead of a new integration.
Optional product report — only meaningful when the property has ecommerce tracking configured (automatic on the common shop platforms, frequently missing on custom builds):
dimensions: itemName, itemId, itemCategory
metrics: itemsViewed, itemsAddedToCart, itemsPurchased, itemRevenue
Storage. One row per (brand, date, source, landing page), with the raw source string kept alongside the normalised platform. A separate table for the product rows.
Decisions already taken — please keep these
Never merge with our own tracking snippet. ai_traffic_logs already counts the same visits for brands that installed the snippet. Every stored row must carry its origin, and the two must never be summed anywhere — a customer who sees their traffic double on the day they connect Analytics will not trust the number again. Reconciling or choosing between the two is a presentation decision for the surface phase, not something the pipeline should bake in.
Classify sources from an explicit list, not a regex. Real data from a live account shows why: chatgpt.com, chatgpt and openai all arrive as separate sources for the same engine, and a *.workers.dev subdomain containing the string "claude" appears as an unrelated referrer that a naive pattern would count as AI traffic. Map known sources to the platform names already used elsewhere in the product, store anything unrecognised verbatim so the list can be extended from observed data.
Mind where revenue is attributed. A GA4 purchase event fires on the checkout or confirmation page, not the product page. Pairing a page dimension with itemsPurchased therefore attributes all revenue to /checkout. The correct pairings are:
| Question | Breakdown |
|---|---|
| Which entry page produced sales | landing page × purchaseRevenue / transactions (session-scoped) |
| Which product page draws interest | page path × itemsViewed (view_item fires there) |
| What actually sold | itemName / itemId × itemsPurchased / itemRevenue |
Backfill and refresh. Unlike Search Console, GA4 has no multi-day reporting lag. Backfill 90 days on first sync, then run daily and rewrite the last 3 days, since GA4 can revise recent figures.
Verified before writing this
Against a live connected account, using the toolkit tools through tools.execute with the pinned version (same path as Search Console, so COMPOSIO_GA_TOOLKIT_VERSION applies):
GOOGLE_ANALYTICS_RUN_REPORTreturns in ~1.7s for a 28-day source breakdown.GOOGLE_ANALYTICS_CHECK_COMPATIBILITYconfirms every dimension/metric combination above is valid, including the item-scoped ones alongsidesessionSource.- AI-sourced sessions are a small share of traffic in absolute terms (single- to double-digit sessions per source over 28 days on the account tested). Charts built on this later must degrade gracefully — percentage-change framing on a base of four sessions is noise, not insight.
Out of scope
- Any UI. No traffic page, no KPI cards, no charts.
- Prompt suggestions built on this data — that is Phase 4.
- Deciding how GA traffic and snippet traffic are presented together.
Acceptance criteria
- A brand with a mapped GA4 property gets its AI-sourced traffic synced daily, broken down by date, source and landing page, with conversions and revenue where the property reports them.
- Product-level rows are stored when the property has ecommerce tracking, and their absence is not an error.
- Every row records where it came from, and nothing in the pipeline sums GA rows with
ai_traffic_logs. - Unmapped brands, brands without the connection, and self-host installs without Composio credentials are unaffected.
- Re-running the sync for a day already synced updates rather than duplicates.
- A manual trigger exists for a single organization, mirroring the Search Console sync endpoint.
Activity
gkhngyk commentedon Aug 13, 2026
Two additions to the storage shape before implementation starts. Both are schema decisions, so retrofitting either one means re-running the 90-day backfill.
1. A second report without the source dimension.
The primary report is filtered to AI-sourced traffic, which answers "what did AI bring us" but cannot answer "what is this page worth to the business". Every follow-on idea that ranks pages by commercial value — high-value pages with weak AI visibility, pages at risk as AI search grows, high-engagement pages we are not visible on — needs the URL's totals across all sources, not the AI slice of them.
One extra
runReportper brand per day, stored in its own table so nothing can accidentally sum it with the AI-sourced rows — the same separation this issue already requires between GA data and the tracking snippet. Worth capping the daily row count for large properties (order by sessions, keep the top N) rather than storing every URL a big site emits.2.
userEngagementDurationon both reports.engagedSessions / sessionsgives engagement rate but not time on page. Average engagement time is the metric that distinguishes a page people read from one they bounce off, and it costs nothing to request alongside the metrics already listed.Everything else stays as specified — this remains pipeline only, and the scoring, prioritisation and lifecycle work that motivated these two fields belongs in its own issue.
feat(integrations): sync AI-sourced traffic, conversions and revenue …