Add tracking script to your website
To use Swetrix on your website, you need to add a tracking script to your website and there are several ways to do this.
Using a CMS or site builder?
If your website runs on WordPress, Wix, Shopify, Webflow, or another CMS/site builder, use a dedicated integration guide instead of editing HTML manually.
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.
<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>It's important to remember to replace YOUR_PROJECT_ID with your actual Project ID, which you can find in the Dashboard, otherwise tracking will not work!
Done. Now you can start using Swetrix on your website.
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.
Install the package
npm install swetrixImport Swetrix
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 * as Swetrix from "swetrix";Start tracking
After that you can track anything you want. For example, the following code snippet will work just fine:
Swetrix.init("YOUR_PROJECT_ID");
Swetrix.trackViews();Help us improve Swetrix
Was this page helpful to you?