From dde5116a76763c626541ed500a85454c389c5164 Mon Sep 17 00:00:00 2001
From: Iiro Krankka <iiro.krankka@gmail.com>
Date: Thu, 18 Mar 2021 14:41:03 +0200
Subject: [PATCH] Stop analytics tracking if running under Cypress tests (#850)

* Stop tracking if running under Cypress tests

* Update CHANGELOG.md
---
 CHANGELOG.md             | 1 +
 tracker/src/plausible.js | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 55d2d511..02718b5a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file.
 ### Fixed
 - Capitalized date/time selection keybinds not working plausible/analytics#709
 - Invisible text on Google Search Console settings page in dark mode plausible/analytics#759
+- Disable analytics tracking when running Cypress tests
 
 ## [1.2] - 2021-01-26
 
diff --git a/tracker/src/plausible.js b/tracker/src/plausible.js
index eb460d17..589c8cac 100644
--- a/tracker/src/plausible.js
+++ b/tracker/src/plausible.js
@@ -18,7 +18,7 @@
 
   function trigger(eventName, options) {
     if (/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/.test(location.hostname) || location.protocol === 'file:') return warn('localhost');
-    if (window.phantom || window._phantom || window.__nightmare || window.navigator.webdriver) return;
+    if (window.phantom || window._phantom || window.__nightmare || window.navigator.webdriver || window.Cypress) return;
     if (plausible_ignore=="true") return warn('localStorage flag')
     {{#if exclusionMode}}
     if (excludedPaths)
-- 
GitLab