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 GitBook, Laravel Blade and PrestaShop integrations

Blue Mousee7ddfa648e49
diff --git a/docs/docs/integrations/gitbook.md b/docs/docs/integrations/gitbook.md
new file mode 100644
index 000000000..1c6788b0e
--- /dev/null
+++ b/docs/docs/integrations/gitbook.md
@@ -0,0 +1,114 @@
+---
+title: GitBook
+slug: /gitbook-integration
+---
+
+Integrate Swetrix with your [GitBook](https://www.gitbook.com/) documentation site to understand how visitors navigate your docs, which pages get the most attention, and where readers drop off β€” all with full privacy and GDPR compliance.
+
+## Prerequisites
+
+GitBook's custom script injection requires:
+
+- A **Pro**, **Team**, or **Enterprise** plan. Custom scripts are not available on the free Community plan.
+- A **custom domain** configured for your GitBook space. Scripts only execute on custom domains, not on default `*.gitbook.io` URLs.
+
+## Installation
+
+### 1. Open your space settings
+
+1. Navigate to the GitBook space you want to track.
+2. Click the **Settings** icon (gear) in the top-right corner.
+3. Select **Integrations** from the sidebar.
+
+### 2. Add the tracking script
+
+1. Scroll down to the **Custom scripts** section.
+2. In the **Head** field, paste the following:
+
+```html
+<script src="https://swetrix.org/swetrix.js" defer></script>
+<script>
+ document.addEventListener('DOMContentLoaded', function () {
+ swetrix.init('YOUR_PROJECT_ID')
+ swetrix.trackViews()
+ })
+</script>
+```
+
+### 3. Save
+
+Click **Save** to apply the script to your documentation site.
+
+:::caution
+Don't forget to 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)
+
+If the Head section supports multiple code blocks, you can also add a noscript pixel to track visitors who have JavaScript disabled:
+
+```html
+<noscript>
+ <img
+ src="https://api.swetrix.com/log/noscript?pid=YOUR_PROJECT_ID"
+ alt=""
+ referrerpolicy="no-referrer-when-downgrade"
+ />
+</noscript>
+```
+
+## Check your installation
+
+Open your documentation site through your custom domain in a new browser tab or incognito window. Browse through a few pages. Within a minute you should see new pageviews appearing in your Swetrix dashboard.
+
+:::tip
+Make sure you're accessing the site via your custom domain, not the default `*.gitbook.io` URL. Custom scripts only load on custom domains.
+:::
+
+## Page navigation tracking
+
+GitBook uses client-side navigation when readers move between pages. Swetrix's `trackViews()` handles this automatically via the History API, so every page transition is captured without any extra configuration.
+
+## Error tracking
+
+You can enable automatic client-side error monitoring by adding `trackErrors()` alongside the other initialisation calls. This captures unhandled JavaScript errors and reports them to Swetrix.
+
+Update the script in your Head section:
+
+```html
+<script src="https://swetrix.org/swetrix.js" defer></script>
+<script>
+ document.addEventListener('DOMContentLoaded', function () {
+ swetrix.init('YOUR_PROJECT_ID')
+ swetrix.trackViews()
+ swetrix.trackErrors()
+ })
+</script>
+```
+
+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`.
+
+## Troubleshooting
+
+### Script not loading
+
+- **Check your plan.** Custom scripts require a Pro plan or higher. Verify your GitBook subscription.
+- **Verify your custom domain.** Scripts only execute on custom domains. If you're viewing your docs at `yourspace.gitbook.io`, the script won't run.
+- **Inspect the source.** Open your published site on your custom domain, right-click and select "View Page Source", then search for `swetrix` to confirm the script is present.
+
+### No data in dashboard
+
+- **Confirm the Project ID.** Double-check that `YOUR_PROJECT_ID` is replaced with your actual project ID from the Swetrix dashboard.
+- **Check the console.** Open your browser's developer tools (F12) and look at the Console tab for JavaScript errors. Check the Network tab for requests to `api.swetrix.com` to verify data is being sent.
+
+### Changes not appearing
+
+GitBook may cache pages aggressively. Try:
+
+- Hard-refreshing the page (Ctrl+Shift+R or Cmd+Shift+R).
+- Opening the site in an incognito or private window.
+- Waiting a few minutes for the cache to update.
+
+## Further reading
+
+- [Tracking script reference](/swetrix-js-reference) β€” full API documentation for `init()`, `track()`, `trackViews()`, `trackErrors()`, and more.
diff --git a/docs/docs/integrations/laravel.md b/docs/docs/integrations/laravel.md
new file mode 100644
index 000000000..4c13a974b
--- /dev/null
+++ b/docs/docs/integrations/laravel.md
@@ -0,0 +1,256 @@
+---
+title: Laravel
+slug: /laravel-integration
+---
+
+Integrate Swetrix with your [Laravel](https://laravel.com/) application using Blade templates to track page views, monitor errors, and capture custom events β€” all while staying privacy-friendly and GDPR-compliant.
+
+## Installation
+
+The recommended approach is to add the Swetrix tracking script to your main Blade layout and use Laravel's environment configuration to manage your Project ID.
+
+### 1. Find your layout file
+
+Laravel applications typically use a shared layout that all pages extend. Depending on your setup, this is usually one of:
+
+- `resources/views/layouts/app.blade.php` (common default)
+- `resources/views/components/layout.blade.php` (if using [Blade components](https://laravel.com/docs/blade#components))
+
+If you're using **Laravel Breeze** or **Jetstream**, the main layout lives at `resources/views/layouts/app.blade.php` or `resources/views/layouts/guest.blade.php`.
+
+### 2. Add the tracking script
+
+Open your layout file and add the Swetrix script just before the closing `</head>` tag, and the initialisation snippet just before the closing `</body>` tag:
+
+```html
+<!DOCTYPE html>
+<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>{{ config('app.name', 'Laravel') }}</title>
+
+ @vite(['resources/css/app.css', 'resources/js/app.js'])
+
+ {{-- Swetrix Analytics --}}
+ <script src="https://swetrix.org/swetrix.js" defer></script>
+</head>
+<body>
+ @yield('content')
+
+ {{-- Swetrix Analytics --}}
+ <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>
+</body>
+</html>
+```
+
+:::caution
+Replace `YOUR_PROJECT_ID` with your actual Project ID from the [Swetrix dashboard](https://swetrix.com/projects), otherwise tracking won't work.
+:::
+
+### 3. Disable tracking in development (recommended)
+
+To avoid polluting your analytics with local page views, wrap the snippet in an environment check so it only loads in production:
+
+```html
+@production
+ <script src="https://swetrix.org/swetrix.js" defer></script>
+@endproduction
+```
+
+And for the body initialisation:
+
+```html
+@production
+ <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>
+@endproduction
+```
+
+The `@production` Blade directive ensures the script is only included when `APP_ENV=production`.
+
+:::tip
+During development, Swetrix ignores `localhost` traffic by default. If you want to verify tracking locally without changing your environment, you can temporarily set `devMode: true`:
+
+```js
+swetrix.init('YOUR_PROJECT_ID', { devMode: true })
+```
+
+Remember to remove this before deploying.
+:::
+
+## Store your Project ID in config (optional)
+
+Rather than hardcoding the Project ID in your Blade template, you can manage it through Laravel's configuration system. This is especially useful if you manage multiple environments or want to keep configuration in one place.
+
+**1. Add to your `.env` file:**
+
+```
+SWETRIX_PROJECT_ID=YOUR_PROJECT_ID
+```
+
+**2. Register it in `config/services.php`:**
+
+```php
+return [
+ // ...other services
+
+ 'swetrix' => [
+ 'project_id' => env('SWETRIX_PROJECT_ID'),
+ ],
+];
+```
+
+**3. Reference it in your Blade template:**
+
+```html
+@production
+ <script src="https://swetrix.org/swetrix.js" defer></script>
+ <script>
+ document.addEventListener('DOMContentLoaded', function () {
+ swetrix.init('{{ config('services.swetrix.project_id') }}')
+ swetrix.trackViews()
+ })
+ </script>
+
+ <noscript>
+ <img
+ src="https://api.swetrix.com/log/noscript?pid={{ config('services.swetrix.project_id') }}"
+ alt=""
+ referrerpolicy="no-referrer-when-downgrade"
+ />
+ </noscript>
+@endproduction
+```
+
+If you've previously cached your config, run `php artisan config:clear` to pick up the new values.
+
+## Check your installation
+
+Deploy your application (or temporarily set `APP_ENV=production`) and visit a few pages. Within a minute you should see new pageviews appearing in your Swetrix dashboard.
+
+## Error tracking
+
+Enable automatic client-side error monitoring by adding `trackErrors()` to the initialisation snippet. This captures unhandled JavaScript errors and reports them to Swetrix.
+
+```html
+<script>
+ document.addEventListener('DOMContentLoaded', function () {
+ swetrix.init('{{ config('services.swetrix.project_id') }}')
+ swetrix.trackViews()
+ swetrix.trackErrors()
+ })
+</script>
+```
+
+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 events
+
+Custom events let you track specific user interactions β€” form submissions, button clicks, feature usage, and more. Since the Swetrix script is loaded globally, you can call `swetrix.track()` from any inline script or JavaScript file.
+
+### Example: tracking form submissions
+
+Track when users submit a contact form:
+
+```html
+<form id="contact-form" method="POST" action="/contact">
+ @csrf
+ {{-- form fields --}}
+ <button type="submit">Send message</button>
+</form>
+
+<script>
+ document.getElementById('contact-form')?.addEventListener('submit', function () {
+ if (typeof swetrix !== 'undefined') {
+ swetrix.track({
+ ev: 'CONTACT_FORM_SUBMITTED',
+ meta: {
+ page: window.location.pathname,
+ },
+ })
+ }
+ })
+</script>
+```
+
+### Example: tracking outbound links
+
+Track clicks on external links across your site. You can add this to your main layout file:
+
+```html
+<script>
+ document.addEventListener('DOMContentLoaded', function () {
+ document.querySelectorAll('a[href^="http"]').forEach(function (link) {
+ if (link.hostname !== window.location.hostname) {
+ link.addEventListener('click', function () {
+ if (typeof swetrix !== 'undefined') {
+ swetrix.track({
+ ev: 'OUTBOUND_CLICK',
+ meta: { url: link.href },
+ })
+ }
+ })
+ }
+ })
+ })
+</script>
+```
+
+### Event naming rules
+
+Event names must:
+
+- Contain only English letters (a-Z), numbers (0-9), underscores (`_`), and dots (`.`)
+- Be fewer than 64 characters
+- Start with an English letter
+
+We recommend `UPPER_SNAKE_CASE` for consistency (e.g. `CONTACT_FORM_SUBMITTED`, `OUTBOUND_CLICK`).
+
+## Using Swetrix with Livewire or Inertia
+
+If your Laravel application uses **Livewire** or **Inertia.js**, the Swetrix script loaded in your layout will still work for initial page loads. However, subsequent navigations happen client-side and won't trigger new page view events automatically.
+
+Swetrix's `trackViews()` function listens for History API changes, so Inertia navigations (which use `pushState` under the hood) are tracked automatically in most cases.
+
+For Livewire, if you use `wire:navigate` for SPA-style navigation, Swetrix will similarly pick up the URL changes. If you experience any gaps, you can manually fire a page view after navigation:
+
+```js
+document.addEventListener('livewire:navigated', function () {
+ if (typeof swetrix !== 'undefined') {
+ swetrix.pageview({
+ payload: { pg: window.location.pathname },
+ })
+ }
+})
+```
+
+## Further reading
+
+- [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 for use with Laravel Mix or Vite.
diff --git a/docs/docs/integrations/prestashop.md b/docs/docs/integrations/prestashop.md
new file mode 100644
index 000000000..7e3a2492e
--- /dev/null
+++ b/docs/docs/integrations/prestashop.md
@@ -0,0 +1,203 @@
+---
+title: PrestaShop
+slug: /prestashop-integration
+---
+
+Integrate Swetrix with your PrestaShop store to get privacy-friendly, GDPR-compliant analytics and track e-commerce events like purchases.
+
+## Installation
+
+There are two ways to add Swetrix to PrestaShop: through the **Back Office** using a free module, or by editing your **theme template** directly.
+
+### Method 1: Custom HTML module
+
+This approach doesn't require editing theme files and works across PrestaShop versions.
+
+#### 1. Install a custom code module
+
+PrestaShop doesn't have a built-in "paste HTML into head" feature like some other platforms. Install a free module that lets you inject custom code:
+
+1. Log in to your **PrestaShop Back Office**.
+2. Go to **Modules > Module Manager**.
+3. Search for a module like **Custom code** or **Custom JS & CSS** in the marketplace, or install one manually.
+4. Enable the module and open its configuration.
+
+#### 2. Add the tracking snippet
+
+In the module's configuration, add the following code to the **header** (`<head>`) section:
+
+```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>
+```
+
+3. Save the module configuration.
+
+:::caution
+Don't forget to replace `YOUR_PROJECT_ID` with your actual Project ID from the Swetrix dashboard, otherwise tracking won't work.
+:::
+
+### Method 2: Edit the theme template
+
+If you prefer to add the script directly to your theme files, you can edit the main layout template.
+
+#### 1. Open the layout file
+
+1. Connect to your server via FTP or your hosting file manager.
+2. Navigate to your active theme's template directory:
+ - **PrestaShop 1.7+:** `themes/<your-theme>/templates/_partials/head.tpl`
+ - **PrestaShop 8.x:** Same path β€” `themes/<your-theme>/templates/_partials/head.tpl`
+
+#### 2. Add the tracking snippet
+
+Paste the following just before the closing `</head>` section (or at the end of `head.tpl`):
+
+```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>
+```
+
+3. Save the file.
+
+:::caution
+Replace `YOUR_PROJECT_ID` with your actual Project ID from the Swetrix dashboard.
+:::
+
+:::note
+Always use a **child theme** when editing template files. Changes to the parent theme will be lost when you update PrestaShop or the theme. To create a child theme, copy your theme folder, rename it, and update the `theme.yml` file with the new name and parent reference.
+:::
+
+## Check your installation
+
+After adding the script, visit your store and browse a few pages. Within a minute you should see new pageviews appearing in your Swetrix dashboard.
+
+If you don't see data, open your browser's developer tools (F12), check the **Console** tab for errors, and look in the **Network** tab for requests to `api.swetrix.com`.
+
+## Tracking e-commerce events
+
+Beyond basic page views, you can track purchases and other e-commerce interactions as custom events using `swetrix.track()`. You can view these events and their metadata in the **Custom events** section of your Swetrix dashboard. Refer to the [tracking script reference](/swetrix-js-reference) for full API details.
+
+:::tip
+Always **back up your theme** before editing template files.
+:::
+
+### Track purchases
+
+To track completed orders, add a script to PrestaShop's order confirmation page. Edit the file `themes/<your-theme>/templates/checkout/order-confirmation.tpl` and add the following near the end:
+
+```html
+{literal}
+<script>
+ document.addEventListener('DOMContentLoaded', function () {
+ if (typeof swetrix === 'undefined') return
+{/literal}
+
+{if isset($order)}
+ swetrix.track({
+ ev: 'purchase',
+ meta: {
+ order_id: '{$order.details.reference}',
+ total: '{$order.totals.total.amount}',
+ currency: '{$order.totals.total.value|regex_replace:"/[^A-Z]/":""}',
+ items: '{$order.products|count}'
+ }
+ })
+{/if}
+
+{literal}
+ })
+</script>
+{/literal}
+```
+
+PrestaShop uses the **Smarty** templating engine. The `{$variable}` syntax is processed server-side to inject order data, while `{literal}` blocks prevent Smarty from trying to parse the JavaScript code.
+
+:::note
+The exact Smarty variables may differ depending on your PrestaShop version and theme. Check your theme's existing `order-confirmation.tpl` to see which variables are available.
+:::
+
+### Track add-to-cart actions
+
+To track when a visitor adds a product to their cart, add a script to your product page template (`themes/<your-theme>/templates/catalog/product.tpl`):
+
+```html
+{literal}
+<script>
+ document.addEventListener('DOMContentLoaded', function () {
+ var addToCartBtn = document.querySelector('.add-to-cart')
+ if (!addToCartBtn || typeof swetrix === 'undefined') return
+
+ addToCartBtn.addEventListener('click', function () {
+ var nameEl = document.querySelector('h1[itemprop="name"]')
+ var priceEl = document.querySelector('[itemprop="price"]')
+ var qtyInput = document.querySelector('#quantity_wanted')
+
+ swetrix.track({
+ ev: 'added_to_cart',
+ meta: {
+ name: nameEl ? nameEl.textContent.trim() : '',
+ price: priceEl ? priceEl.getAttribute('content') || priceEl.textContent.trim() : '',
+ quantity: qtyInput ? qtyInput.value : '1'
+ }
+ })
+ })
+ })
+</script>
+{/literal}
+```
+
+:::note
+The `.add-to-cart` selector is standard in PrestaShop's default themes (Classic and similar). If your theme uses a different class or structure, adjust the selector to match your "Add to Cart" button.
+:::
+
+## Troubleshooting
+
+### Script not loading
+
+- **Clear PrestaShop cache:** Go to **Advanced Parameters > Performance** and click **Clear cache**.
+- **Disable JavaScript optimisation:** If you're using CCC (Combine, Compress, Cache) for JavaScript, temporarily disable it under **Advanced Parameters > Performance** to rule out conflicts.
+- **Check the page source:** Right-click on your store, select "View Page Source", and search for `swetrix` to confirm the script is present.
+
+### Theme updates overwriting changes
+
+Always use a child theme when editing template files. Changes to the parent theme are lost when you update. If you're using a module to inject the code, your snippet will persist through theme updates.
+
+### E-commerce events not tracking
+
+- **Smarty variables:** Verify that the Smarty variables (like `{$order.details.reference}`) match your PrestaShop version. Place a test order and check if the values are populated correctly by inspecting the rendered HTML source on the confirmation page.
+- **Console errors:** Open the browser console (F12) and look for JavaScript errors on the order confirmation page.
+- **Test with a real order:** PrestaShop's order confirmation page only renders properly after an actual checkout. Use a test payment method to complete a full purchase flow.
+
+### Module conflicts
+
+Some PrestaShop modules that optimise or defer JavaScript can interfere with the tracking script. If Swetrix isn't loading:
+
+1. Temporarily disable JavaScript optimisation modules.
+2. Check if the issue resolves.
+3. If so, configure the module to exclude `swetrix.org/swetrix.js` from its processing.
diff --git a/docs/sidebars.js b/docs/sidebars.js
index 68b17357d..70f16fa2f 100644
--- a/docs/sidebars.js
+++ b/docs/sidebars.js
@@ -25,6 +25,9 @@ module.exports = {
'integrations/hugo',
'integrations/squarespace',
'integrations/joomla',
+ 'integrations/laravel',
+ 'integrations/gitbook',
+ 'integrations/prestashop',
],
},
'troubleshooting',