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.cmdchallenge.com/count"
async src="//s.cmdchallenge.com/count.js"></script>
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