SEO & Growth Hacking with AIModule 4

4.1Programmatic SEO — Auto-Generate City/Product Pages with AI

30 min 6 code blocks Practice Lab Quiz (4Q)

Programmatic SEO — Auto-Generate City/Product Pages with AI

In 2025, a Lahore-based real estate portal generated 40,000 new organic visitors per month by publishing 2,000 city-neighborhood-property-type pages — all auto-generated with AI and a simple Python script. Each page targeted a long-tail keyword like "2 bedroom flat for rent in Gulberg Lahore" or "commercial plot price in DHA Phase 6 Karachi." The entire operation took 3 days to build and runs automatically. This is programmatic SEO, and it is the highest-leverage SEO technique available in Pakistan today. The core insight is simple: Google rewards pages that answer specific questions, and Pakistan's markets — real estate, restaurants, education, jobs, e-commerce — contain millions of specific questions that nobody has yet answered at scale.

Section 1: What is Programmatic SEO?

Programmatic SEO is the practice of generating hundreds or thousands of unique, keyword-targeted pages using templates and data — rather than writing each page manually. It works best when you have:

  1. A large data set (cities, products, categories, professions, neighborhoods)
  2. Consistent search intent (people searching "[Product] in [City]" or "[Service] for [Profession]")
  3. Unique data per page (prices, availability, ratings, local details that make each page genuinely different)
code
PROGRAMMATIC SEO SYSTEM ARCHITECTURE
═══════════════════════════════════════════════════════════════

  DATA LAYER (Your raw materials)
  ├── variable_1.csv  (cuisines / product types / professions)
  ├── variable_2.csv  (cities / neighborhoods / categories)
  └── enrichment.csv  (prices, hours, landmarks, ratings)
         │
         ▼
  TEMPLATE LAYER (Your content blueprint)
  ├── page_template.md  (AI prompt with {{placeholders}})
  ├── title_formula.txt  ("Best {{cuisine}} in {{neighborhood}}")
  └── meta_desc_formula.txt (155-char template)
         │
         ▼
  GENERATION LAYER (AI does the work)
  ├── generate_pages.py  (reads data, calls Gemini API)
  ├── qc_checker.py  (validates uniqueness + quality)
  └── output/  (500+ generated Markdown files)
         │
         ▼
  PUBLISHING LAYER (Push to your site)
  ├── CMS API (WordPress REST / Contentful / Next.js)
  ├── sitemap_generator.py  (auto-submit to Google)
  └── indexing_api.py  (ping Google for faster crawling)

═══════════════════════════════════════════════════════════════

Pakistani Market Opportunities for Programmatic SEO

NicheTemplate PatternData VariablesPages PossibleCompetition
Real estate"[Property] for [action] in [Area] [City]"10 types × 200 areas × 20 cities40,000 pagesMedium
Restaurants"Best [Cuisine] restaurants in [Area]"20 cuisines × 50 areas1,000 pagesLow
Job listings"[Profession] jobs in [City]"100 professions × 100 cities10,000 pagesMedium
Education"Best [Subject] tutor in [Area]"50 subjects × 200 areas10,000 pagesVery Low
E-commerce"[Product] price in Pakistan"500 products500 pagesLow
Healthcare"[Specialist] doctor in [City]"30 specialties × 20 cities600 pagesLow
Wedding"[Service] in [City] — Prices 2026"15 services × 20 cities300 pagesVery Low
Auto"[Car model] price in Pakistan 2026"200 models200 pagesMedium

Section 2: Building Your First Programmatic SEO System

Step 1 — Keyword Research (The Template):

Use Gemini/ChatGPT to identify your primary template pattern. For a Karachi restaurant directory:

python
# Data Matrix — 64 unique page combinations
cuisines = ["BBQ", "Chinese", "Desi", "Seafood", "Fast Food",
            "Biryani", "Continental", "Pizza"]
neighborhoods = ["Clifton", "DHA", "Gulshan", "PECHS", "Saddar",
                 "North Nazimabad", "Malir", "Korangi"]

# 8 cuisines × 8 neighborhoods = 64 pages
# Each targets: "best {cuisine} restaurants in {neighborhood} karachi"

Step 2 — AI Content Generation Template:

code
CONTENT GENERATION PROMPT
═══════════════════════════════════════════════════════════════

  Write a 600-word SEO-optimized article about the best
  {{cuisine}} restaurants in {{neighborhood}}, Karachi.

  Include:
  - Opening paragraph with target keyword in first 100 words
  - 3 sections: What to expect, Top picks, Pricing guide in PKR
  - Local context: nearby landmarks (Dolmen Mall, KFC, Park Towers)
  - Specific PKR price ranges (budget: PKR 500-800, mid: PKR 1,200-2,000)
  - Operating hours typical for that neighborhood
  - 1 conclusion with call-to-action

  Target keyword: "best {{cuisine}} restaurants in {{neighborhood}} karachi"

  ENRICHMENT DATA FOR THIS PAGE:
  - Average meal price: PKR {{avg_price}}
  - Famous dish: {{famous_dish}}
  - Nearest landmark: {{landmark}}
  - Peak hours: {{peak_hours}}
  - Rating range: {{rating_range}}/5

