Semalt: Excluding Internal Traffic From Selenium WebDriver In Google Analytics
Once in a while, a site requires testing to determine optimization levels. Selenium WebDriver and Watir are among the automatic UI testing tools used. Developers should, therefore, make a point of putting into consideration that by accessing the site, they will also count as internal traffic. It is prudent for them to exclude such traffic from Google Analytics to prevent skewed reports.
Julia Vaishnava, the Senior Customer Success Manager of Semalt, states that it is relatively easy to eliminate traffic from Selenium if it is carried out in the testing environment. One can use GA tokens from production to separate the analytics data. The other method is to avoid adding the GA extension to a testing server.
However, if the developer uses Selenium against production, there are a few ways through which one can exclude the traffic generated by Google Analytics. Some require excluding specific traffic, while others require a complete update of the Selenium test code.
General Solutions1. Exclude IP/ISP. The developer can create a custom filter for a particular IP address or a range of them, or the ISP to prevent recording internal traffic. The steps to follow are:
Select Admin, navigate to Filters and select Add Filter. Choose to Create New Filter and choose the custom feature. Look for the Exclude button and select it.
Select IP Address from the filter field and the IP address from the filter pattern.
The method may also filter out traffic that is not generated by Selenium as well. If the person conducting the tests uses a dynamic IP or distributed CI systems, maintaining all of them in Google Analytics may turn to be too tedious for them.
2. Edit Hosts File.One does not have to change the settings on Google Analytics. They can simply prevent traffic from reaching the server. It means that they will have to edit the host's file on the machines used to run the tests. It involves adding or removing permissions for the testing environment. It blocks all traffic from all sites, which is not an ideal thing to do for a site.
Selenium Specific Solutions
2. Set Custom User Agents.The Wrap Site in Google Analytics makes it possible to create an if statement to ignore traffic from some of the users using Selenium. It thus serves as another plausible solution to deal with the internal traffic from Selenium tests.
3. Opt-out Plugins.Google has official plugins that give the site owner an option to opt-out of Google Analytics. If one installs the plugin, then Google does not collect or use any information from that site. Selenium does not start without custom add-ons installed, which means that one will have to add them manually.
4. Use Proxy.BrowserMob is a proxy used by developers as it has an option to blacklist. It comes in handy when blocking data sent to Google Analytics.