New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to specify a URL in the manual extension #1479
Conversation
The uglify-js dependency had to be updated to support the optional chaining operator
This added weight unnecessarily, as the users can simply call the function themselves before triggering the event.
Hey folks! I went ahead and closed the previous PR for this feature since we moved to a completely different implementation. For the documentation, should I simply mention this new feature in the section about the I'll wait for your feedback before working on that part. Cheers! |
tracker/src/plausible.js
Outdated
payload.u = options.u | ||
} | ||
{{else}} | ||
payload.u = options?.u || location.href |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional chaining isn't supported in relatively recent (2019-2020) browsers: https://caniuse.com/?search=optional%20chaining
I think it's fine to just always use the standard if-else flow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call!
I went ahead and replaced it with the following ternary, which saves a few bytes over a regular if-else:
payload.u = options && options.u ? options.u : location.href
I also reverted the dependency update for uglify-js, as the old one better reflected your browser support stance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I would like to remove the optional chaining but otherwise this is good to go
thanks for your contribution @EmilePerron! in terms of docs, we can mention it on the script extensions page and then link from there to its own docs page. this is not the smallest feature to describe so best it has its own page |
It was previously updated to support optional chaining; reverting it as a reminder that this is the current browser support level that is accepted by Plausible.
Great! I'll go ahead and do just that then 👍 |
Thanks @EmilePerron. I'll let you know when this is live |
@EmilePerron it's live |
Could you test it and let me know how it works? |
Just tested it really briefly, looks like it works as intended. Here's the snippet I used for all my pages : <script defer data-domain="koalati.com" src="https://plausible.io/js/plausible.manual.js"></script>
<script>window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }</script>
<script>plausible("pageview");</script> And to test it I ran the following in my browser's console: plausible("pageview", { u: "https://koalati.webflow.io/test" }) The command in my console: The results on Plausible: |
I'll try and update my documentation MR tonight or tomorrow 👨🏻💻 |
@EmilePerron Thanks! Did it count double or did you manually trigger the second pageview? |
@ukutaht I manually triggered the second pageview, which is why it shows up twice. So it feels to me like it works as intended - there's no duplicate count or anything :) |
Wonderful |
Changes
This PR gives users the possibility of specifying a custom tracking location for their pages via a new
u
option in themanual
script extension.The main advantage of this addition is that it allows users to aggregate and/or redact URLs to improve the privacy and usefulness of their analytics. This helps to resolve the issues mentioned in #136.
Custom URLs can be specified either as a string, or a function which returns a string. Absolute URLs (complete with protocol and anchor) are the expected value, in order to maintain the same functionality as with the
Tests
Changelog
Documentation
Other notes and information
manual
extension script (4 bytes when gzipped).Usage examples: