plausible-hugo icon indicating copy to clipboard operation
plausible-hugo copied to clipboard

Custom tracking script name

Open FarisZR opened this issue 1 year ago • 20 comments

Hello, thanks for the awesome project!,

can you add the ability to customize the tracking script's name? I use nginx rewrite to get past ad-blockers, and it would be useful if this component can support custom script names.

FarisZR avatar Jul 05 '22 22:07 FarisZR

I don't understand what you need. do you have an example for your use case ??

divinerites avatar Aug 14 '22 20:08 divinerites

I meant a way to change the standard script name from, plausible.js, to something different.

For example, https://server.domain.com/js/plausible.js > https://server.domain.com/js/pls1.js.

Its the same script, just a different name.

Its used to get past Ad-blockers, more details here: https://plausible.io/docs/proxy/introduction https://plausible.io/docs/proxy/guides/nginx

FarisZR avatar Aug 14 '22 20:08 FarisZR

Sorry but still do not understand. This project is usefull if you use the plausible script.

If you have control on your ngnix, why don't you make what you want/need on the rewrite part ??

I do not see how my module can help you in the ngnix use case. Or more precisely I do not see why you can't just rewrite the script in the spirit of proxy_netlify.html and use the basic code ?

divinerites avatar Aug 14 '22 20:08 divinerites

I think that renaming the script is the job for the proxy part and not for this module. I provide the proxy_netlify.html as a bonus. So it is sort of an "add-on" outside the module.

divinerites avatar Aug 14 '22 20:08 divinerites

I know, what i am asking is for this module, to use the new and proxied script name. Not the standrad name.

Instead of calling https://plausible.server.com/js/pausible.js, it would call the custom script name specified by the user, like https://plausible.server.com/js/newname.js

FarisZR avatar Aug 14 '22 20:08 FarisZR

I know, what i am asking is for this module, to use the new and proxied script name. Not the standrad name. Instead of calling plausible.server.com/js/pausible.js, it would call the custom script name specified by the user, like plausible.server.com/js/newname.js

Yes I understand.

This is why i'm telling you that this is the work for the proxy/ rewrite part. And not this module.

Just take the proxy_netlify.html idea and code this same principle in your ngnix conf. I think it is just this.

When you've done it I can add your ngnix conf to the project.

divinerites avatar Aug 14 '22 20:08 divinerites

I have NO WAY to do this in the module.

This only can be done on the proxy side (netlify or ngnix, apache, whatever)

divinerites avatar Aug 14 '22 20:08 divinerites

And I do think that if you still, call from plausible.server.com this will not bypass the adblockers.

Whatever the script name is.

divinerites avatar Aug 14 '22 20:08 divinerites

I have already setup a rewrite, i already have a custom script name.

This module by default, uses the default script name by Plausible (/js/plausible.js).

I want to make the module use the custom script name, which I already had set up with Nginx.

So instead of calling /js/plausible.js, it will call the new rewritten script name specified by the user.

I'm not asking for the module to do the rewrite for me, I already set it up, I want the module to use it.

FarisZR avatar Aug 14 '22 20:08 FarisZR

OK. I saw that you have a clean way of doing it : <script async defer data-domain="aosus.org" src="https://pa.aosus.org/js/pls4.js"></script>

But I'm really sorry ... i just do not understand the point.

My module JUST call the right script from plausible.io according to variables. Just that.

AFTER this, and because I use Netlify I rewrite the origin+script name for something else in my netlify conf. And I provide as a bonus a partial for this : proxy_netlify.html

In your case if I use the domain name pa.aosus.org I would have written this:

# Redirects for plausible.io & github.com/divinerites/plausible-hugo
{{- if site.Params.plausible.outbound_link }}
/js/pls4.js https://plausible.io/js/plausible.outbound-links.js 200
{{- else }}
/js/pls4.js https://plausible.io/js/plausible.js 200
{{- end }}
/api/event https://plausible.io/api/event 200

And this would generate your <script async defer data-domain="aosus.org" src="https://pa.aosus.org/js/pls4.js"></script> or so.

divinerites avatar Aug 14 '22 20:08 divinerites

You are asking for something that I (or anyone) can't do inside this module.

divinerites avatar Aug 14 '22 20:08 divinerites

Would the module use /js/s/pls4.js instead of directly conneting to plausible?

FarisZR avatar Aug 14 '22 20:08 FarisZR

Would the module use /js/s/pls4.js instead of directly conneting to plausible?

Sorry, but I think you're missing something on the way all this works.

It is the other way ; YOU rename the plausible script in whatever you want.

divinerites avatar Aug 14 '22 20:08 divinerites

about a way to change the name of the script used in the module

I'm still far away to understand why you still looking for this rename thing in THIS module, as it is a EXTERNAL job to do. Still puzzled with your request and the lack of trying to do this outside the script.

Also this projects seems to not support Self-hosted Plausible instances, is that right?

I do not use it myself, but we have a self hosting option

[params.plausible]
   selfhosted_domain = "myplausible.example.com"  # Self-hosted plausible domain

divinerites avatar Oct 11 '22 08:10 divinerites

If you look at this partial plausible_redirects_netlify.html, it is just something created for netlify users, but this partial is OUTSIDE the real module.

Just do the same with your context.

In short : I WILL NOT change the scripts name in this module. NOT.

divinerites avatar Oct 11 '22 08:10 divinerites

That comment was an email that was probably stuck on sending a long time ago. Sorry to re-open the issue!

FarisZR avatar Oct 11 '22 23:10 FarisZR

I have made the change that I think you want, and was certainly what I was after, here; https://github.com/steve-winter/plausible-hugo

New config param to enable changing the JS filename to whatever I want.

steve-winter avatar Oct 12 '22 10:10 steve-winter

Thanks see my comment.

Reopening for now

divinerites avatar Oct 12 '22 11:10 divinerites

OK. Got your comments on the PR.

So we all agree (@steve-winter & @FarisZR) :

  1. The option for changing the script name is concernin g self-hosting use case.
  2. In all other cases (using the polausible.io service), changing script name only can be done thru proxy rewrite.
  • This is outside the scope of this module.
  • We can add some extra partial for that if someone provide the code for the proxy.
    • The example for this is the plausible_redirects_netlify.html exytra script
    • You could name it plausible_redirects_MYPROXY.html with MYPROXY being the proxy real name.

Are we all ok with this ? If yes i will make the change base on your PR.

divinerites avatar Oct 12 '22 13:10 divinerites