How to setup tracking script
This guides shows you how to add Prisme Analytics tracking script to your website.
Our tracking script is ultra light (< 1kB) and designed to not slow down your website. You can consult its content here.
Prerequisites
- You have a running Prisme Analytics instance.
Step 1: Add script tag
In order to track pageviews and other metrics, you must add Prisme tracking script on all pages.
Regardless of the technology used, all pages must contain the following tag
either in <head>
or <body>
tag.
<script src="https://<your-prisme-instance-hostname>/static/wa.js" defer></script>
Depending on the tools you're using to build your website this can be as simple as editing a single file.
Tracking script can be configured, see options here
Step 2: Add noscript tag (optional)
If you website can works without javascript and you wants to track visitors with javascript disabled, you can add the following snippet:
<noscript>
<img src="https://my-prisme-instance.example.com/api/v1/noscript/events/pageviews" style="position:absolute;top:-100px">
</noscript>
For all /api/v1/noscript/events/*
handlers, Prisme returns a small (35 bytes)
single transparent pixel GIF image.
You can read more about noscript events here.
Step 3: Test
Once you've added the script tag, check that tracking works by visiting a page containing it.
Open your browser, navigate to the page and open developer tools (press right click and then inspect).
Then go to the network tab:
And search for requests to
https://<your-prisme-instance-hostname>/api/v1/events/pageviews
. You should
see a POST
request with a 200 OK
response. On the above screenshot, Prisme
instance hostname is app.prismeanalytics.com
.
If you received a non 200 response, it means an error occurred. In that case, checkout relevant troubleshoot section.
Troubleshoot
400 Bad Request
If you received a 400 Bad Request
, it means that your Prisme instance rejected
the request because it came from an unauthorized
origin.
This can be fixed by adding your website domain to Prisme origins registry.
Other
For any other errors, check Prisme logs using
docker logs <prisme-container-name>
.