Sub topic 5
Grouping queries into exposed and comparison cohorts
Assume you know the basics of Search Console metrics, GA4 sessions, organic search, and Python with pandas. This chapter uses those concepts to prepare data for a before-and-after comparison.
An exposed cohort contains queries for which an AI Overview appeared during the study’s exposure period. A comparison cohort contains similar queries without recorded AI Overview exposure. The cohorts let you ask whether performance changed more for exposed queries than for comparable queries.
Choose the unit of analysis
Search Console can return rows by query, page, date, country, device, and other dimensions. Decide what one observation represents before creating cohorts.
For this analysis, use one row per query, page, and date. Assign the same cohort to every row for a query. Do not assign a cohort separately based on whether a row received a click. That would make the outcome influence the treatment label.
A query belongs in the exposed cohort when an independent SERP tracking source recorded an AI Overview for that query in the relevant market, device, and date range. The comparison cohort should contain queries that could have been affected by the same general search conditions but had no recorded exposure.
| Field | Purpose | Example |
|---|---|---|
| `query` | Search term that identifies the cohort | `best running shoes` |
| `cohort` | Exposure classification | `exposed` or `comparison` |
| `period` | Before or after the change window | `pre` or `post` |
| `date` | Date of the Search Console observation | `2026-02-14` |
Build the cohort labels
Start with a query-level exposure list from your SERP tracker. Normalize text consistently before matching. Lowercase queries, trim whitespace, and use the same spelling rules in both data sources.
Keep the exposure definition fixed for the study. For example, define exposure using tracker observations from January and analyze Search Console performance before and after February 1. Do not repeatedly update the exposed list while inspecting the results.
import pandas as pd
rows = [
{"date": "2026-01-15", "query": "best running shoes", "page": "/shoes",
"clicks": 120, "impressions": 2000},
{"date": "2026-02-15", "query": "best running shoes", "page": "/shoes",
"clicks": 90, "impressions": 2100},
{"date": "2026-01-15", "query": "running shoe size guide", "page": "/guide",
"clicks": 80, "impressions": 1200},
{"date": "2026-02-15", "query": "running shoe size guide", "page": "/guide",
"clicks": 78, "impressions": 1250},
]
exposed_queries = {"best running shoes"}
df = pd.DataFrame(rows)
df["query"] = df["query"].str.strip().str.lower()
df["date"] = pd.to_datetime(df["date"])
df["cohort"] = df["query"].isin(exposed_queries).map({
True: "exposed",
False: "comparison",
})
df["period"] = df["date"].ge("2026-02-01").map({
True: "post",
False: "pre",
})
summary = (
df.groupby(["cohort", "period"], as_index=False)
.agg(clicks=("clicks", "sum"),
impressions=("impressions", "sum"))
)
summary["ctr"] = summary["clicks"] / summary["impressions"]
print(summary)This code classifies each Search Console row, then aggregates clicks and impressions by cohort and period. Calculate click-through rate (CTR) after aggregation. Do not average the row-level CTR values, because a query with ten impressions should not have the same weight as a query with ten thousand impressions.
Select a credible comparison cohort
A useful comparison group resembles the exposed group before exposure. Match or filter on factors that influence clicks, such as:
- Search intent, such as informational or transactional.
- Country and device.
- Landing-page type and business area.
- Baseline impressions, position, and CTR.
- Search volume and query length.
Exclude queries with unclear exposure status rather than forcing them into a group. You can also create several comparison cohorts, such as informational queries and transactional queries, then check whether the estimated effect is consistent.
The comparison group does not need identical performance. It needs a plausible parallel trend: without the AI Overview change, both groups would probably have changed in similar ways.
Validate the labels before analysis
Check the number of queries and impressions in each cohort. Look for queries that switch cohorts because the tracker observed exposure only intermittently. Decide in advance whether to classify them as exposed, exclude them, or analyze them separately.
Also compare pre-period position and CTR. A cohort made mostly of high-ranking brand queries will not be a fair comparison for a cohort made mostly of broad informational queries.
The next step is to compare CTR, impressions, and average position within these cohorts. The cohort construction determines how much confidence you can place in that comparison.
Exercise
Why should cohort membership be assigned before calculating clicks or CTR?
Show answer
Assigning membership first prevents the outcome, such as receiving a click, from influencing whether a query is labeled exposed. This keeps the comparison definition independent of performance.