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!

Hugo & Squarespace integrations

Blue Mouse8f55c12d9729
diff --git a/docs/docs/integrations/hugo.md b/docs/docs/integrations/hugo.md
new file mode 100644
index 000000000..c5f759eec
--- /dev/null
+++ b/docs/docs/integrations/hugo.md
@@ -0,0 +1,100 @@
+---
+title: Hugo
+slug: /hugo-integration
+---
+
+After you sign up on Swetrix and create a new project, the only thing left is to add it to your website.
+
+## Installation
+
+The recommended approach is to create a Hugo partial template for the Swetrix tracking script and include it in your site's base layout.
+
+### 1. Create a partial template
+
+In your Hugo project, create the file `layouts/partials/swetrix-analytics.html` with the following content:
+
+```html
+{{ if not .Site.IsServer }}
+<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>
+{{ end }}
+```
+
+The `{{ if not .Site.IsServer }}` condition ensures the tracking script is only included in production builds (`hugo`) and not during local development (`hugo server`). This prevents inflating your analytics with local page views.
+
+:::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!
+:::
+
+### 2. Include the partial in your layout
+
+Open your base layout template β€” typically `layouts/_default/baseof.html`. If your theme provides one, you may need to copy it into your project's `layouts/` directory first to override it.
+
+Add the partial just before the closing `</body>` tag:
+
+```html
+ {{ partial "swetrix-analytics.html" . }}
+ </body>
+</html>
+```
+
+## Using Hugo config parameters (optional)
+
+To keep your Project ID out of the template and make it easy to manage across environments, you can use Hugo's site parameters instead.
+
+Update `layouts/partials/swetrix-analytics.html`:
+
+```html
+{{ if and (not .Site.IsServer) .Site.Params.swetrixProjectID }}
+<script src="https://swetrix.org/swetrix.js" defer></script>
+<script>
+ document.addEventListener('DOMContentLoaded', function () {
+ swetrix.init('{{ .Site.Params.swetrixProjectID }}')
+ swetrix.trackViews()
+ })
+</script>
+
+<noscript>
+ <img
+ src="https://api.swetrix.com/log/noscript?pid={{ .Site.Params.swetrixProjectID }}"
+ alt=""
+ referrerpolicy="no-referrer-when-downgrade"
+ />
+</noscript>
+{{ end }}
+```
+
+Then add your Project ID to your Hugo configuration file.
+
+**config.toml:**
+
+```toml
+[params]
+ swetrixProjectID = "YOUR_PROJECT_ID"
+```
+
+**config.yaml:**
+
+```yaml
+params:
+ swetrixProjectID: "YOUR_PROJECT_ID"
+```
+
+## Check your installation
+
+After installing Swetrix tracking script, build your site with `hugo` and deploy it.
+
+Visit your live website and navigate through a few pages. Within a minute you should be able to see new pageviews being added to your project's dashboard.
diff --git a/docs/docs/integrations/squarespace.md b/docs/docs/integrations/squarespace.md
new file mode 100644
index 000000000..dfb22c004
--- /dev/null
+++ b/docs/docs/integrations/squarespace.md
@@ -0,0 +1,90 @@
+---
+title: Squarespace
+slug: /squarespace-integration
+---
+
+Integrate Swetrix with your Squarespace website using the built-in Code Injection feature.
+
+## Prerequisites
+
+Squarespace's Code Injection feature is available on **Business** and **Commerce** plans. If you're on a Personal plan, you'll need to upgrade before following this guide.
+
+## Installation
+
+### 1. Open Code Injection settings
+
+1. Log in to your Squarespace account and open the site you want to track.
+2. From the Home Menu, navigate to **Settings > Advanced > Code Injection**.
+
+### 2. Add the Swetrix script
+
+In the **Header** field, paste the following to load the Swetrix library:
+
+```html
+<script src="https://swetrix.org/swetrix.js" defer></script>
+```
+
+### 3. Add the initialisation snippet
+
+In the **Footer** field, paste the following to initialise tracking:
+
+```html
+<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>
+```
+
+### 4. Save
+
+Click **Save** at the top of the Code Injection panel.
+
+:::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
+
+After saving, open your Squarespace site in a new tab (or an incognito window) and browse a few pages. Within a minute you should see new pageviews appearing in your Swetrix dashboard.
+
+:::tip
+The tracking script only runs on your live published site. You won't see analytics data while previewing pages inside the Squarespace editor.
+:::
+
+## Optional: track custom events
+
+You can use `swetrix.track()` to capture custom interactions β€” button clicks, form submissions, video plays, etc. Add any extra tracking calls in the same **Footer** code block, after `swetrix.trackViews()`.
+
+For example, to track newsletter sign-ups:
+
+```html
+<script>
+ document.addEventListener('DOMContentLoaded', function () {
+ var form = document.querySelector('.newsletter-block form')
+ if (!form || typeof swetrix === 'undefined') return
+
+ form.addEventListener('submit', function () {
+ swetrix.track({ ev: 'newsletter_signup' })
+ })
+ })
+</script>
+```
+
+Refer to the [tracking script reference](/swetrix-js-reference) for the full list of options and functions available.
+
+## Important considerations
+
+- **Plan requirement.** Code Injection is not available on Squarespace Personal plans. You need a Business or Commerce plan.
+- **Template changes.** Switching your Squarespace template does not remove Code Injection snippets β€” they persist across template changes.
+- **Single-page navigation.** Some Squarespace templates use AJAX-style page loading (page transitions without a full reload). Swetrix's `trackViews()` handles this automatically via the History API, so no extra configuration is needed.
+- **Testing.** Use your browser's developer console to confirm the script is loaded and check for JavaScript errors. Look for network requests to `api.swetrix.com` to verify data is being sent.
diff --git a/docs/sidebars.js b/docs/sidebars.js
index 1952499fc..4c24ad1fb 100644
--- a/docs/sidebars.js
+++ b/docs/sidebars.js
@@ -22,6 +22,8 @@ module.exports = {
'integrations/google-tag-manager',
'integrations/google-search-console',
'integrations/sveltekit',
+ 'integrations/hugo',
+ 'integrations/squarespace',
],
},
'troubleshooting',