How to exclude Google Analytics in your Cypress E2E tests

Published on
Last updated

Since starts a browser to run the end-to-end tests, your Google Analytics tracking calls (also from other analytics services like are made, and you don’t want to have wrong analytics.

Looking through cypress’ documentation I finally found the blockHosts option that can be specified in your cypress.json configuration file.

Simply blacklist * by adding an entry to cypress.json like this:

  "blockHosts": "*",
  "video": false

But I want to specify more than one host to block

Simply specify blockHosts as an array, as the documentation says

By passing a string or array of strings you can block requests made to one or more hosts.

For example, to block calls to * and *, simply write:

  "blockHosts": ["*", "*"]

Update 2021-06-23

The blacklistHosts configuration option has been renamed to blockHosts.

Thanks to for reporting

Here, have a slice of pizza 🍕