Skip to content

Commit

Permalink
Merge pull request #105 from itsamirhn/chore-update-goat-counter-js
Browse files Browse the repository at this point in the history
chore: Update GoatCounter counter.js file
  • Loading branch information
not-matthias authored Feb 15, 2025
2 parents b808209 + 579c452 commit 0dc952c
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions static/js/count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// GoatCounter: https://www.goatcounter.com
// This file (and *only* this file) is released under the ISC license:
// https://opensource.org/licenses/ISC
// This file (and *only* this file) is released under the ISC license: https://opensource.org/licenses/ISC
;(function() {
'use strict';

Expand Down Expand Up @@ -145,24 +144,27 @@
var f = goatcounter.filter()
if (f)
return warn('not counting because of: ' + f)

var url = goatcounter.url(vars)
if (!url)
return warn('not counting because path callback returned null')

var img = document.createElement('img')
img.src = url
img.style.position = 'absolute' // Affect layout less.
img.style.bottom = '0px'
img.style.width = '1px'
img.style.height = '1px'
img.loading = 'eager'
img.setAttribute('alt', '')
img.setAttribute('aria-hidden', 'true')

var rm = function() { if (img && img.parentNode) img.parentNode.removeChild(img) }
img.addEventListener('load', rm, false)
document.body.appendChild(img)
if (!navigator.sendBeacon(url)) {
// This mostly fails due to being blocked by CSP; try again with an
// image-based fallback.
var img = document.createElement('img')
img.src = url
img.style.position = 'absolute' // Affect layout less.
img.style.bottom = '0px'
img.style.width = '1px'
img.style.height = '1px'
img.loading = 'eager'
img.setAttribute('alt', '')
img.setAttribute('aria-hidden', 'true')

var rm = function() { if (img && img.parentNode) img.parentNode.removeChild(img) }
img.addEventListener('load', rm, false)
document.body.appendChild(img)
}
}

// Get a query parameter.
Expand Down Expand Up @@ -266,5 +268,4 @@
if (!goatcounter.no_events)
goatcounter.bind_events()
})
})();

})();

0 comments on commit 0dc952c

Please sign in to comment.