Skip to content

πŸ“ˆ 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!

Add Carrd & Joomla integrations; update Docusaurus

Blue Mousebbe730934b10
diff --git a/docs/docs/integrations/carrd.md b/docs/docs/integrations/carrd.md
new file mode 100644
index 000000000..0bc75f2bd
--- /dev/null
+++ b/docs/docs/integrations/carrd.md
@@ -0,0 +1,93 @@
+---
+title: Carrd
+slug: /carrd-integration
+---
+
+Integrate Swetrix with your Carrd site to get privacy-friendly analytics on your one-page website.
+
+## Prerequisites
+
+Adding custom code to a Carrd site requires a **Pro** subscription (Pro Standard, Pro Plus, or Pro Max). If you're on the free plan, you'll need to upgrade before following this guide.
+
+## Installation
+
+### 1. Open your site settings
+
+1. Log in to [Carrd](https://carrd.co) and open the site you want to track in the editor.
+2. Click the **gear icon** (Settings) in the top-right corner of the editor.
+
+### 2. Add the tracking script
+
+1. In the settings panel, scroll down to the **Head** section under "Embed Code".
+2. Paste the following code:
+
+```html
+<script>
+ (function () {
+ var s = document.createElement('script')
+ s.src = 'https://swetrix.org/swetrix.js'
+ s.defer = true
+ s.onload = function () {
+ swetrix.init('YOUR_PROJECT_ID')
+ swetrix.trackViews()
+ }
+ document.head.appendChild(s)
+ })()
+</script>
+
+<noscript>
+ <img
+ src="https://api.swetrix.com/log/noscript?pid=YOUR_PROJECT_ID"
+ alt=""
+ referrerpolicy="no-referrer-when-downgrade"
+ />
+</noscript>
+```
+
+We use the JavaScript approach (dynamically creating the script element) instead of a plain `<script src="...">` tag because Carrd may strip `defer` or other attributes during processing.
+
+### 3. Publish your site
+
+Click **Save**, then **Publish** to apply the changes to your live site.
+
+:::caution
+Don't forget to replace `YOUR_PROJECT_ID` with your actual Project ID from the Swetrix dashboard, otherwise tracking won't work.
+:::
+
+## Check your installation
+
+Open your published Carrd site in a new tab (or an incognito window). Within a minute you should see a pageview appear in your Swetrix dashboard.
+
+:::tip
+The tracking script only runs on your published site. You won't see analytics data while previewing inside the Carrd editor.
+:::
+
+## Multiple pages
+
+If your Carrd site uses multiple pages (available on Pro Plus and Pro Max plans), the tracking script in the head code loads on every page automatically β€” no extra configuration needed.
+
+## Optional: track custom events
+
+You can use `swetrix.track()` to capture custom interactions such as button clicks or form submissions. Add the following in the same **Head** embed code section, after the main tracking snippet:
+
+```html
+<script>
+ document.addEventListener('DOMContentLoaded', function () {
+ var form = document.querySelector('form')
+ if (!form || typeof swetrix === 'undefined') return
+
+ form.addEventListener('submit', function () {
+ swetrix.track({ ev: 'form_submission' })
+ })
+ })
+</script>
+```
+
+Refer to the [tracking script reference](/swetrix-js-reference) for the full list of options and functions available.
+
+## Troubleshooting
+
+- **Script not loading.** Verify you have a Carrd Pro subscription β€” custom code is not available on the free plan.
+- **No data in dashboard.** Make sure you published the site after adding the embed code. Changes in the editor are not live until you publish.
+- **Check the source.** Open your published site, right-click and select "View Page Source", then search for `swetrix` to confirm the script is present.
+- **Console errors.** Open your browser's developer tools (F12) and check the Console tab for JavaScript errors. Look for network requests to `api.swetrix.com` to verify data is being sent.
diff --git a/docs/docs/integrations/docusaurus.md b/docs/docs/integrations/docusaurus.md
index 0e54d3f83..bb3535675 100644
--- a/docs/docs/integrations/docusaurus.md
+++ b/docs/docs/integrations/docusaurus.md
@@ -3,25 +3,35 @@ title: Docusaurus
slug: /docusaurus-integration
---
-After you sign up on Swetrix and create a new project, the only thing left is to add it to your website.
+Integrate Swetrix with your [Docusaurus](https://docusaurus.io/) site to track page views, monitor errors, and capture custom events β€” all while staying privacy-friendly and GDPR-compliant.
## Installation
-1. Open your Docusaurus project.
-2. Edit the `docusaurus.config.js` file and add the following inside `module.exports`:
+The simplest way to add Swetrix to a Docusaurus site is by loading the tracking script through `docusaurus.config.js` and initialising it with a small setup file.
+
+### 1. Add the scripts to your config
+
+Open `docusaurus.config.js` and add the Swetrix script and your setup file to the `scripts` array:
```js
-module.export = {
- ...
+const config = {
+ // ...your existing config
scripts: [
- { src: 'https://swetrix.org/swetrix.js', defer: true },
- { src: 'js/setupswetrix.js', defer: true }
+ {
+ src: 'https://swetrix.org/swetrix.js',
+ defer: true,
+ },
+ {
+ src: '/js/setupswetrix.js',
+ defer: true,
+ },
],
- ...
}
```
-3. Create a new file at `static/js/setupswetrix.js` and add the following:
+### 2. Create the setup file
+
+Create a new file at `static/js/setupswetrix.js`:
```js
document.addEventListener('DOMContentLoaded', function () {
@@ -30,12 +40,239 @@ document.addEventListener('DOMContentLoaded', function () {
})
```
+That's it β€” Swetrix will now automatically track page views across your entire site, including client-side navigations.
+
:::caution
-It's very important not to forget to replace `YOUR_PROJECT_ID` with your actual Project ID you can find in the Dashboard, otherwise tracking won't work!
+Replace `YOUR_PROJECT_ID` with your actual Project ID from the [Swetrix dashboard](https://swetrix.com/projects), otherwise tracking won't work.
:::
+### Noscript fallback (optional)
+
+To track visitors who have JavaScript disabled, you can add a noscript image pixel. Create or edit `src/theme/Root.js` to wrap your site with the fallback:
+
+```jsx
+import React from 'react'
+
+export default function Root({ children }) {
+ return (
+ <>
+ {children}
+ <noscript>
+ <img
+ src="https://api.swetrix.com/log/noscript?pid=YOUR_PROJECT_ID"
+ alt=""
+ referrerPolicy="no-referrer-when-downgrade"
+ />
+ </noscript>
+ </>
+ )
+}
+```
+
## Check your installation
-After installing Swetrix tracking script, go to your website and visit some pages.
+After adding the tracking script, start your Docusaurus site and visit a few pages. Within a minute you should see new pageviews appearing in your Swetrix dashboard.
+
+:::tip
+During development, pageviews from `localhost` are not sent by default. Set `devMode: true` in the setup file if you want to verify tracking locally:
+
+```js
+swetrix.init('YOUR_PROJECT_ID', {
+ devMode: true,
+})
+```
+
+Remember to remove this before deploying to production.
+:::
+
+## Error tracking
+
+You can enable automatic client-side error monitoring by adding `trackErrors()` to your setup file. This captures unhandled JavaScript errors and reports them to Swetrix.
+
+Update `static/js/setupswetrix.js`:
+
+```js
+document.addEventListener('DOMContentLoaded', function () {
+ swetrix.init('YOUR_PROJECT_ID')
+ swetrix.trackViews()
+ swetrix.trackErrors()
+})
+```
+
+Errors will appear in the **Errors** tab of your project dashboard. See the [tracking script reference](/swetrix-js-reference#trackerrors) for configuration options like `sampleRate` and `callback`.
+
+## Tracking custom events
+
+Custom events let you track specific user interactions beyond page views β€” button clicks, form submissions, feature usage, and more. In Docusaurus, you can call `swetrix.track()` directly from any React component.
+
+Since the Swetrix script is loaded globally, the `swetrix` object is available on `window`. Here's a helper pattern you can use in your components:
+
+```js
+const trackEvent = (eventName, metadata = {}) => {
+ try {
+ window?.swetrix?.track({
+ ev: eventName,
+ meta: metadata,
+ })
+ } catch (error) {
+ console.error('Swetrix tracking error:', error)
+ }
+}
+```
+
+### Example: tracking button clicks
+
+A simple example β€” track when users click a CTA button:
+
+```jsx
+import React from 'react'
+
+export default function SignUpButton() {
+ const handleClick = () => {
+ window?.swetrix?.track({
+ ev: 'CTA_CLICK',
+ meta: {
+ label: 'Sign up',
+ location: 'hero',
+ },
+ })
+ }
+
+ return (
+ <a href="https://swetrix.com/signup" onClick={handleClick}>
+ Get started free
+ </a>
+ )
+}
+```
+
+### Example: docs feedback widget
+
+A more practical example β€” track whether users found a docs page helpful. This is similar to what we use on the Swetrix docs site itself:
+
+```jsx
+import React, { useState } from 'react'
+import { useLocation } from '@docusaurus/router'
+
+export default function DocsFeedback() {
+ const { pathname } = useLocation()
+ const [submitted, setSubmitted] = useState(false)
+
+ const sendFeedback = async (answer) => {
+ try {
+ await window?.swetrix?.track({
+ ev: 'DOCS_FEEDBACK',
+ meta: {
+ answer,
+ path: pathname,
+ },
+ })
+ } catch (error) {
+ console.error('Error tracking feedback:', error)
+ }
+
+ setSubmitted(true)
+ }
+
+ if (submitted) {
+ return <p>Thank you for your feedback!</p>
+ }
+
+ return (
+ <div>
+ <p>Was this page helpful?</p>
+ <button onClick={() => sendFeedback('Yes')}>Yes</button>
+ <button onClick={() => sendFeedback('No')}>No</button>
+ </div>
+ )
+}
+```
+
+This sends a `DOCS_FEEDBACK` event to Swetrix with the user's answer and the current page path as metadata. You can then view conversion rates and filter by metadata values in the **Custom events** section of your dashboard.
+
+### Example: tracking search usage
+
+If you use Docusaurus's built-in search (e.g. Algolia DocSearch), you can track when users open the search modal:
+
+```jsx
+import React, { useEffect } from 'react'
+
+export default function Root({ children }) {
+ useEffect(() => {
+ const handleKeyDown = (event) => {
+ if ((event.metaKey || event.ctrlKey) && event.key === 'k') {
+ window?.swetrix?.track({
+ ev: 'SEARCH_OPENED',
+ meta: { trigger: 'keyboard' },
+ })
+ }
+ }
+
+ const searchButton = document.querySelector('.DocSearch-Button')
+ const handleClick = () => {
+ window?.swetrix?.track({
+ ev: 'SEARCH_OPENED',
+ meta: { trigger: 'click' },
+ })
+ }
+
+ document.addEventListener('keydown', handleKeyDown)
+ searchButton?.addEventListener('click', handleClick)
+
+ return () => {
+ document.removeEventListener('keydown', handleKeyDown)
+ searchButton?.removeEventListener('click', handleClick)
+ }
+ }, [])
+
+ return <>{children}</>
+}
+```
+
+### Example: tracking outbound link clicks
+
+Track when users click external links in your docs, useful for measuring referral traffic to third-party resources:
+
+```jsx
+import React from 'react'
+
+export default function TrackedLink({ href, children, eventName = 'OUTBOUND_CLICK' }) {
+ const handleClick = () => {
+ window?.swetrix?.track({
+ ev: eventName,
+ meta: {
+ url: href,
+ },
+ })
+ }
+
+ return (
+ <a href={href} target="_blank" rel="noopener noreferrer" onClick={handleClick}>
+ {children}
+ </a>
+ )
+}
+```
+
+Usage in MDX:
+
+```mdx
+import TrackedLink from '@site/src/components/TrackedLink'
+
+Check out the <TrackedLink href="https://github.com/Swetrix/swetrix">source code</TrackedLink>.
+```
+
+## Event naming conventions
+
+When defining custom event names, keep in mind:
+
+- Names must contain only English letters (a-Z), numbers (0-9), underscores (`_`), and dots (`.`).
+- Names must be fewer than 64 characters.
+- Names must start with an English letter.
+
+We recommend using `UPPER_SNAKE_CASE` for consistency (e.g. `DOCS_FEEDBACK`, `CTA_CLICK`, `SEARCH_OPENED`).
+
+## Further reading
-Within a minute you should be able to see new pageviews being added to your project's dahsboard.
+- [Tracking script reference](/swetrix-js-reference) β€” full API documentation for `init()`, `track()`, `trackViews()`, `trackErrors()`, and more.
+- [Swetrix npm package](https://www.npmjs.com/package/swetrix) β€” if you prefer importing Swetrix as an ES module instead of loading it via a script tag.
diff --git a/docs/docs/integrations/joomla.md b/docs/docs/integrations/joomla.md
new file mode 100644
index 000000000..8dd586a50
--- /dev/null
+++ b/docs/docs/integrations/joomla.md
@@ -0,0 +1,146 @@
+---
+title: Joomla
+slug: /joomla-integration
+---
+
+Integrate Swetrix with your Joomla site to get privacy-friendly, GDPR-compliant analytics without any third-party plugins.
+
+## Installation
+
+There are two ways to add Swetrix to Joomla: using a **Custom HTML module** (no file editing required) or by editing your **template's index.php** directly.
+
+### Method 1: Custom HTML module
+
+This is the simplest approach and works with any Joomla template.
+
+#### 1. Create the module
+
+1. Log in to your Joomla Administrator panel.
+2. Navigate to **Content > Site Modules** (Joomla 4/5) or **Extensions > Modules** (Joomla 3).
+3. Click **New** and choose **Custom**.
+
+#### 2. Configure the module
+
+Set the following fields:
+
+- **Title:** Swetrix Analytics (or any name you prefer)
+- **Show Title:** No
+- **Position:** Choose a position that loads on every page. Many templates provide a `debug` or `head` position β€” either works fine.
+
+Switch to the **Editor** tab. If the WYSIWYG editor is active, switch it to source / code view, then paste:
+
+```html
+<script src="https://swetrix.org/swetrix.js" defer></script>
+<script>
+ document.addEventListener('DOMContentLoaded', function () {
+ swetrix.init('YOUR_PROJECT_ID')
+ swetrix.trackViews()
+ })
+</script>
+
+<noscript>
+ <img
+ src="https://api.swetrix.com/log/noscript?pid=YOUR_PROJECT_ID"
+ alt=""
+ referrerpolicy="no-referrer-when-downgrade"
+ />
+</noscript>
+```
+
+:::caution
+Don't forget to replace `YOUR_PROJECT_ID` with your actual Project ID from the Swetrix dashboard, otherwise tracking won't work.
+:::
+
+#### 3. Publish the module
+
+1. Set **Status** to **Published**.
+2. Under the **Menu Assignment** tab, select **On all pages**.
+3. Click **Save & Close**.
+
+### Method 2: Edit the template directly
+
+If you prefer to embed the tracking code at the template level, you can add it to your active template's main layout file.
+
+#### 1. Open your template file
+
+1. In your Joomla Administrator panel, go to **System > Site Templates** (Joomla 4/5) or **Extensions > Templates** (Joomla 3).
+2. Click on your active template to open the template editor.
+3. Open the file `index.php` (or `component.php` depending on your template structure).
+
+#### 2. Add the tracking snippet
+
+Paste the following just before the closing `</body>` tag:
+
+```html
+<script src="https://swetrix.org/swetrix.js" defer></script>
+<script>
+ document.addEventListener('DOMContentLoaded', function () {
+ swetrix.init('YOUR_PROJECT_ID')
+ swetrix.trackViews()
+ })
+</script>
+
+<noscript>
+ <img
+ src="https://api.swetrix.com/log/noscript?pid=YOUR_PROJECT_ID"
+ alt=""
+ referrerpolicy="no-referrer-when-downgrade"
+ />
+</noscript>
+```
+
+:::caution
+Replace `YOUR_PROJECT_ID` with your actual Project ID from the Swetrix dashboard.
+:::
+
+3. Click **Save**.
+
+:::note
+Template updates may overwrite your changes. If you update your template, verify the Swetrix snippet is still present. Making a copy of the template before updating is a good precaution.
+:::
+
+## Tracking custom events
+
+Once basic page tracking is working, you can use `swetrix.track()` to record custom interactions β€” form submissions, button clicks, downloads, and more. Refer to the [tracking script reference](/swetrix-js-reference) for the full API.
+
+Example β€” tracking a contact form submission:
+
+```html
+<script>
+ document.addEventListener('DOMContentLoaded', function () {
+ var form = document.querySelector('#contact-form')
+ if (!form || typeof swetrix === 'undefined') return
+
+ form.addEventListener('submit', function () {
+ swetrix.track({ ev: 'contact_form_submitted' })
+ })
+ })
+</script>
+```
+
+## Troubleshooting
+
+### The editor strips the script tags
+
+Joomla's default editor (TinyMCE) may remove `<script>` tags when saving. To prevent this:
+
+- **Easiest fix:** Switch to code / source view before pasting the snippet. In Joomla 4/5, click the **Toggle editor** button below the editor area.
+- **Alternative:** Go to **System > Plugins** (or **Extensions > Plugins**), find **Editor - TinyMCE**, and under the **Extended Valid Elements** field add `script[src|defer|data-site-id]`. Save the plugin.
+- **Last resort:** Temporarily switch the editor to **Editor - None** under **System > Global Configuration > Default Editor**, paste the snippet, then switch back.
+
+### Script not appearing on the site
+
+- Confirm the module is published and assigned to all pages.
+- Clear Joomla's cache: **System > Clear Cache**.
+- Check that the module position you selected actually exists in your active template.
+
+### Caching issues
+
+If you're using Joomla's built-in cache or a third-party caching extension:
+
+- Clear all caches after adding the snippet.
+- The Swetrix script loads client-side, so it works fine with page caching once the HTML has been served with the snippet included.
+
+## Check your installation
+
+Visit your live Joomla site and navigate through a few pages. Within a minute you should see new pageviews appearing in your Swetrix dashboard.
diff --git a/docs/sidebars.js b/docs/sidebars.js
index 4c24ad1fb..68b17357d 100644
--- a/docs/sidebars.js
+++ b/docs/sidebars.js
@@ -24,6 +24,7 @@ module.exports = {
'integrations/sveltekit',
'integrations/hugo',
'integrations/squarespace',
+ 'integrations/joomla',
],
},
'troubleshooting',