nuxt-modules / plausible

🎟️ Plausible Analytics integration for Nuxt
https://plausible.io
MIT License
107 stars 7 forks source link

Proxy through Nitro server #34

Closed MickL closed 1 week ago

MickL commented 3 months ago

I would like everything to be proxied as described in the docs:

https://<yourdomain.com>/js/script.js -> https://plausible.io/js/script.js
https://<yourdomain.com>/api/event    -> https://plausible.io/api/event

In Nuxt normally this can be done easily by use of Nitro route rules, I imagine the following would work:

nuxt.config.ts:

routeRules: {
    '/api/event': {
      redirect: 'https://plausible.io/api/event',
    },
},
plausible: {
    apiHost: '/', <-- This doesnt work
},

The problem is that I cant set the data-api property as it is required and describe in the docs:

<script defer data-api="/api/event" data-domain="website.com" src="/js/script.js"></script>

If I set apiHost to / it makes the call go to https:///api/event instead of /api/event. If this would be fixed I guess it would work as shown above.

MickL commented 3 months ago

I updated the issue. I think it would be possible if we could only set data-api property correctly

hymair commented 2 months ago

Would be even cooler if it is a simple proxy: true config option.

MickL commented 1 week ago

I added one comment to the PR, hope its okay if I dont open a new issue as it should be a quick fix :)