Using with vue.js and Typescript

Aloha. I’m pretty new to typescript and vue.js so I’m not sure what’s the best approach to use plausible in these contexts. Specifically I want to use custom events and of course webpack will complain that “plausible isn’t defined”. I want plausible to work everywhere (e.g. I can add the script into the head of my index.html) but I also want to call plausible to push custom events and I have no idea what’s the best approach for that.


OK I’ve figured this out and hopefully others will find it useful. Since I’m using typescript I had to cast any. Also as noted in other places adding the logic into the mounted() function where the global window is available is the way to go.

public mounted() {
  const plausible = () => {
    ((window as any).plausible.q = (window as any).plausible.q || []).push(arguments);
  (window as any).plausible = (window as any).plausible || plausible;

then later in my methods I can do,

(window as any).plausible('Plays', {props: {station: "My Station"}});
1 Like

Thanks for the update and the details! Enjoy Plausible!