Sub topic 9
Segmenting queries and pages to answer real questions
This chapter assumes you have a daily Search Console table with the columns date, query, page, clicks, impressions and position. It also assumes you can read basic pandas. The table design comes from the earlier chapter on the daily data model.
Why one site-wide number misleads
A site-wide average position mixes very different searches. A query like "example shoes login" ranks first and has a high CTR. A query like "best running shoes" ranks twelfth and has a low CTR. If the mix changes, the total moves even though no ranking changed. Segments let you ask one question at a time.
Each segment should answer a specific question. If you cannot name the question, do not build the segment.
Common segments
| Segment | Question it answers | Typical rule |
|---|---|---|
| Brand vs non-brand | Is growth coming from people who already know us? | Regex on brand name and misspellings |
| Page group | Which section gained or lost? | First URL folder, or a page template |
| Device | Did mobile change differently from desktop? | Search Console `device` dimension |
| Country | Is a market dropping? | Search Console `country` dimension |
Brand and non-brand matter most. Brand clicks follow marketing, press and seasonality. Non-brand clicks follow your SEO work. Reporting them together hides both.
Building segments in code
Assign each row a segment once, then aggregate. Do not average the segment's daily position values. Sum position * impressions and divide by total impressions, as the earlier chapter on averaging position showed.
import pandas as pd
df = pd.read_csv("gsc_daily.csv", parse_dates=["date"])
brand_pattern = r"example|examp1e|exmaple"
is_brand = df["query"].str.contains(brand_pattern, case=False, regex=True)
df["segment"] = is_brand.map({True: "brand", False: "non-brand"})
# First folder of the URL path, for example /blog or /shoes
df["section"] = (
df["page"]
.str.extract(r"https?://[^/]+(/[^/?#]*)", expand=False)
.fillna("/")
)
df["pos_x_impr"] = df["position"] * df["impressions"]
summary = (
df.groupby(["segment", "section"], as_index=False)[
["clicks", "impressions", "pos_x_impr"]
].sum()
)
summary["ctr"] = summary["clicks"] / summary["impressions"]
summary["avg_position"] = summary["pos_x_impr"] / summary["impressions"]
print(summary.sort_values("clicks", ascending=False))Keeping segments trustworthy
- Store the segment rules in version control. If the brand regex changes, old and new numbers are no longer comparable.
- Review the largest non-brand queries each month. Brand variants often hide there.
- Keep segments mutually exclusive. A query that is both brand and non-brand double counts.
- Remember that Search Console omits anonymized queries from query rows. Segment totals by query will not match page totals.
Common errors
- Segmenting by current page URL when pages were moved or renamed. Old rows then land in the wrong group.
- Using too many segments. With tiny impression counts, CTR and position swing randomly.
- Comparing a segment's CTR across weeks with different ranking mixes, without checking position first.
Exercise
Your non-brand clicks are flat, but total clicks rose 15%. Which segment do you check first, and why do you compute CTR from sums instead of averaging daily CTR values?
Show answer
Check the brand segment first, because brand demand from campaigns or press often explains a total increase while non-brand stays flat. Compute CTR as total clicks divided by total impressions, because averaging daily CTR values gives a low-impression day the same weight as a high-impression day and distorts the result.