Testing websites with Google AdSense
Automated tests on pages that display Google AdSense ads can be treated as invalid traffic. Learn how to keep ads out of your BugBug test sessions and protect your AdSense account.
If your website displays ads from Google AdSense (or Google Ad Manager), every page your tests open also loads those ads. Google treats impressions and clicks generated by automated tools as invalid traffic, and the publisher (website owner) is responsible for all traffic on the site - even if it comes from their own tests.
What is the risk?
Impressions only - usually harmless. Google filters out automated impressions and doesn't pay for them. However, frequent scheduled runs that open many pages with ads from the same IPs increase the share of invalid traffic on your account, which can lead to an ad serving limit.
Clicks on ads - the real danger. Even a few repeated clicks from the same source look like click fraud and can result in withheld earnings, ad serving limits, or in the worst case account suspension.
Tests rarely click ads on purpose. It usually happens by accident:
an ad loads late and shifts the layout, so the click lands on the ad instead of the intended element,
a selector is too generic (for example "the first link on the page") and matches a link inside an ad,
an anchor or vignette (full-screen) ad from Auto ads covers the element the test wants to click.
How to prevent it
The safest approach is to not load the AdSense script at all during test runs. Your website needs to recognize BugBug traffic and skip the adsbygoogle.js script (and the <ins class="adsbygoogle"> tags). Pick the option that fits your setup best.
Option 1: Test on a staging environment without ads
If you have a staging or development environment, keep AdSense disabled there and run most of your tests against it. Use profiles and variables to switch between environments. Run only a small set of smoke tests on production and protect them with one of the options below.
Option 2: Send a custom HTTP header or user-agent (recommended for production)
Go to Project settings > Browser.
Add a header in HTTP request headers (for example
X-BugBug-Testwith a secret value of your choice), or set a custom User agent.On your server (or in your tag manager), skip rendering the AdSense script when the request contains this header or user-agent.
This works for every test in the project, both local and cloud runs, with no changes to the tests themselves. Read more in Project settings.
Option 3: Add a query string parameter
Add a parameter such as ?bugbug=1 to the URL in your Go to URL steps, and don't load AdSense when the parameter is present. If you use Google Tag Manager to load AdSense, you can add this as an exception to the tag's trigger.
Keep in mind that the parameter is only present on the first page. If the test navigates further, your website should remember it, for example in a cookie or sessionStorage.
Option 4: Set a cookie or localStorage flag with Custom JavaScript
Add a Custom JavaScript step at the beginning of the test that sets a flag, then reload the page:
Your website then checks for this cookie before loading AdSense. To reuse the step across tests, put it in a component.
Option 5: Exclude BugBug cloud runner IPs
Cloud runs reach your site from the IP address of the Cloud Proxy selected in project settings. Your server can skip AdSense for requests coming from that address. See the IPs list of cloud runners. Remember that local runs come from your own IP address, so this option alone does not cover them.
Option 6: Use AdSense test mode
If you want to keep ads visible in tests (for example to check the layout), add data-adtest="on" to your ad units during test sessions only. Ads in test mode are displayed but not counted or billed. Combine it with one of the options above to enable test mode only for BugBug traffic - never leave it on for regular visitors.
Good practices in your tests
Even with ads disabled, follow these rules to avoid accidental clicks:
Use precise selectors - avoid generic selectors such as "first link" or "first button" that could match an element inside an ad.
Never interact with ad iframes - don't record or add steps inside iframes served by
googlesyndication.comordoubleclick.net.Wait for a stable layout - use waiting conditions so the page stops shifting before the test clicks.
Watch for vignette and anchor ads - if they appear, disable them for test sessions instead of adding steps that close them.
Was this helpful?
