DEV Community

Michel Jee
Michel Jee

Posted on

How I Solved the Local SEO Location Bias Problem Using Geolocation Testing

Ever had a client insist their business shows up in local search results, but when you check from your own location, it's nowhere to be found? That's the classic 'location bias' problem in SEO testing.

I've been digging into this recently, and built a quick script to spoof search results for different cities using Puppeteer. Here's the gist:

javascript
const puppeteer = require('puppeteer');

async function spoofLocalSearch(query, lat, lng) {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();

// Override geolocation
await page.setGeolocation({ latitude: lat, longitude: lng });

// Set a relevant user-agent for that region (optional)
await page.setUserAgent('Mozilla/5.0 ...');

await page.goto(`https://www.google.com/search?q=${encodeURIComponent(query)}`);

// Wait for results to load
await page.waitForSelector('#search');

const results = await page.evaluate(() => {
    const items = document.querySelectorAll('.g');
    return Array.from(items).map(item => item.innerText);
});

console.log(`Results for ${query} at ${lat},${lng}:`, results.slice(0, 5));
await browser.close();
Enter fullscreen mode Exit fullscreen mode

}

// Test for 'coffee shops' in New York
spoofLocalSearch('coffee shops', 40.7128, -74.0060);


This works for quick checks, but for more reliable, large-scale analysis across multiple cities and languages, I've been using a dedicated API that handles location spoofing natively. It's much cleaner than managing browser instances for every test case.

What's your go-to method for verifying local search visibility without being physically present?

https://serpspur.com

Top comments (1)

Collapse
 
sebastian_cole123 profile image
Sebastian Cole

This is clever! I usually just ask a friend in that city to run a quick search for me, but your Puppeteer approach is way more systematic. Have you noticed any discrepancies between spoofed results and what real users see, or does the geolocation override handle it pretty accurately?