What you see
A browser test clicks a link that leaves the page — to another page of your site, to a sign-up
page, to an app store. verify_tracking then reports the click, and usually the page view before
it, as missing. Adding flush() after every track() makes them arrive.
Your site is not losing these events. The SDK sends what is queued as the page is left (on
pagehide), and something in the test stops that request.
The usual causes
- The test intercepts requests. In Playwright,
page.route()orcontext.route()holds every request the page makes until the test lets it continue — not only the ones the pattern matches. A route that stubs App Store links therefore holds Togo’s request too. The request sent as the page is left belongs to a page that no longer exists, so it is never let through, and it is cancelled when the browser closes, however long the test waits. Your visitors’ browsers intercept nothing, so production is not affected. - The test reads its own request log. A request sent while a page unloads may not appear in
Playwright’s
requestevents even when it reaches Togo. Check withverify_tracking, never with the test’s network log.
Check the fix
Remove the routes before the click that leaves the page, then check the run:
await page.route(/apps\.apple\.com/, (route) => route.fulfill({ status: 200, body: '' }));
await page.goto('http://localhost:4321/');
// ...steps that need the stub...
await page.unrouteAll({ behavior: 'ignoreErrors' });
await page.getByRole('link', { name: 'Sign up' }).click();
Then ask your agent to call verify_tracking with the test browser’s device id and the event names
you expect (Check that events arrive). Every count is 0 when the fix is right.
Do not keep flush() after every track() to make a test pass. It sends each event as its own
request in every visitor’s browser, and it hides the test’s problem rather than fixing it. Call
flush() where the browser SDK reference says to.