Test analytics consent across a planner visit and a reload

2026-11-20来源 dev.toEnglish

The air conditioning planner collects high-level choices about the system and space. The shared Google Analytics script has its own consent workflow. A useful browser test exercises the analytics boundary independently from the question flow, including what happens after a person declines and reloads.

Control the external dependency

Network tests should run with a known test measurement ID and intercept the tag request instead of depending on the real third-party connection. Register the route before loading the page. Capturing a matching request gives observable evidence of script loading. Separately inspect any queued events for the properties you care about.

const scriptRequests: string[] = []; await page.route('https://www.googletagmanager.com/gtag/js?**', async route => { scriptRequests.push(route.request().url()); await route.fulfill({ status: 200, contentType: 'application/javascript', body: '' }); }); await page.goto('/airconditioning/'); expect(scriptRequests).toEqual([]); 

Run three consent paths

The excerpt is a starting point for a test in an analytics-enabled fixture. Add a readiness assertion for the consent controls before interpreting an empty request list. Exercise decline, reload, and verify the tag remains unloaded after the choice is restored. In a fresh context, accept and wait for the intercepted request. Compare the event payload against the implementation. The repository's Google Analytics suite provides a fixture for these checks.

Keep consent storage and project storage distinct in the test. The site may persist the visitor’s analytics choice while the project answers remain in memory. Assert the allowed preference and check that entered postcode or answer labels aren’t added to that record or to the flow-event payload.

Inspect declared event fields as well as the absence of selected values. An explicit allowlist of step and site metadata is easier to audit when more fields are introduced. The suite already tests query and fragment sanitisation under its analytics fixture.

Perth Quotes air conditioning planner is the live preview. Online enquiries are closed.

原文:https://www.a8q9.cn/en/article/test-analytics-consent-across-a-planner-visit-and-a-reload-ac96c3.html

相关文章