When running automated tests frequently on your website, at one point it may be essential to keep your website statistics consistent with correct visitor counts, conversions, and geo-location data. The impact of such skewed data from automation can lead to pricy mistakes for incorrect ad targeting and the business economy statistics, hence it can be important to exclude test automation from analytics data.
First off, please keep in mind that if possible do not run big load tests on production servers to minimize impact on the end user. But we do understand that there might be a need to use production servers, so these are the things that you can do!
What can be done?
There are three available options that you can use to exclude test automation runs from analytics. Whichever fits your infrastructure the best is the option you should pick. In our professional experience, we suggest separating environments (either creating a copy of production or using staging) for automation with the combination of adding exceptions to the tag that is applied to production.
Disabling Google Analytics
Disabling Google Analytics is possibly the simplest option by temporarily removing the code responsible for reporting visitors or removing the tag from Google Tag Manager. By doing this there will be NO traffic being registered in Google Analytics. The biggest negative impact for this option is quite obvious – the regular website visitors will not be registered which will result in data loss for the period that GA is disabled. Another implication for this is re-enabling GA for your website – reverting the changes can be time-consuming and often takes a longer time than the test itself.
Best testing practices indicate that such automated tests should not run on production servers – especially large-scale tests that can impact visitor experience when using the services. Creating a copy of the production server’s for large-scale tests will not impact regular visitor. In this case, the GA will not run on that website avoiding the whole issue altogether.
Exclude test automation on tags
The easiest and most versatile way to exclude test automation runs from visitors is by using Google Tag Manager implementation. The best part is – you’re most likely already using it. This is achieved by creating a single variable and a trigger, which will be applied to your tag responsible for visitor monitoring – like Google Analytics.
navigator object in the browser. The mentioned object contains a field called “webdriver” which is a boolean value indicating whether WebDriver client is used. For regular visitors, this value is false, but automated test browsers have the value set to true by default.
Try it out by printing
navigator.webdriver value in your browser console.
How to set up the Tag Manager
You can name the variable however you want, but remember that it will have to be referenced later, so make sure it’s meaningful and easy to understand what value this variable will hold. In our case, we called it “Navigator WebDriver Value”.
Next, navigate to the “Triggers” page and create a new trigger. The trigger type should be “Custom Event”.
Important: Set the event name to “gtm.js”, this will be the entry point for the tag and that is the event we will want to block later on if this trigger will be executed.
This trigger will be fired on “Some Custom Events”, when selected 3 forms will appear – variable, comparison, expected value. For the variable pick the previously created variable, for comparison pick “equals”, and the expected value should be “true”. Before saving, it should look something like the picture below.
The only step left is adding this trigger as an exception to the tag you want to be skipped by automation. To do that, navigate to the “Tags” page view and edit the desired tag.
When in the tag, click on the “Triggering” block, after which an “Add exception” button should appear, allowing you to add the previously created trigger.
Save the tag and submit the changes for the container.
Please note that we highly recommend previewing the changes and looking at the triggered tag – if there are any bugs in the setup your tag could be non-functional for all visitors.
Now back to running Loadero tests
There you go! From now on, when an automated browser enters your website, it will not trigger the tags that you set exceptions on. By doing that, even if we don’t necessarily recommend it, you can run automated tests on your production app, without skewing the data that you gather about your visitor demographics.
By applying the exception in Google Tag Manager, you’ve applied a long-term solution for such an issue. This approach is very versatile, as it allows the use of the same exception for other tags. Additionally, these tags can be rapidly changed whenever necessary without any complex and lengthy deployments.