📈 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
added PID support
Blue Mousee3ad55145c80
diff --git a/captcha-loader.js b/captcha-loader.jsindex ccd17ce10..f28e97f3b 100644--- a/captcha-loader.js+++ b/captcha-loader.js@@ -1,6 +1,6 @@(() => {const CAPTCHA_SELECTOR = '.swecaptcha'- const LIGHT_CAPTCHA_IFRAME_URL = './index.html'+ const LIGHT_CAPTCHA_IFRAME_URL = './light.html'const DARK_CAPTCHA_IFRAME_URL = './dark.html'const THEMES = ['light', 'dark']@@ -9,11 +9,21 @@console[status](`[Swetrix Captcha] ${text}`)}+ const appendParamsToURL = (url, params) => {+ const queryString = Object.keys(params).map((key) => {+ return `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`+ }).join('&')++ return `${url}?${queryString}`+ }+const renderCaptcha = (container, params) => {const { theme } = paramsconst captchaFrame = document.createElement('iframe')- captchaFrame.src = theme === 'dark' ? DARK_CAPTCHA_IFRAME_URL : LIGHT_CAPTCHA_IFRAME_URL+ captchaFrame.src = theme === 'dark' ?+ appendParamsToURL(DARK_CAPTCHA_IFRAME_URL, params) :+ appendParamsToURL(LIGHT_CAPTCHA_IFRAME_URL, params)captchaFrame.title = 'Swetrix Captcha'captchaFrame.style.border = 'none'captchaFrame.style.width = '302px'diff --git a/captcha.js b/captcha.jsindex e031d9b7c..9674f0176 100644--- a/captcha.js+++ b/captcha.js@@ -80,6 +80,7 @@ const generateCaptcha = async () => {},body: JSON.stringify({theme: window.__SWETRIX_CAPTCHA_THEME || DEFAULT_THEME,+ pid: window.__SWETRIX_PROJECT_ID,}),})@@ -102,6 +103,9 @@ const verify = async () => {headers: {'Content-Type': 'application/json',},+ body: JSON.stringify({+ pid: window.__SWETRIX_PROJECT_ID,+ }),})if (!response.ok) {@@ -143,6 +147,7 @@ document.addEventListener('DOMContentLoaded', () => {body: JSON.stringify({hash: HASH,code,+ pid: window.__SWETRIX_PROJECT_ID,}),headers: {'Content-Type': 'application/json',diff --git a/dark.html b/dark.htmlindex 29f232f20..0654bbc6e 100644--- a/dark.html+++ b/dark.html@@ -200,7 +200,11 @@}</style><script>- window.__SWETRIX_CAPTCHA_THEME = 'dark'+ window.__SWETRIX_CAPTCHA_THEME = 'light'+ const urlParams = new URLSearchParams(window.location.search)+ const pid = urlParams.get('pid')++ window.__SWETRIX_PROJECT_ID = pid</script><script src="captcha.js" defer></script></head>diff --git a/index.html b/light.htmlsimilarity index 97%rename from index.htmlrename to light.htmlindex 7facaf701..f985184d7 100644--- a/index.html+++ b/light.html@@ -184,6 +184,10 @@</style><script>window.__SWETRIX_CAPTCHA_THEME = 'light'+ const urlParams = new URLSearchParams(window.location.search)+ const pid = urlParams.get('pid')++ window.__SWETRIX_PROJECT_ID = pid</script><script src="captcha.js" defer></script></head>