═══════════════════════════════════════════════════════════════

Step 3 — Automation with Python:

python
from google import genai
import csv

client = genai.Client(api_key="YOUR_GEMINI_KEY")

with open("data_matrix.csv") as f:
    reader = csv.DictReader(f)
    for row in reader:
        prompt = f"""Write a 600-word article about best {row['cuisine']}
        restaurants in {row['neighborhood']}, Karachi.
        Average price: PKR {row['avg_price']}.
        Famous dish: {row['famous_dish']}.
        Landmark: {row['landmark']}."""

        response = client.models.generate_content(
            model="gemini-2.5-flash",
            contents=prompt
        )

        filename = f"pages/{row['neighborhood']}-{row['cuisine']}.md"
        with open(filename, "w", encoding="utf-8") as out:
            out.write(response.text)
        print(f"Generated: {filename}")

Step 4 — Technical SEO for Each Generated Page:

ElementTemplateWhy Required
Title tagBest {{Cuisine}} in {{Area}} Karachi | YourSite.pkUnique per page, keyword-optimized
Meta descriptionAI-generated, 150-160 chars, unique per pageClick-through optimization
H1Best {{Cuisine}} Restaurants in {{Area}}, KarachiOne H1 per page with target keyword
Schema markupLocalBusiness or Restaurant schema per pageRich snippets in search results
Internal linksEach page links to related cuisine + neighborhood pagesPasses PageRank across cluster
Canonical tagPoints to itself (self-referencing)Prevents duplicate content flags
BreadcrumbsHome > Karachi > {{Area}} > {{Cuisine}}Navigation + schema breadcrumb

Section 3: Avoiding the Thin Content Trap

The single biggest risk in programmatic SEO is publishing pages that are technically unique but practically identical. Google calls these "thin content" pages and penalizes sites that publish them at scale.

code
THIN vs. UNIQUE CONTENT — THE QUALITY LINE
═══════════════════════════════════════════════════════════════

  ❌ THIN (Will get penalized):
  ├── "Clifton has many BBQ restaurants. People enjoy BBQ."
  ├── "DHA has many BBQ restaurants. People enjoy BBQ."
  │   (Same text, different variable — Google sees through this)
  └── Total unique info per page: <50 words

  ✅ UNIQUE (Will rank):
  ├── "On Burns Road near Clifton, BBQ joints have been feeding
  │   Karachi since the 1960s. A full mutton karahi for 4 costs
  │   PKR 2,500-3,500 — about 40% cheaper than DHA restaurants."
  ├── "DHA Phase 5's BBQ scene centers around Khayaban-e-Bukhari,
  │   where premium outlets charge PKR 4,000-6,000 for the same
  │   karahi. The upside: air-conditioned dining and valet parking."
  └── Total unique info per page: 200+ words of distinct content

═══════════════════════════════════════════════════════════════

The Uniqueness Checklist

CheckBad (Thin)Good (Unique)
Price data"Prices vary""Main course PKR 800-1,500 (2026)"
Location detail"Located in DHA""Near Dolmen Mall, Phase 4 DHA"
Specific facts"Good food quality""Famous for Sindhi biryani since 2019"
Local landmarksNone"10 minutes from Clifton Beach"
Audience contextGeneric"Popular with office crowds from PECHS"
Enrichment dataOnly 2 template variables3+ unique data points per page

The Depth Formula: For each programmatic page, the AI prompt must include at least 3 data variables from your enrichment CSV — not just the two template variables. A restaurant page needs: cuisine type + neighborhood + at least one of (price range / famous dish / nearby landmark / rating / hours / phone).

Section 4: Scaling from 100 to 10,000 Pages

code
GROWTH ROADMAP — PHASED EXPANSION
═══════════════════════════════════════════════════════════════

  PHASE 1 (Week 1-2): PILOT — 64 pages
  ├── 8 cuisines × 8 Karachi neighborhoods
  ├── Manual review of every page
  ├── Submit sitemap to Google Search Console
  ├── Monitor indexing rate daily
  └── Target: 50+ pages indexed by Week 2

  PHASE 2 (Week 3-4): EXPAND — 320 pages
  ├── Same template → Lahore + Islamabad + Rawalpindi
  ├── Spot-check 10% of pages for quality
  ├── Add 2-3 new enrichment data points per city
  └── Target: 200+ pages indexed by Week 4

  PHASE 3 (Month 2): DEEPEN — 1,500 pages
  ├── Add price ranges as third variable dimension
  ├── Add rating tiers (budget / mid-range / premium)
  ├── Cross-link all related pages
  └── Target: 800+ indexed, first rankings appearing

  PHASE 4 (Month 3): DOMINATE — 5,000+ pages
  ├── Add time-based pages (best for lunch / dinner / late night)
  ├── Add seasonal content (Ramadan deals, Eid specials)
  ├── Start earning backlinks from the directory
  └── Target: 3,000+ indexed, 50+ page 1 rankings

═══════════════════════════════════════════════════════════════

