Tracking script shouldn't require a separate <script> for config
Everything should be configured via data- attributes (or something else). Basically – just avoid another script tag.
Is there any reason to not just do something like this?
<script>
(function () {
window.counterscale = {
q: [["set", "siteId", "your-unique-site-id"], ["trackPageview"]],
};
var cs = document.createElement('script');
cs.id = 'counterscale-script';
cs.src = 'https://counterscale.{yoursubdomain}.workers.dev/tracker.js';
cs.defer = true;
document.head.appendChild(cs);
})();
</script>
Sounds like you're suggesting something like this though
<script src="/tracking.js" id="counterscale-script" data-counterscale='[["set", "siteId", "counterscale-dev"], ["trackPageview"]]' defer></script>
Then in the tracking script
var scriptTag = document.currentScript;
var q = JSON.parse(scriptTag.getAttribute('data-counterscale'));
Still need to dig into how the tracking script works not really sure what the point of the queue is at a glance but passing the array as a data attribute feels kind of off
Is there any reason to not just do something like this?
You totally could – but the reason to use data- attributes is so that users who have disallowed inline scripts using CSP can still use Counterscale.
Sounds like you're suggesting something like this though
Still need to dig into how the tracking script works not really sure what the point of the queue is at a glance but passing the array as a data attribute feels kind of off
I'd probably the kill the queue stuff entirely.
The tracking script is a fork (see the comments in the file). I didn't really alter how it behaves besides removing some cookie stuff.
Fixed via #132