Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking script shouldn't require a separate <script> for config #9

Open
benvinegar opened this issue Jan 18, 2024 · 2 comments
Open
Labels
good first issue Good for newcomers
Milestone

Comments

@benvinegar
Copy link
Owner

Everything should be configured via data- attributes (or something else). Basically – just avoid another script tag.

@benvinegar benvinegar added the good first issue Good for newcomers label Feb 5, 2024
@danecando
Copy link

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

@benvinegar
Copy link
Owner Author

benvinegar commented Feb 20, 2024

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.

@benvinegar benvinegar added this to the 1.0 milestone Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants