goatcounter
goatcounter copied to clipboard
Unexpected token < in JSON at position 0 when using on Nuxt js site
Hi,
We are using this on a Nuxt site. When we refresh the site we get the error above.
The code we are using is below in the nuxt.config.js site.
script: [
{
type: 'text/javascript',
src: '//gc.zgo.at/count.js',
'data-goatcounter': 'https://securityscorecards.goatcounter.com/count',
async: true,
},
{
type: 'text/javascript',
innerHTML:`
window.goatcounter = {no_onload: true}
window.addEventListener("hashchange", function(e) {
window.goatcounter.count({
path: location.pathname + location.search + location.hash,
})
})`
}
],
This basically loads the site into the head.
Does anyone know why we might hit this error?
I found this, which links to https://staging-netlify-test--elastic-noether-393172.netlify.app/, and it seems it works correctly now?
The goatcounter count script doesn't really do much with JSON; it only loads the data-goatcounter-settings attribute as JSON, and you're not using that, and you should also get a invalid JSON in data-goatcounter-settings: ' + err message if that fails.
So it seems like somehow Nuxt is expecting JSON ... somewhere, but not getting it?