Log in Sign up

Is there a Mustache template key for the request URL path available?

I'm looking to integrate GoatCounter's tracking pixel: https://www.goatcounter.com/help/pixel

Per their docs, this looks like:

<img src="https://MYCODE.goatcounter.com/count?p=/url-goes-here">

I'd like to be able to use Blot's existing templating logic to do something like:

<img src="https://MYCODE.goatcounter.com/count?p=/{{req.url.path}}">

5 months ago, 2 replies   developers   request   Edit question

I don't believe there is a global variable which you can use to achieve something approaching {{req.url.path}}.

Could you use JS instead append the image to the footer of each page? Adding something like this to script.js should do the trick:

document.body.innerHTML += 
  `<img src="https://MYCODE.goatcounter.com/count?p=${window.location.path}">`
Answered 10 months ago · Edit answer

I came up with a solution.

In all my posts & pages I use the link: metadata e.g.

---
link: /my-link
---

So I realized I was able to use this (if it exists) to include a <noscript>:

<script data-goatcounter="https://MYCODE.goatcounter.com/count" async src="//gc.zgo.at/count.js"></script>
{{#entry.metadata.link}}
<noscript>
  <img src="https://MYCODE.goatcounter.com/count?p={{{entry.metadata.link}}}">
</noscript>
{{/entry.metadata.link}}

It's slightly more complicated on my custom theme, but that's the gist of it.

Answered 5 months ago · Edit answer