Squarespace
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
- Log in to your Squarespace account and open the site you want to track.
- 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:
<script src="https://swetrix.org/swetrix.js" defer></script>
3. Add the initialisation snippet
In the Footer field, paste the following to initialise tracking:
<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.
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.
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:
<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 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.comto verify data is being sent.
Help us improve Swetrix
Was this page helpful to you?
