📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
fix: Goals modal closes on stats refresh; describe IP blacklisting feature in the documentation
Blue Mouse6285e9ceebf8
diff --git a/docs/content/docs/script-reference.mdx b/docs/content/docs/script-reference.mdxindex b35de33b2..2c29f845a 100644--- a/docs/content/docs/script-reference.mdx+++ b/docs/content/docs/script-reference.mdx@@ -40,6 +40,8 @@ swetrix.init("YOUR_PROJECT_ID", {| profileId | Optional profile ID for long-term user tracking (MAU/DAU). If set, it will be used for all pageviews and events unless overridden per-call. This allows you to track users across sessions and devices. To also link the visitor's previous anonymous activity to this profile, use [identify()](#identify) instead. | `undefined` || preloadSessionReplay | Set to `true` to preload the session replay recorder after `init()`, or pass `{ rrwebUrl: "https://example.com/rrweb.min.js" }` to load it from a custom URL. Recording only starts after you call `startSessionReplay()`. | `undefined` |+To disable tracking only for your own browser, see [Exclude your own visits](/exclude-own-visits#exclude-only-your-browser-with-a-cookie) for a cookie-based example using `disabled`.+## Automatic outbound link trackingOutbound link tracking is **disabled by default**. Enable it in `init()`:diff --git a/docs/content/docs/sitesettings/exclude-own-visits.mdx b/docs/content/docs/sitesettings/exclude-own-visits.mdxnew file mode 100644index 000000000..4a02d119a--- /dev/null+++ b/docs/content/docs/sitesettings/exclude-own-visits.mdx@@ -0,0 +1,97 @@+---+title: Exclude your own visits+slug: /exclude-own-visits+description: "Stop tracking your own visits in Swetrix. Exclude your IP address in project settings or use a cookie to disable analytics in your browser."+---++You can keep your own visits, testing, and internal traffic out of your Swetrix statistics in two ways:++- **Block your IP address** in project settings. This requires no changes to your website and excludes everyone using that public IP address.+- **Set an exclusion cookie** in your browser after updating your tracking script. This excludes that browser, even when you change networks.++Both methods apply to future visits. They do not remove data that has already been collected.++## Exclude your IP address++1. Open the free [Swetrix IP lookup tool](https://swetrix.com/tools/ip-lookup) from the network you want to exclude and copy your public IP address.+2. Open your website's [Project Settings](/how-to-access-site-settings).+3. Select **Shields** under **Protection**.+4. Add your IP address to **Blocked IP addresses**. Press **Enter** or a comma to add it to the list, then wait for the save confirmation. Changes save automatically.++<img+ alt="Swetrix project settings with Shields selected and the Blocked IP addresses field visible"+ src="/docs/img/sitesettings/exclude-own-visits.webp"+ width="2384"+ height="1656"+/>++You can add multiple IP addresses or CIDR ranges, separated by commas. IPv4 and IPv6 are supported. Repeat this for each project where you want to exclude your visits.++Use the public address shown by the lookup tool, rather than a local address such as `192.168.0.1`. If your connection uses both IPv4 and IPv6, you may need to add both public addresses.++<Callout type="info">+ Blocking a public IP address also excludes other people who share it, such as colleagues on your+ office network. If your IP changes, or you switch networks or VPNs, update the blocked list. Use+ the cookie method below if you only want to exclude your own browser.+</Callout>++To include your visits again, remove your address using the **×** beside it and wait for the save confirmation.++## Exclude only your browser with a cookie++This method needs a small change to your website's tracking script. The cookie is a marker that your script checks; setting it alone does not disable Swetrix.++### 1. Update your tracking script++Update your existing `swetrix.init()` call to pass the [`disabled` option](/swetrix-js-reference#init):++```js+swetrix.init("YOUR_PROJECT_ID", {+ disabled: document.cookie.split(";").some((cookie) => cookie.trim() === "exclude_analytics=1"),+});+swetrix.trackViews();+```++Replace `YOUR_PROJECT_ID` with your project's ID and keep any other options from your existing installation. Make this change in your original initialisation call, before tracking starts. Adding a second `init()` call will not update an already initialised tracker.++The example uses the browser script's `swetrix` global. If you use the npm package, pass the same option to the `init()` function you already import. See the [installation guide](/install-script) for both installation methods.++### 2. Set the cookie on your website++Visit **your own website**, open your browser's developer tools, and run this in the Console:++```js+document.cookie = "exclude_analytics=1; path=/; max-age=31536000; SameSite=Lax";+```++Then **reload the page**. The tracker reads the cookie during initialisation and disables tracking when its value is `1`.++You can also use a cookie editor extension or your browser's developer tools to create the cookie manually:++- **Name:** `exclude_analytics`+- **Value:** `1`+- **Path:** `/`+- **Domain:** your website's hostname++The console snippet sets the cookie for one year on the current hostname. It applies only to that browser profile. Set it separately for other browsers, devices, or subdomains you use. Clearing cookies, opening a private browsing window, or letting the cookie expire means your visits can be tracked again.++### 3. Re-enable tracking++To remove the cookie created by the snippet, run this on the same website and reload:++```js+document.cookie = "exclude_analytics=; path=/; max-age=0; SameSite=Lax";+```++If you created the cookie manually with a different domain or path, delete that cookie using the same cookie editor.++## Check that your visits are excluded++After saving your IP block or setting the cookie and reloading, open a page on your website and check your project's live visitors or recent sessions. Your new visit should not appear. Visits recorded before the change may still be visible.++If you still see your visits:++- **For IP blocking:** check your current public IP again, confirm it is in the correct project's blocked list, and account for any VPN, network change, or IPv6 connection.+- **For the cookie:** confirm it is set on your website, its value is exactly `1`, and the deployed tracking script checks it in the first `init()` call. Reload after making changes.++The cookie method controls the JavaScript tracker in that browser. It does not exclude events sent independently by your backend or the `<noscript>` tracking pixel when JavaScript is disabled. Use IP blocking or apply an exclusion in your server-side integration for those cases.diff --git a/docs/content/docs/sitesettings/meta.json b/docs/content/docs/sitesettings/meta.jsonindex 146bb8bb2..7b86db97c 100644--- a/docs/content/docs/sitesettings/meta.json+++ b/docs/content/docs/sitesettings/meta.json@@ -3,6 +3,7 @@"pages": ["how-to-access-site-settings","project-configuration",+ "exclude-own-visits","bot-protection","how-to-invite-users-to-your-website","transfer-ownership",diff --git a/docs/content/docs/sitesettings/project-configuration.mdx b/docs/content/docs/sitesettings/project-configuration.mdxindex 3bf2819d1..5255a8895 100644--- a/docs/content/docs/sitesettings/project-configuration.mdx+++ b/docs/content/docs/sitesettings/project-configuration.mdx@@ -33,6 +33,8 @@ By default, Swetrix accepts events from any domain. If you want to restrict tracYou can ignore traffic from specific IP addresses or CIDR ranges, which is useful for excluding your own visits from analytics.+See [Exclude your own visits](/exclude-own-visits) for step-by-step instructions, a free IP lookup tool, and an alternative that disables tracking only in your browser using a cookie.+- Separate multiple values with commas.- Supports IPv4, IPv6, and CIDR ranges, for example `172.126.10.16`, `192.168.0.1/32`, or `::1`.diff --git a/docs/lib/source.ts b/docs/lib/source.tsindex 7b8a7d105..10f51d908 100644--- a/docs/lib/source.ts+++ b/docs/lib/source.ts@@ -25,6 +25,7 @@ const SLUG_MAP: Record<string, string[]> = {// Site settings → flat URLs"sitesettings/how-to-access-site-settings": ["how-to-access-site-settings"],"sitesettings/project-configuration": ["project-configuration-and-security"],+ "sitesettings/exclude-own-visits": ["exclude-own-visits"],"sitesettings/how-to-invite-users-to-your-website": ["how-to-invite-users-to-your-website"],"sitesettings/transfer-ownership": ["how-to-transfer-ownership-of-your-website"],"sitesettings/embed-your-analytics-dashboard-into-your-website": ["how-to-embed"],diff --git a/docs/public/img/sitesettings/exclude-own-visits.webp b/docs/public/img/sitesettings/exclude-own-visits.webpnew file mode 100644index 000000000..714224da5Binary files /dev/null and b/docs/public/img/sitesettings/exclude-own-visits.webp differdiff --git a/web/app/pages/Project/tabs/Experiments/ExperimentSettingsModal.tsx b/web/app/pages/Project/tabs/Experiments/ExperimentSettingsModal.tsxindex e96ed3bc5..06aaed4e8 100644--- a/web/app/pages/Project/tabs/Experiments/ExperimentSettingsModal.tsx+++ b/web/app/pages/Project/tabs/Experiments/ExperimentSettingsModal.tsx@@ -78,7 +78,7 @@ const ExperimentSettingsModal = ({const { fetchGoals } = useProjectGoalsProxy()const { fetchFeatureFlags } = useProjectFeatureFlagsProxy()const fetcher = useFetcher<ProjectViewActionData>()- const processedRef = useRef<string | null>(null)+ const processedRef = useRef<ProjectViewActionData | null>(null)const [isLoading, setIsLoading] = useState(false)const [goals, setGoals] = useState<Goal[]>([])@@ -314,9 +314,8 @@ const ExperimentSettingsModal = ({useEffect(() => {if (!fetcher.data || fetcher.state !== 'idle') return- const responseKey = `${fetcher.data.intent}-${fetcher.data.success}`- if (processedRef.current === responseKey) return- processedRef.current = responseKey+ if (processedRef.current === fetcher.data) return+ processedRef.current = fetcher.dataif (fetcher.data.success) {const { intent } = fetcher.data@@ -332,18 +331,10 @@ const ExperimentSettingsModal = ({}}, [fetcher.data, fetcher.state, t, onSuccess, onClose])- // Reset processed ref when modal opens- useEffect(() => {- if (isOpen) {- processedRef.current = null- }- }, [isOpen])-const handleSubmit = (e: React.FormEvent) => {e.preventDefault()if (!validateForm()) return- processedRef.current = nullconst effectiveFlagKey = featureFlagKey.trim() || suggestedFlagKeyconst formData = new FormData()diff --git a/web/app/pages/Project/tabs/FeatureFlags/FeatureFlagSettingsModal.tsx b/web/app/pages/Project/tabs/FeatureFlags/FeatureFlagSettingsModal.tsxindex 93d109351..c24cb60c0 100644--- a/web/app/pages/Project/tabs/FeatureFlags/FeatureFlagSettingsModal.tsx+++ b/web/app/pages/Project/tabs/FeatureFlags/FeatureFlagSettingsModal.tsx@@ -223,16 +223,8 @@ const FeatureFlagSettingsModal = ({}}, [fetcher.data, fetcher.state, t, onSuccess, onClose, isLoading])- // Reset ref when modal opens to allow fresh data handling- useEffect(() => {- if (isOpen) {- lastHandledData.current = null- }- }, [isOpen])-const handleSubmit = (e: React.FormEvent) => {e.preventDefault()- lastHandledData.current = nullif (scheduleChangeEnabled) {if (!scheduledApplyAt) {diff --git a/web/app/pages/Project/tabs/Goals/GoalSettingsModal.tsx b/web/app/pages/Project/tabs/Goals/GoalSettingsModal.tsxindex db2e5c1fe..d62794ea6 100644--- a/web/app/pages/Project/tabs/Goals/GoalSettingsModal.tsx+++ b/web/app/pages/Project/tabs/Goals/GoalSettingsModal.tsx@@ -211,7 +211,7 @@ const GoalSettingsModal = ({}: GoalSettingsModalProps) => {const { t } = useTranslation()const fetcher = useFetcher<ProjectViewActionData>()- const processedRef = useRef<string | null>(null)+ const processedRef = useRef<ProjectViewActionData | null>(null)const goalProxy = useGoalProxy()const isNew = !goalId@@ -317,9 +317,8 @@ const GoalSettingsModal = ({useEffect(() => {if (!fetcher.data || fetcher.state !== 'idle') return- const responseKey = `${fetcher.data.intent}-${fetcher.data.success}`- if (processedRef.current === responseKey) return- processedRef.current = responseKey+ if (processedRef.current === fetcher.data) return+ processedRef.current = fetcher.dataif (fetcher.data.success) {const { intent } = fetcher.data@@ -335,15 +334,8 @@ const GoalSettingsModal = ({}}, [fetcher.data, fetcher.state, t, onSuccess, onClose])- useEffect(() => {- if (isOpen) {- processedRef.current = null- }- }, [isOpen])-const handleSubmit = (e: React.FormEvent) => {e.preventDefault()- processedRef.current = nullconst mappedConditions: GoalCondition[] = []let hasUnmappableCondition = false