π 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
Use Fumadocs UI components for nicer docs
Blue Mouse618bece5003d
diff --git a/docs/app/[[...slug]]/page.tsx b/docs/app/[[...slug]]/page.tsxindex c0a8a4143..2deaf5146 100644--- a/docs/app/[[...slug]]/page.tsx+++ b/docs/app/[[...slug]]/page.tsx@@ -9,6 +9,7 @@ import defaultMdxComponents from 'fumadocs-ui/mdx';import { notFound } from 'next/navigation';import { FeedbackWidget } from '@/components/FeedbackWidget';import { IntegrationsGrid } from '@/components/IntegrationsGrid';+import { getMDXComponents } from '@/mdx-components';export default async function Page(props: {params: Promise<{ slug?: string[] }>;@@ -32,7 +33,7 @@ export default async function Page(props: {<DocsTitle>{page.data.title}</DocsTitle><DocsDescription>{page.data.description}</DocsDescription><DocsBody>- <Mdx components={{ ...defaultMdxComponents, IntegrationsGrid }} />+ <Mdx components={getMDXComponents({ IntegrationsGrid })} /><FeedbackWidget /></DocsBody></DocsPage>diff --git a/docs/content/docs/add-script.mdx b/docs/content/docs/add-script.mdxindex bcbaf2b1c..c729d7481 100644--- a/docs/content/docs/add-script.mdx+++ b/docs/content/docs/add-script.mdx@@ -16,7 +16,8 @@ See [CMS & website builder integrations](/integrations#cms--website-builders).</Callout>-## Edit the website's HTML code+<Tabs items={["HTML script tag", "npm package"]}>+<Tab value="HTML script tag">The easiest way to add the tracking script to your website is to edit the HTML code of your website.To do this, paste the following code snippet into the Body section (`<body>` tag). You have to place the script within the `<body>...</body>` tags.@@ -47,21 +48,30 @@ It's important to remember to replace `YOUR_PROJECT_ID` with your actual ProjectDone. Now you can start using Swetrix on your website.-## Install Swetrix via npm+</Tab>+<Tab value="npm package">If you are using a website based on a JavaScript framework such as React or Vue, you can install Swetrix via npm and use it on your website.-To install Swetrix using npm, run the following command in your terminal:+<Steps>+<Step>+### Install the package```bashnpm install swetrix```+</Step>+<Step>+### Import Swetrix-Next, you should import the module into your project's root file (in React this is usually called `index.js` or `App.js`, and these files are located in the `src` folder):+Import the module into your project's root file (in React this is usually called `index.js` or `App.js`, and these files are located in the `src` folder):```jsimport * as Swetrix from 'swetrix'```+</Step>+<Step>+### Start trackingAfter that you can track anything you want. For example, the following code snippet will work just fine:@@ -69,3 +79,8 @@ After that you can track anything you want. For example, the following code snipSwetrix.init('YOUR_PROJECT_ID')Swetrix.trackViews()```+</Step>+</Steps>++</Tab>+</Tabs>diff --git a/docs/content/docs/billing/exceeding-plan-limits.mdx b/docs/content/docs/billing/exceeding-plan-limits.mdxindex 63da16e72..ec50582e1 100644--- a/docs/content/docs/billing/exceeding-plan-limits.mdx+++ b/docs/content/docs/billing/exceeding-plan-limits.mdx@@ -3,7 +3,9 @@ title: Exceeding your subscription plan limitsslug: /exceeding-plan-limits----First of all, we don't stop collecting traffic or charge extra if you have an occasional traffic spike. We also don't stop collecting data if you miss your invoice for a short period of time. There are no hidden charges and we won't charge your card unexpectedly.+<Callout type="info">+We don't stop collecting traffic or charge extra if you have an occasional traffic spike. We also don't stop collecting data if you miss your invoice for a short period of time. There are no hidden charges and we won't charge your card unexpectedly.+</Callout>If you exceed your subscription plan, we won't automatically upgrade you to the next one because it's unethical.@@ -16,6 +18,8 @@ If this happens, we will not lock your dashboard immediately. Instead, we will gWe may also lock your dashboard if you miss a bill. We will lock the dashboard after 5 failed attempts.-We will not stop collecting your analytics data even if your dashboard is temporarily locked. If you upgrade to an appropriate toer that reflects your traffic usage (or the payment issues are resolved) - the dashboard will automatically be unlocked.+<Callout>+We will not stop collecting your analytics data even if your dashboard is temporarily locked. If you upgrade to an appropriate tier that reflects your traffic usage (or the payment issues are resolved) - the dashboard will automatically be unlocked.+</Callout>We will only stop collecting data if our invoices go unpaid for many months, the dashboard is locked for a long time, or if you have exceptionally high traffic to your site and the billing issue is not resolved.diff --git a/docs/content/docs/billing/upgrade-from-trial.mdx b/docs/content/docs/billing/upgrade-from-trial.mdxindex 40c5cc3ad..2e2199356 100644--- a/docs/content/docs/billing/upgrade-from-trial.mdx+++ b/docs/content/docs/billing/upgrade-from-trial.mdx@@ -6,23 +6,33 @@ slug: /upgrade-from-trial-to-a-paid-subscriptionAt any time during your trial, or once it's over, you can upgrade to a paid subscription.+<Callout type="info">We do not stop collection or reset your collected data. The analytics data is preserved when you update from a trial to a paid plan, or change your paid subscription to another plan.+</Callout>## Updating to a paid subscription-To update to a paid plan, you need to log in to your account and go to the [billing page](https://swetrix.com/billing).+<Steps>+<Step>+### Choose a plan++Log in to your account and go to the [billing page](https://swetrix.com/billing).You will see the Plan usage section with an indicator of how many events you used during the current calendar month. You can hover over this chart and see what kind of events you used during that period.We count pageviews, error events, and custom events as "events".-Using the subscription plan selector, you can choose a plan based on your estimated usage, and the billing frequency (monthly or yearly). You can get 2 free months with a yearly subscription.+Using the subscription plan selector, choose a plan based on your estimated usage, and the billing frequency (monthly or yearly). You can get 2 free months with a yearly subscription.+</Step>+<Step>+### Start the upgradeOnce you choose your subscription plan, click on the "Upgrade" button to get started.<img alt="Upgrade to a paid subscription" src="/docs/img/billing/subscription-selector.png" />--## Choosing your payment method and subscribing+</Step>+<Step>+### Complete paymentThe billing information and the payment process is handled by Paddle, a third-party payment processor. Click on the "Subscribe" button to proceed.@@ -33,6 +43,8 @@ Choose your location and click on the "Continue" button.Next you need to select your payment method and enter your payment details. You can pay by PayPal, payment card, or Apple and Google Pay if supported by your device.After you're done, click on the "Subscribe now" button to complete the subscription. You'll receive an email confirmation and your subscription will be active immediately.+</Step>+</Steps>## Opt into company VAT refund for your subscription@@ -44,4 +56,4 @@ You can also add your VAT number after you created a subscription, to do that op<img alt="Add VAT on existing invoice" src="/docs/img/billing/invoice_add_vat.png" />-To learn more about billing, visit our [billing FAQ page].+To learn more about billing, visit our [billing FAQ page](/billing-faq).diff --git a/docs/content/docs/captcha/client-side-usage.mdx b/docs/content/docs/captcha/client-side-usage.mdxindex 4785b01ff..d1ef38a96 100644--- a/docs/content/docs/captcha/client-side-usage.mdx+++ b/docs/content/docs/captcha/client-side-usage.mdx@@ -9,7 +9,8 @@ You can use the CAPTCHA widget on any page of your website by using our CAPTCHA## Installation-### Using CDN+<Tabs items={["CDN", "npm"]}>+<Tab value="CDN">The easiest way to add the CAPTCHA script to your website is to edit the HTML code of your website. To do this, paste the following code snippet into the header section (`<head>` tag) of your website:@@ -17,10 +18,14 @@ The easiest way to add the CAPTCHA script to your website is to edit the HTML co<script src="https://cdn.swetrixcaptcha.com/captcha-loader.js" defer></script>```-### Using NPM+</Tab>+<Tab value="npm">**Not yet supported**+</Tab>+</Tabs>+## UsageOnce the CAPTCHA script is installed (or embedded) on your website, you can use the CAPTCHA widget by adding the following HTML code to your page:diff --git a/docs/content/docs/captcha/introduction.mdx b/docs/content/docs/captcha/introduction.mdxindex c801a84e3..b7d0b325f 100644--- a/docs/content/docs/captcha/introduction.mdx+++ b/docs/content/docs/captcha/introduction.mdx@@ -9,10 +9,23 @@ Swetrix CAPTCHA is a fully open source, cookieless, and privacy-friendly CAPTCHAUnlike traditional CAPTCHAs that require users to identify objects in images or solve puzzles, Swetrix CAPTCHA uses a **Proof of Work (PoW)** mechanism.-1. **Challenge Request**: When a user interacts with a protected form, the client requests a challenge from the Swetrix server.-2. **PoW Calculation**: The client-side script performs a cryptographic calculation (Proof of Work) in the background. This requires a small amount of computational power from the user's device, which is trivial for a legitimate user but computationally expensive for bots trying to spam at scale.-3. **Verification**: The solution to the PoW challenge is sent back to the server for verification.+<Steps>+<Step>+### Challenge Request+When a user interacts with a protected form, the client requests a challenge from the Swetrix server.+</Step>+<Step>+### PoW Calculation+The client-side script performs a cryptographic calculation (Proof of Work) in the background. This requires a small amount of computational power from the user's device, which is trivial for a legitimate user but computationally expensive for bots trying to spam at scale.+</Step>+<Step>+### Verification+The solution to the PoW challenge is sent back to the server for verification.+</Step>+</Steps>This approach provides a seamless user experience (no more "select all traffic lights") while effectively deterring automated bots.+<Callout type="info">You can find the demonstration of the CAPTCHA widget [here](https://captcha.swetrix.com/demo).+</Callout>diff --git a/docs/content/docs/captcha/server-side-validation.mdx b/docs/content/docs/captcha/server-side-validation.mdxindex 1e03c1b83..d8d740bda 100644--- a/docs/content/docs/captcha/server-side-validation.mdx+++ b/docs/content/docs/captcha/server-side-validation.mdx@@ -15,7 +15,8 @@ Token validation can only be performed once, if you try to validate the same tok</Callout>-## Validation via HTTP request+<Tabs items={["HTTP request", "Node.js library"]}>+<Tab value="HTTP request">To validate the token, you have to send a POST request to the `https://api.swetrix.com/v1/captcha/validate` URL, with the following parameters:@@ -24,8 +25,6 @@ To validate the token, you have to send a POST request to the `https://api.swetr| token | string | The token returned by the CAPTCHA widget. || secret | string | Your CAPTCHA project secret key. |-<br />-The successful response will have the `success` field set to `true` and the `data` field will contain the following fields:| Field | Type | Description |@@ -45,8 +44,6 @@ The successful response will have the `success` field set to `true` and the `dat}```-<br />-The failed response will throw an error that will look like the following example. The HTTP status code will correspond to the `statusCode` in JSON.```json@@ -57,8 +54,6 @@ The failed response will throw an error that will look like the following exampl}```-<br />-Here's an example of how to validate the token using `curl`:```bash@@ -68,7 +63,8 @@ curl -X POST\https://api.swetrix.com/v1/captcha/validate```-## Validation via Node.js library+</Tab>+<Tab value="Node.js library">You can use the [@swetrix/captcha-validator](https://www.npmjs.com/package/@swetrix/captcha-validator) package to validate the token in your Node.js project.@@ -81,8 +77,6 @@ The package exports a single function `validateToken` which takes arguments list| secretKey | string | Your CAPTCHA project secret key. | YES || apiURL | string | The API URL to use (default: `https://api.swetrix.com/captcha`), this one may be used in case you're selfhosting the API. | NO |-<br />-Here's an example of how to use the package in your project:```js@@ -98,3 +92,6 @@ validateToken('CAPTCHA_TOKEN', 'YOUR_SECRET_KEY').then((result) => {console.log(status, data)})```++</Tab>+</Tabs>diff --git a/docs/content/docs/contribute/how-to.mdx b/docs/content/docs/contribute/how-to.mdxindex 81ac9265a..067fa5754 100644--- a/docs/content/docs/contribute/how-to.mdx+++ b/docs/content/docs/contribute/how-to.mdx@@ -12,3 +12,7 @@ Here are some ways you can contribute to the project:- Help us with the development of Swetrix. All our source codes are available on [GitHub](https://github.com/swetrix), we also have an open roadmap filled with tasks [there](https://github.com/orgs/Swetrix/projects/2).- Contribute by translating Swetrix into the language you know. We use [Crowdin](https://crowdin.com/project/swetrix) to manage translations. All translations are provided by the community, thanks for your help!- Report a bug to [Report](https://github.com/Swetrix/roadmap/issues) or make a feature request on our Github issues page. We are always open to your ideas and suggestions.++<Callout type="info">+All Swetrix repositories are open source and available on [GitHub](https://github.com/Swetrix). We welcome contributions of all kinds β from code to translations to documentation.+</Callout>diff --git a/docs/content/docs/error-tracking.mdx b/docs/content/docs/error-tracking.mdxindex c115d6a70..2e0566e67 100644--- a/docs/content/docs/error-tracking.mdx+++ b/docs/content/docs/error-tracking.mdx@@ -7,4 +7,6 @@ icon: BugAs well as providing you with regular data insights such as traffic or site speed, Swetrix also offers client-side error tracking.This allows you to track when, on which pages and what kind of errors your users are experiencing. The error tracking script is included in swetrix.js by default and can be easily enabled with a [one line of code](/swetrix-js-reference#trackerrors).+<Callout type="info">Error tracking is included in all plans and is charged as 1 error event = 1 regular event (like a pageview or custom event).+</Callout>diff --git a/docs/content/docs/integrations/astro.mdx b/docs/content/docs/integrations/astro.mdxindex dc5328084..209dc37aa 100644--- a/docs/content/docs/integrations/astro.mdx+++ b/docs/content/docs/integrations/astro.mdx@@ -16,13 +16,12 @@ There are two ways to add Swetrix to your Astro site:| **CDN script** | Simple sites, blogs, and documentation β no build-time dependency required || **npm package** | Full TypeScript support, tighter integration with island components, more configuration options |-### Option A: CDN script (recommended for most sites)+<Tabs items={["CDN script (recommended)", "npm package"]}>+<Tab value="CDN script (recommended)">The simplest way to add Swetrix is to include the tracking script in a shared layout component. No npm install needed.-**1. Add the script to your layout**--Open your base layout (e.g. `src/layouts/Layout.astro`) and add the Swetrix script inside the `<head>`:+Add the script to your base layout (e.g. `src/layouts/Layout.astro`) inside the `<head>`:```html---@@ -61,8 +60,6 @@ Replace `YOUR_PROJECT_ID` with your actual Project ID from the [Swetrix dashboar</Callout>-**2. Use the layout on your pages**-Make sure your pages use this layout so the script is included on every page:```html@@ -78,7 +75,8 @@ import Layout from '../layouts/Layout.astro';Since Astro builds multi-page applications by default, each navigation triggers a full page load and Swetrix will automatically track each page view.-### Option B: npm package+</Tab>+<Tab value="npm package">If you want full TypeScript support or need fine-grained control (e.g. custom init options, programmatic event tracking from island components), install the npm package instead.@@ -86,9 +84,9 @@ If you want full TypeScript support or need fine-grained control (e.g. custom innpm install swetrix```-Create a client-side script that initialises Swetrix and add it to your layout.--**1. Create the analytics script**+<Steps>+<Step>+### Create the analytics scriptCreate `src/scripts/analytics.ts`:@@ -98,10 +96,11 @@ import * as Swetrix from 'swetrix'Swetrix.init('YOUR_PROJECT_ID')Swetrix.trackViews()```+</Step>+<Step>+### Include it in your layout-**2. Include it in your layout**--Add the script to your base layout with the `client:load` directive via a `<script>` tag:+Add the script to your base layout:```html---@@ -130,6 +129,8 @@ const { title } = Astro.props;</body></html>```+</Step>+</Steps><Callout type="warn">@@ -143,6 +144,25 @@ Astro processes `<script>` tags β they're bundled and deduplicated automatical</Callout>+Your project structure should look like this:++<Files>+ <Folder name="src" defaultOpen>+ <Folder name="layouts" defaultOpen>+ <File name="Layout.astro" />+ </Folder>+ <Folder name="pages" defaultOpen>+ <File name="index.astro" />+ </Folder>+ <Folder name="scripts" defaultOpen>+ <File name="analytics.ts" />+ </Folder>+ </Folder>+</Files>++</Tab>+</Tabs>+## View Transitions supportIf you're using [Astro's View Transitions](https://docs.astro.build/en/guides/view-transitions/) for client-side navigation, no extra configuration is needed. Swetrix's `trackViews()` automatically detects route changes via the History API, so View Transition navigations are tracked out of the box.@@ -165,7 +185,10 @@ To track visitors who have JavaScript disabled, add a noscript image pixel to yoBy default, Swetrix ignores `localhost` traffic. If you want to be explicit about it, you can conditionally disable tracking in development.-**CDN script** β wrap the initialisation in a host check:+<Tabs items={["CDN script", "npm package"]}>+<Tab value="CDN script">++Wrap the initialisation in a host check:```html<script>@@ -178,7 +201,10 @@ By default, Swetrix ignores `localhost` traffic. If you want to be explicit abou</script>```-**npm package** β use `import.meta.env`:+</Tab>+<Tab value="npm package">++Use `import.meta.env`:```typescriptimport * as Swetrix from 'swetrix'@@ -189,6 +215,9 @@ Swetrix.init('YOUR_PROJECT_ID', {Swetrix.trackViews()```+</Tab>+</Tabs>+<Callout type="info">If you want to verify tracking locally during development, set `devMode: true` instead:@@ -211,7 +240,8 @@ Build and deploy your site (or temporarily enable `devMode`) and visit a few pagEnable automatic client-side error monitoring to capture unhandled JavaScript errors and report them to Swetrix.-**CDN script:**+<Tabs items={["CDN script", "npm package"]}>+<Tab value="CDN script">```html<script>@@ -223,7 +253,8 @@ Enable automatic client-side error monitoring to capture unhandled JavaScript er</script>```-**npm package:**+</Tab>+<Tab value="npm package">```typescriptimport * as Swetrix from 'swetrix'@@ -233,6 +264,9 @@ Swetrix.trackViews()Swetrix.trackErrors()```+</Tab>+</Tabs>+Errors will appear in the **Errors** tab of your project dashboard. See the [tracking script reference](/swetrix-js-reference#trackerrors) for options like `sampleRate` and `callback`.## Tracking custom eventsdiff --git a/docs/content/docs/integrations/nextjs.mdx b/docs/content/docs/integrations/nextjs.mdxindex 293d66e70..dc6f50dc5 100644--- a/docs/content/docs/integrations/nextjs.mdx+++ b/docs/content/docs/integrations/nextjs.mdx@@ -15,11 +15,14 @@ The recommended approach for Next.js is to install Swetrix as an npm package, whnpm install swetrix```-### App Router (recommended)+<Tabs items={["App Router (recommended)", "Pages Router"]}>+<Tab value="App Router (recommended)">Create a client component that initialises Swetrix. `trackViews()` automatically detects client-side route changes, so you only need to call it once.-**1. Create the analytics component**+<Steps>+<Step>+### Create the analytics componentCreate a new file at `src/components/Analytics.tsx` (or `src/components/Analytics.jsx` if you're not using TypeScript):@@ -38,8 +41,9 @@ export default function Analytics() {return null}```--**2. Add it to your root layout**+</Step>+<Step>+### Add it to your root layoutOpen `src/app/layout.tsx` and render the `Analytics` component:@@ -61,6 +65,22 @@ export default function RootLayout({)}```+</Step>+</Steps>++Your project structure should look like this:++<Files>+ <Folder name="src" defaultOpen>+ <Folder name="app" defaultOpen>+ <File name="layout.tsx" />+ <File name="page.tsx" />+ </Folder>+ <Folder name="components" defaultOpen>+ <File name="Analytics.tsx" />+ </Folder>+ </Folder>+</Files><Callout type="warn">@@ -68,7 +88,8 @@ Replace `YOUR_PROJECT_ID` with your actual Project ID from the [Swetrix dashboar</Callout>-### Pages Router+</Tab>+<Tab value="Pages Router">If you're using the Pages Router, add Swetrix to your `_app.tsx` (or `_app.jsx`) file. `trackViews()` automatically detects route changes, so a single call is all you need.@@ -87,11 +108,17 @@ export default function App({ Component, pageProps }: AppProps) {}```+</Tab>+</Tabs>+### Noscript fallback (optional)To track visitors who have JavaScript disabled, add a noscript image pixel to your root layout (App Router) or `_document.tsx` (Pages Router).-**App Router** β add to `src/app/layout.tsx` inside `<body>`:+<Tabs items={["App Router", "Pages Router"]}>+<Tab value="App Router">++Add to `src/app/layout.tsx` inside `<body>`:```tsx<noscript>@@ -103,7 +130,10 @@ To track visitors who have JavaScript disabled, add a noscript image pixel to yo</noscript>```-**Pages Router** β add to `pages/_document.tsx` inside `<body>`:+</Tab>+<Tab value="Pages Router">++Add to `pages/_document.tsx` inside `<body>`:```tsximport { Html, Head, Main, NextScript } from 'next/document'@@ -128,6 +158,9 @@ export default function Document() {}```+</Tab>+</Tabs>+## Disable tracking in developmentBy default, Swetrix ignores `localhost` traffic. If you want to be explicit about it, you can conditionally disable tracking based on your environment:@@ -160,7 +193,10 @@ Deploy your application (or temporarily enable `devMode`) and visit a few pages.Enable automatic client-side error monitoring by adding `trackErrors()` to your analytics component. This captures unhandled JavaScript errors and reports them to Swetrix.-**App Router** β update `src/components/Analytics.tsx`:+<Tabs items={["App Router", "Pages Router"]}>+<Tab value="App Router">++Update `src/components/Analytics.tsx`:```tsxuseEffect(() => {@@ -170,7 +206,10 @@ useEffect(() => {}, [])```-**Pages Router** β update `_app.tsx`:+</Tab>+<Tab value="Pages Router">++Update `_app.tsx`:```tsxuseEffect(() => {@@ -180,6 +219,9 @@ useEffect(() => {}, [])```+</Tab>+</Tabs>+Errors will appear in the **Errors** tab of your project dashboard. See the [tracking script reference](/swetrix-js-reference#trackerrors) for options like `sampleRate` and `callback`.## Tracking custom eventsdiff --git a/docs/content/docs/integrations/nuxt.mdx b/docs/content/docs/integrations/nuxt.mdxindex 22cf44fbe..2c9182ffa 100644--- a/docs/content/docs/integrations/nuxt.mdx+++ b/docs/content/docs/integrations/nuxt.mdx@@ -30,6 +30,17 @@ export default defineNuxtPlugin(() => {That's it β Nuxt auto-registers files in the `plugins/` directory. `trackViews()` automatically detects client-side route changes, so page views are tracked on every navigation.+<Files>+ <Folder name="plugins" defaultOpen>+ <File name="swetrix.client.ts" />+ </Folder>+ <Folder name="pages">+ <File name="index.vue" />+ </Folder>+ <File name="app.vue" />+ <File name="nuxt.config.ts" />+</Files>+<Callout type="warn">Replace `YOUR_PROJECT_ID` with your actual Project ID from the [Swetrix dashboard](https://swetrix.com/projects), otherwise tracking won't work.@@ -209,7 +220,9 @@ We recommend `UPPER_SNAKE_CASE` for consistency (e.g. `SIGNUP_CTA_CLICK`, `CONTARather than hardcoding your Project ID, use Nuxt's [runtime config](https://nuxt.com/docs/guide/going-further/runtime-config).-**1. Add to your `nuxt.config.ts`:**+<Steps>+<Step>+### Add to your `nuxt.config.ts````tsexport default defineNuxtConfig({@@ -220,19 +233,23 @@ export default defineNuxtConfig({},})```--**2. Set the environment variable:**+</Step>+<Step>+### Set the environment variable```NUXT_PUBLIC_SWETRIX_PID=YOUR_PROJECT_ID```--**3. Reference it in your plugin:**+</Step>+<Step>+### Reference it in your plugin```tsconst config = useRuntimeConfig()Swetrix.init(config.public.swetrixPid)```+</Step>+</Steps>## Further readingdiff --git a/docs/content/docs/integrations/sveltekit.mdx b/docs/content/docs/integrations/sveltekit.mdxindex 94e952cc1..cc27d247e 100644--- a/docs/content/docs/integrations/sveltekit.mdx+++ b/docs/content/docs/integrations/sveltekit.mdx@@ -7,9 +7,19 @@ After you sign up on Swetrix and create a new project, the only thing left is to## Installation-1. Install the Swetrix package via `npm install swetrix`.-2. Go to your SvelteKit website codebase and either create a new `+layout.svelte` file or use an existing one.-3. Make your layout file look like this:+<Steps>+<Step>+### Install the Swetrix package++```bash+npm install swetrix+```+</Step>+<Step>+### Create or update your layout file++Go to your SvelteKit website codebase and either create a new `+layout.svelte` file or use an existing one.+Make your layout file look like this:```html<script>@@ -28,6 +38,8 @@ After you sign up on Swetrix and create a new project, the only thing left is to````trackViews()` automatically detects client-side route changes, so you only need to call it once.+</Step>+</Steps><Callout type="warn">diff --git a/docs/content/docs/integrations/wordpress.mdx b/docs/content/docs/integrations/wordpress.mdxindex 5861d32fd..782fe7b72 100644--- a/docs/content/docs/integrations/wordpress.mdx+++ b/docs/content/docs/integrations/wordpress.mdx@@ -7,17 +7,35 @@ After you sign up on Swetrix and create a new project, the only thing left is to## Installation-1. Log in to your Wordpress account.-2. Install a plugin for adding the code to your HTML, for instance the [Insert Headers and Footers plugin](https://wordpress.org/plugins/insert-headers-and-footers).-3. Open up your project, go to the `Project Settings > Custom Code` section.+<Steps>+<Step>+### Log in to Wordpress-4. To the `Scripts in Header` section you need to add the following:+Log in to your Wordpress account.+</Step>+<Step>+### Install a code injection plugin++Install a plugin for adding the code to your HTML, for instance the [Insert Headers and Footers plugin](https://wordpress.org/plugins/insert-headers-and-footers).+</Step>+<Step>+### Open the Custom Code section++Open up your project, go to the `Project Settings > Custom Code` section.+</Step>+<Step>+### Add the script to the header++To the `Scripts in Header` section you need to add the following:```html<script src="https://swetrix.org/swetrix.js" defer></script>```+</Step>+<Step>+### Add the initialisation to the footer-5. In the `Scripts in Footer` section you need to add the following:+In the `Scripts in Footer` section you need to add the following:```html<script>@@ -35,6 +53,8 @@ After you sign up on Swetrix and create a new project, the only thing left is to/></noscript>```+</Step>+</Steps><Callout type="warn">diff --git a/docs/content/docs/selfhosting/how-to.mdx b/docs/content/docs/selfhosting/how-to.mdxindex b8bac74d5..d98bee00d 100644--- a/docs/content/docs/selfhosting/how-to.mdx+++ b/docs/content/docs/selfhosting/how-to.mdx@@ -24,36 +24,49 @@ We've tested self-hosting Swetrix using [Hetzner Cloud](https://hetzner.cloud),## Installation-### 1. Install the self-hosting repository+<Steps>+<Step>+### Clone the self-hosting repository-To self-host Swetrix, download the [self-hosting repository](https://github.com/swetrix/selfhosting) from GitHub.+Download the [self-hosting repository](https://github.com/swetrix/selfhosting) from GitHub.```bashgit clone https://github.com/swetrix/selfhostingcd selfhosting```-That repository contains a `compose.yaml` file with all the necessary configuration to run Swetrix, you'll need to configure it later.--The repository also contains various configuration files to ease the setup process (for example, `nginx` or `clickhouse` config files).--### 2. Configure the environment variables--That repository contains a `configure.sh` script that will help you set up the environment variables. It will help you configure and autogenerate some necessary variables.+The repository contains a `compose.yaml` file with all the necessary configuration to run Swetrix.++<Files>+ <Folder name="selfhosting" defaultOpen>+ <File name="compose.yaml" />+ <File name="configure.sh" />+ <Folder name="nginx">+ <File name="config" />+ </Folder>+ <Folder name="clickhouse">+ <File name="config.xml" />+ </Folder>+ </Folder>+</Files>+</Step>+<Step>+### Configure the environment variables++Run the `configure.sh` script to set up the environment variables. It will help you configure and autogenerate some necessary variables.This script will also check if you have Docker and Docker Compose installed, and if you don't, it will try to install them for you.-The script will save the environment variables to a `.env` file in the repository directory. You can later change them manually if needed.-```bash./configure.sh```-You can always manually edit these `.env` variables later. Please refer to the [configuration section](/selfhosting/configuring) for more information.--### 3. Run the container+The script will save the environment variables to a `.env` file in the repository directory. You can later change them manually if needed. Please refer to the [configuration section](/selfhosting/configuring) for more information.+</Step>+<Step>+### Run the containers-Once all the environment variables are set, you can start the containers by running the following command:+Once all the environment variables are set, start the containers:```bashdocker compose up -d@@ -67,6 +80,8 @@ After you run this command, the following containers will be started:- Clickhouse server for analytics and transactional dataAfter starting the container you can access the dashboard at `http://{host}:80` (or your configured reverse-proxy domain).+</Step>+</Steps>## Updating@@ -80,17 +95,21 @@ The default routing is:- Frontend: /- API: /backend/ (proxied to swetrix-api)-### Nginx proxy (default)+<Tabs items={["Nginx (default)", "Traefik"]}>+<Tab value="Nginx (default)">The self-hosting repository includes an nginx-proxy service and an nginx/config file. The nginx-proxy container listens on port 80 and forwards:- `/` β `swetrix-fe` (frontend, port 3000)- `/backend/` β `swetrix-api` (API, port 5005)+If you use another reverse proxy in front of Swetrix (for example for TLS termination), keep exposing only the nginx-proxy service and forward traffic to it.-### Traefik (alternative to nginx-proxy)+</Tab>+<Tab value="Traefik">If you are already using Traefik, you can omit the nginx-proxy service and route requests directly to the Swetrix containers by path.+swetrix-fe labels:```yaml- traefik.enable=true@@ -99,7 +118,7 @@ swetrix-fe labels:- traefik.http.routers.swetrix_fe.tls=true- traefik.http.routers.swetrix_fe.priority=1- traefik.http.services.swetrix_fe.loadbalancer.server.port=3000- ```+```swetrix-api labels:```yaml@@ -111,7 +130,10 @@ swetrix-api labels:- traefik.http.middlewares.swetrix_be_strip.stripprefix.prefixes=/backend- traefik.http.routers.swetrix_be.middlewares=swetrix_be_strip- traefik.http.services.swetrix_be.loadbalancer.server.port=5005- ```+```++</Tab>+</Tabs>## Client IP headersdiff --git a/docs/content/docs/sitesettings/embed-your-analytics-dashboard-into-your-website.mdx b/docs/content/docs/sitesettings/embed-your-analytics-dashboard-into-your-website.mdxindex 57275161e..5a6541530 100644--- a/docs/content/docs/sitesettings/embed-your-analytics-dashboard-into-your-website.mdx+++ b/docs/content/docs/sitesettings/embed-your-analytics-dashboard-into-your-website.mdx@@ -6,11 +6,14 @@ slug: /how-to-embedYou can embed your Swetrix analytics dashboard into any other website using an iframe. This is useful if you're building a custom admin panel, a dashboard for your customers or just want to show your stats to your visitors.-### 1. Get your sharable link+<Steps>+<Step>+### Get your sharable linkFirst, you need to find the sharable link to your dashboard. You can get it in your [site settings](/how-to-access-site-settings) page. For people to be able to access your dashboard, you need to make it public or password-protected.--### 2. Write the HTML embed code+</Step>+<Step>+### Write the HTML embed codeNow you need to write the HTML code for the iframe. You can do this in any text editor, or directly in your website's code. Here's an example of how it should look like:@@ -22,10 +25,13 @@ Now you need to write the HTML code for the iframe. You can do this in any texttitle="Test"></iframe>```--### 3. Paste the code into your website+</Step>+<Step>+### Paste the code into your websiteNow you can paste the code into your website's HTML. You can put it anywhere you want, but it's usually best to put it in a dedicated page or section.+</Step>+</Steps>### Embed options and customisationdiff --git a/docs/content/docs/sitesettings/how-to-access-site-settings.mdx b/docs/content/docs/sitesettings/how-to-access-site-settings.mdxindex c46e9f627..5bc45298c 100644--- a/docs/content/docs/sitesettings/how-to-access-site-settings.mdx+++ b/docs/content/docs/sitesettings/how-to-access-site-settings.mdx@@ -6,14 +6,19 @@ slug: /how-to-access-site-settingsYou can access your site settings in two ways:-### From the dashboard+<Tabs items={["From the dashboard", "From the analytics page"]}>+<Tab value="From the dashboard">Click on the 'Settings' icon in the top right corner of site on the dashboard page.<img alt="Settings from the Dashboard page" src="/docs/img/sitesettings/settings_from_dashboard.png" />-### From your site's analytics page+</Tab>+<Tab value="From the analytics page">Click on the 'Settings' tab in the top navigation bar of your site's analytics page.<img alt="Settings from the sites analytics page" src="/docs/img/sitesettings/settings_from_project.png" />++</Tab>+</Tabs>diff --git a/docs/content/docs/troubleshooting.mdx b/docs/content/docs/troubleshooting.mdxindex 17caa6eb3..2e8b35560 100644--- a/docs/content/docs/troubleshooting.mdx+++ b/docs/content/docs/troubleshooting.mdx@@ -15,24 +15,59 @@ The first thing you should do is to check if the script is installed correctly.You should also check the "Network" tab to see if the script is loaded correctly and if it sends any requests to the Swetrix servers.-1. Open the website you installed Swetrix script on.-2. Open the developer tools in your browser, you can do this by pressing `F12` for Chrome and Firefox, or `Ctrl + Shift + C` for Safari (alternatively, right-click anywhere on the page and press the "Inspect" button).-3. Click on the "Network" tab in the developer tools (it will be empty at first, so you need to reload the page).-4. Search for `swetrix` related requests in the list of requests. You should see a bunch of POST requests to `api.swetrix.com`, and the status of these requests should be `201`.+<Steps>+<Step>+### Open your website++Open the website you installed Swetrix script on.+</Step>+<Step>+### Open DevTools++Open the developer tools in your browser, you can do this by pressing `F12` for Chrome and Firefox, or `Ctrl + Shift + C` for Safari (alternatively, right-click anywhere on the page and press the "Inspect" button).+</Step>+<Step>+### Check the Network tab++Click on the "Network" tab in the developer tools (it will be empty at first, so you need to reload the page).+</Step>+<Step>+### Look for Swetrix requests++Search for `swetrix` related requests in the list of requests. You should see a bunch of POST requests to `api.swetrix.com`, and the status of these requests should be `201`.+</Step>+</Steps><img alt="Browser Network tab" src="/docs/img/swetrix-network-tab.png" />## Visits are not appearing in the Dashboard+<Callout type="info">Don't worry if you don't see any visits in the dashboard right away. There may be a small delay (up to 10 seconds) before they appear. That's because we cache the data for a short period of time to reduce the load on our servers, instead of sending it to the database right away.+</Callout>+In case you don't see any visits even after a delay, make sure you don't have an ad-blocker or a similar extension active, as it may interfere with the script. Try visiting your website in a different browser or device to see if the issue persists.## Common issues and how to fix them-- **Make sure that you entered a correct Project ID in the script configuration**. Sometimes mistype their Project IDs in the integration or use the wrong ID (for example, an API key). You can find your Project ID on the Project Settings page in dashboard.-- **Did you set up Content Security Policy (CSP) on your site?**. If you did, make sure to add Swetrix to the list of allowed domains. The simplest way to do this is `Content-Security-Policy: default-src 'self' *.swetrix.com *.swetrix.org`, but we recommend you to read more about CSP and set it up properly.-- **Are you testing your integration on localhost?**. By default, Swetrix doesn't track any events on localhost to prevent developers from polluting their data with test events. If you want to test your integration on localhost, you can enable the `devMode` option in the [script configuration](/swetrix-js-reference#init).-- **Do you use caching on your site?**. Make sure to purge the cache after you install Swetrix script, to ensure you're loading the latest version of your site.-- **Did you set up allowed domains in the Project settings?**. If you did, you might have misspelled your domain name or added a `www.` prefix to it while your site does not use it (or vice versa).-- **You might be using an SPA or a similar framework**. You might have set up the script inproperly. Generally, we recommend using [Swetrix via NPM](/install-script#install-swetrix-via-npm) for such application.+<Accordions>+<Accordion title="Incorrect Project ID">+Make sure that you entered a correct Project ID in the script configuration. Sometimes mistype their Project IDs in the integration or use the wrong ID (for example, an API key). You can find your Project ID on the Project Settings page in dashboard.+</Accordion>+<Accordion title="Content Security Policy (CSP) blocking Swetrix">+If you set up CSP on your site, make sure to add Swetrix to the list of allowed domains. The simplest way to do this is `Content-Security-Policy: default-src 'self' *.swetrix.com *.swetrix.org`, but we recommend you to read more about CSP and set it up properly.+</Accordion>+<Accordion title="Testing on localhost">+By default, Swetrix doesn't track any events on localhost to prevent developers from polluting their data with test events. If you want to test your integration on localhost, you can enable the `devMode` option in the [script configuration](/swetrix-js-reference#init).+</Accordion>+<Accordion title="Site caching issues">+If you use caching on your site, make sure to purge the cache after you install Swetrix script, to ensure you're loading the latest version of your site.+</Accordion>+<Accordion title="Allowed domains misconfigured">+If you set up allowed domains in the Project settings, you might have misspelled your domain name or added a `www.` prefix to it while your site does not use it (or vice versa).+</Accordion>+<Accordion title="Using an SPA or similar framework">+You might have set up the script improperly. Generally, we recommend using [Swetrix via NPM](/install-script#install-swetrix-via-npm) for such application.+</Accordion>+</Accordions>diff --git a/docs/mdx-components.tsx b/docs/mdx-components.tsxindex 8b1ee2145..565a501fe 100644--- a/docs/mdx-components.tsx+++ b/docs/mdx-components.tsx@@ -1,11 +1,24 @@import defaultMdxComponents from 'fumadocs-ui/mdx';import { Callout } from 'fumadocs-ui/components/callout';+import { Step, Steps } from 'fumadocs-ui/components/steps';+import { Tab, Tabs } from 'fumadocs-ui/components/tabs';+import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';+import { File, Folder, Files } from 'fumadocs-ui/components/files';import type { MDXComponents } from 'mdx/types';export function getMDXComponents(components?: MDXComponents): MDXComponents {return {...defaultMdxComponents,Callout,+ Step,+ Steps,+ Tab,+ Tabs,+ Accordion,+ Accordions,+ File,+ Folder,+ Files,...components,};}