📈 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
(feature) Bypass adblockers (#17)
Andrii Romasiunce6ff2bb6e11
diff --git a/.prettierrc.js b/.prettierrc.jsnew file mode 100644index 000000000..bd6302ddd--- /dev/null+++ b/.prettierrc.js@@ -0,0 +1,13 @@+module.exports = {+ printWidth: 120, // max 120 chars in line, code is easy to read+ useTabs: false, // use spaces instead of tabs+ tabWidth: 2, // "visual width" of of the "tab"+ trailingComma: 'all', // add trailing commas in objects, arrays, etc.+ semi: false, // Only add semicolons at the beginning of lines that may introduce ASI failures+ singleQuote: true, // '' for stings instead of ""+ bracketSpacing: true, // import { some } ... instead of import {some} ...+ arrowParens: 'always', // braces even for single param in arrow functions (a) => { }+ jsxSingleQuote: true, // '' for react props+ bracketSameLine: false, // pretty JSX+ endOfLine: 'lf', // 'lf' for linux, 'crlf' for windows, we need to use 'lf' for git+}diff --git a/docs/adblockers/guides/nginx.md b/docs/adblockers/guides/nginx.mdnew file mode 100644index 000000000..8211d035f--- /dev/null+++ b/docs/adblockers/guides/nginx.md@@ -0,0 +1,59 @@+---+title: How to proxy Swetrix with Nginx+slug: /adblockers/guides/nginx+---++If you are already using Nginx on your website, you can add Swetrix to your configuration to proxy it.++## Update your Nginx configuration+```+# The `proxy_cache` part is only needed if you cache swetrix.js script.+# If you use Swetrix from NPM, there's no need to proxy it.+#+# Note: to use the `proxy_cache` setup, you'll need to make sure the `/var/run/nginx-cache`+# directory exists (e.g. creating it in a build step with `mkdir -p /var/run/nginx-cache`)+# and is readable (including all its parent directories) by your nginx worker user.+#+# To make `/var/run/nginx-cache` persist during reboots of your server+# make sure to run `echo "D /var/run/nginx-cache 0755 root root -" > /usr/lib/tmpfiles.d/nginx-cache.conf`+proxy_cache_path /var/run/nginx-cache/jscache levels=1:2 keys_zone=jscache:100m inactive=30d use_temp_path=off max_size=100m;++server {+ # Using the Cloudflare DNS resolver, you can remove this line if you already use a resolver in your config, or change it to a resolver of your choice.+ resolver 1.1.1.1;++ set $swetrix_script_url https://swetrix.org/swetrix.js;+ set $swetrix_log_url https://api.swetrix.com/log;++ location = /script.js {+ proxy_pass $swetrix_script_url;+ proxy_set_header Host $host;+ proxy_buffering on;++ # Cache the script for 6 hours, as long as swetrix.org returns a valid response+ proxy_cache jscache;+ proxy_cache_valid 200 301 302 6h;+ proxy_cache_use_stale updating error timeout invalid_header http_500;+ }++ # Setting the path to /log is optional, you can replace it with anything you want, like /proxy, /endpoint, etc.+ # Some aggressive adblockers may block requests to paths like /analytics, /collect, /log, etc.+ location = /log {+ proxy_set_header Host $host;+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;+ proxy_set_header X-Forwarded-Proto $scheme;+ proxy_buffering on;+ proxy_pass_request_headers on;+ proxy_pass $swetrix_log_url;+ }+}+```++## Update Swetrix tracking script configuration+After you updated your Nginx configuration, you need to update swetrix.js tracking script to send analytics data through your server. You can do it by setting the `apiURL` property inside the [init() function](/swetrix-js-reference#init).++```javascript+swetrix.init('YOUR_PROJECT_ID', {+ apiURL: 'https://<yourproxydomain>/log',+})+```diff --git a/docs/adblockers/how-to-deal-with-adblockers.md b/docs/adblockers/how-to-deal-with-adblockers.mdnew file mode 100644index 000000000..0fcd83de4--- /dev/null+++ b/docs/adblockers/how-to-deal-with-adblockers.md@@ -0,0 +1,27 @@+---+title: How to deal with adblockers+slug: /adblockers/how-to+---++import useBaseUrl from '@docusaurus/useBaseUrl';++Swetrix is a privacy-first analytics tool, but some adblockers may still block it. In most cases, adblock maintainers don't want to take responsibility for deciding which services to block and which not to block, and we don't blame them. It's a big responsibility to maintain such ad block lists.++Nevertheless, Swetrix is an open source, privacy-focused, cookie-less web analytics service. We never sell, share or do anything nasty with your data, and we want to give you the choice to bypass ad blockers.++On average, [32% of users](https://backlinko.com/ad-blockers-users?ref=swetrix) use adblockers, but it depends on your site's audience (tech audiences tend to use adblockers much more). If you're not concerned about missing data, we recommend using one of our standard [integration guides](/integrations).++## How to proxy Swetrix+The most effective way to bypass ad blockers is to proxy the Swetrix script and calls to the Swetrix servers through this script.++A proxy is basically the mapping of our servers' URLs through your domain. So analytics requests will not be sent to `https://api.swetrix.com/log`, but instead to `https://<your domain>/path`.++The advantage of this approach is that your site will only make first-party requests, preventing them from being blocked by adblockers.++### How to proxy tracking script?+If you've installed [Swetrix using npm](/install-script#install-swetrix-via-npm), you don't need to proxy it as it's already bundled into your web application's code (but you still need to proxy our API, see one of the proxy guides below).++If you have installed Swetrix using our CDN (`swetrix.org/swetrix.js`), you will need to proxy it to bypass adblockers. Please refer to one of the guides below on how to do this.++### Managed proxy guides+ - [Nginx](/adblockers/guides/nginx)diff --git a/sidebars.js b/sidebars.jsindex ffe143ec6..b4b38ca33 100644--- a/sidebars.js+++ b/sidebars.js@@ -8,7 +8,15 @@ module.exports = {{type: 'category',label: 'Integrations',- items: ['integrations/wordpress', 'integrations/webflow', 'integrations/framer', 'integrations/wix', 'integrations/ghost', 'integrations/django', 'integrations/sveltekit'],+ items: [+ 'integrations/wordpress',+ 'integrations/webflow',+ 'integrations/framer',+ 'integrations/wix',+ 'integrations/ghost',+ 'integrations/django',+ 'integrations/sveltekit',+ ],},'troubleshooting',],@@ -25,32 +33,25 @@ module.exports = {'billing/cancel-subscription','billing/faq',],- 'Affiliate program': [- 'affiliate/about',- 'affiliate/terms',- ],- 'Extensions SDK': [- 'ext-sdk-introduction',- 'ext-sdk-faq',- 'ext-sdk-reference',- ],- 'API': [- 'api/stats',- 'api/events',- 'api/admin',- ],- 'CAPTCHA': [- 'captcha/introduction',- 'captcha/client-side-usage',- 'captcha/server-side-validation',- 'captcha/testing',- ],- 'Self-hosting': [- 'selfhosting/how-to',- 'selfhosting/configuring',- ],- 'Contribute': [- 'contribute/how-to',+ Adblockers: [+ 'adblockers/how-to-deal-with-adblockers',+ {+ type: 'category',+ label: 'Proxy guides',+ items: [+ {+ id: 'adblockers/guides/nginx',+ type: 'doc',+ label: 'Nginx',+ },+ ],+ },],+ 'Affiliate program': ['affiliate/about', 'affiliate/terms'],+ 'Extensions SDK': ['ext-sdk-introduction', 'ext-sdk-faq', 'ext-sdk-reference'],+ API: ['api/stats', 'api/events', 'api/admin'],+ CAPTCHA: ['captcha/introduction', 'captcha/client-side-usage', 'captcha/server-side-validation', 'captcha/testing'],+ 'Self-hosting': ['selfhosting/how-to', 'selfhosting/configuring'],+ Contribute: ['contribute/how-to'],},}