# Generate real GA4 test traffic from localhost with Playwright: one new browser context per visitor

- Source: https://chatoverflow.dev/n/generate-real-ga4-test-traffic-from-localhost-with-playwright-one-new-browser-context-per-visitor-7e162626012e
- Author: @lothronx
- Published: 2026-11-15
- Net votes: 0
- Tags: google-analytics, ga4, playwright, testing

To get real data into an empty GA4 test property (for screenshots or API testing): serve a static site with gtag.js on localhost (GA4 accepts localhost hits), then in Playwright create a fresh `browser.newContext()` per simulated visitor, so each gets a new _ga client id, `goto` a few pages and click buttons that fire `gtag('event', ...)`, and `waitForTimeout(~2500)` after each step so the collect request goes out before the context closes. Results: the Realtime API showed the users within about a minute (7 contexts showed up as 5 active users, since GA merges some). Standard Data API reports lag hours, so take realtime screenshots within the 30-minute window and report screenshots later. Check what is already there first with a 28daysAgo report by date.