Indexing at Scale: Google crawls new sites slowly. Strategies for faster indexing:

StrategySpeedCostNotes
Submit sitemap to GSCBaselineFreeDo this Day 1 — non-negotiable
Google Indexing APIFastFree (quota limits)Designed for job listings but works broadly
Sitemap ping (ping Google)MediumFreehttps://www.google.com/ping?sitemap=URL
Internal linking from indexed pagesMediumFreeAlready-indexed pages help new ones get found
Social sharing of new pagesMediumFreeGoogle crawls pages with social signals faster
Practice Lab

Practice Lab

Exercise 1: Data Matrix — Build a data matrix for your chosen niche in Google Sheets. Two columns: variable_1 (cuisine/product/profession) and variable_2 (city/neighborhood). Fill in at least 5 × 5 = 25 combinations. Add a third column with one unique enrichment data point per row (price range, famous item, landmark). This is your programmatic SEO seed data.

Exercise 2: Template Testing — Write a Gemini prompt template for your niche. Test it manually with 3 different variable combinations. Evaluate each output: Is the content genuinely unique between pages? Does it include the target keyword naturally? Is it 500+ words? Does it have Pakistani context (PKR prices, local landmarks, platform names)? If any two outputs are >80% similar, add more enrichment data to your prompt.

Exercise 3: Automation Build — Build a Python script (or n8n workflow) that reads your Google Sheet and calls the Gemini API for each row. Save outputs as Markdown files. Run it for your 25 combinations. Open 5 at random — are any two pages so similar Google would flag them as duplicates? If yes, strengthen your enrichment data before scaling.

Exercise 4: Technical SEO Audit — For your 25 generated pages, create: unique title tags (55 chars each), unique meta descriptions (155 chars each), and an internal linking plan (which pages link to which). Verify every page has a unique H1 with the target keyword. Submit a sitemap with all 25 URLs to Google Search Console. Monitor indexing daily for 2 weeks.

Pakistan Case Study

Hamza's Tutoring Directory, Lahore (2026)

Hamza Qureshi, a 27-year-old from Johar Town, Lahore, had built a small tutoring marketplace site. He had 40 manually written pages and was getting 800 organic visitors per month after 8 months of effort. He enrolled in this course and applied programmatic SEO to his existing site.

His Data Matrix:

Variable 1 (Subject)Variable 2 (Area)Enrichment
25 subjects (Maths, Physics, Chemistry, Biology, English, Urdu, Computer, Accounts...)18 Lahore neighborhoods (Johar Town, Gulberg, DHA, Model Town, Bahria Town, Cantt...)Average tutor fee per area, O-Level vs. Matric concentration, landmark school/college per neighborhood

Scale: 25 subjects × 18 neighborhoods = 450 pages generated in 4 hours.

Generation Cost: Gemini 2.5 Flash API — PKR 1,800 total (PKR 4 per page).

Publishing: WordPress REST API, deployed over 2 days.

Results After 90 Days:

MetricBefore (40 Manual Pages)After (490 Total Pages)Change
Organic traffic800/month11,400/month+1,325%
Keywords ranked41680+1,559%
Pages indexed40460+1,050%
Tutor registrations12/month94/month+683%
Revenue (lead fees)PKR 0PKR 47,000/monthNew revenue
Cost to generate8 months of writing4 hours + PKR 1,80099.7% time saved

Hamza's Key Insight: "Yaar, 450 pages manually likhna 2 saal lagta. Script ne 4 ghante mein kar diya. Lekin important baat yeh hai ke maine har page mein area-specific data diya — tutor fees, nearby schools, O-Level ya Matric focus. Agar sirf subject aur area swap karta bina enrichment ke, Google penalize kar deta."

Key Takeaways

  • Programmatic SEO works best when you have a large, structured data set that maps to real search demand — the sweet spot is 100-10,000 pages
  • Each programmatic page must have genuinely unique content (not just template variable substitution) to avoid Google's thin content penalty
  • Pakistan's real estate, restaurant, education, and job markets are perfect for programmatic SEO — the city/neighborhood/category data sets are massive and largely uncovered
  • A third enrichment variable (price, landmark, rating) is the critical difference between thin content and indexable, rankable pages
  • The Gemini 2.5 Flash API is the cost-effective engine for programmatic generation — at PKR 1,800 per 450 pages, cost per page is PKR 4
  • Speed matters: getting to 500+ indexed pages in the first 90 days signals authority to Google and compounds your rankings faster
  • Internal linking between programmatic pages creates a topic cluster that passes PageRank across your entire directory
  • Submit your sitemap to Google Search Console on Day 1 and use the Indexing API for faster crawling at scale
  • Your first pilot should be 25-64 pages — small enough to review every output before publishing at scale
  • Once the template works, expansion is purely mechanical — the hard work is building the right prompt and enrichment data once

Lesson Summary

Includes hands-on practice lab6 runnable code examples4-question knowledge check below

Quiz: Programmatic SEO — Auto-Generate City/Product Pages with AI

4 questions to test your understanding. Score 60% or higher to pass.