Instead of assuming that one website = one domain, we should be able to specify a site ID in the javascript snippet. This supports new use cases:
For example, even though the Plausible landing page and blog are on the same domain (plausible.io and plausible.io/blog), I’d like to see the stats for them separately.
It is now possible to configure the domain for which traffic is being recorded in the script tag. This should allow all the use-cases mentioned in the first comment.
This is the first time I’m introducing configuration options in the frontend script so it’s pretty important to get the API right. I’ve long wanted to make the tracking setup a bit nicer and I’m taking this opportunity to work on it. Going forward, you can use the simplified script format as follows:
<script async defer src=“https://plausible.io/js/plausible.js“></script>
This replaces the long, minified code block that was used previously.
Configuring the domain to record traffic for can be done with a simple data-domain
attribute:
<script async defer data-domain=“your-site-domain.com” src=“ [https://plausible.io/js/plausible.js](http://localtest.me:8000/js/plausible.js) “></script>
Github pages example
A classic example of why this is needed is Github pages. Suppose I have a couple of projects I’d like to see separate stats for:
By default, the Plausible script will record both of these on the domain ukutaht.github.io
and the stats will be merged together. Clearly, these are two separate websites and I’d like to separate these stats. Now I can do this by specifying the domain (or site id) in the tracking script:
<script async defer data-domain=“ukutaht.github.io/elixir-koans” src=“https://plausible.io/js/plausible.js“></script>
and
<script async defer data-domain=“ukutaht.github.io/plausible” src=“ https://plausible.io/js/plausible.js“></script>
Then, in the Plausible UI I can create two sites: ukutaht.github.io/elixir-koans
and ukutaht.github.io/plausible
. This gives me two separate dashboards as desired.