Use navigator.sendBeacon

You can use navigator.sendBeacon() with GoatCounter, for example to send events when someone closes a page:

<script>
    document.addEventListener('visibilitychange', function(e) {
        if (document.visibilityState !== 'hidden')
            return

        if (goatcounter.filter())
            return
        navigator.sendBeacon(goatcounter.url({
            event: true,
            path: function(p) { return 'unload-' + p },
        }))
    })
</script>
<script data-goatcounter="https://s.jarv.org/count"
        async src="//s.jarv.org/count.js"></script>

Questions or problems?

Feel free to get in touch if you’ve got any questions or having any problems; a lot of times they can be resolved without too much problems.

Ways to contact me: show