Record Plausible analytics events for endpoints intended for Nextstrain CLI#1161
Record Plausible analytics events for endpoints intended for Nextstrain CLI#1161
Conversation
75438cb to
cd7aa5b
Compare
7718729 to
5199543
Compare
|
This appears to work with actual submission to Plausible, BTW. With Nextstrain CLI built from nextstrain/cli#434, I ran: and I saw the appropriate request/response in mitmproxy and I see the event in Plausible when I filter to the review app's hostname. |
…in CLI These will help us in the future gain insight into Nextstrain CLI version usage and update patterns as well as pathogen repository setup and update patterns.
5199543 to
55e096d
Compare
| const userAgentToPlausibleKeys = new Map([ | ||
| ["Nextstrain-CLI", "nextstrain-cli/version"], | ||
| ["Python", "nextstrain-cli/python"], | ||
| ["installer", "nextstrain-cli/installer"], | ||
| ["platform", "nextstrain-cli/platform"], | ||
| ["tty", "nextstrain-cli/tty"], | ||
| ]); |
There was a problem hiding this comment.
Ah okay. It's finally clicking for me here that this is parsing the User-Agent created in the Nextstrain-CLI so that we can track these within Plausible.
Looks like we can configure Plausible to display these properties in the dashboard.
There was a problem hiding this comment.
I was going to leave them for ad-hoc analytics viewing until we settle on what's the most useful view (if we do).
| */ | ||
| fetch( | ||
| // <https://plausible.io/docs/events-api> | ||
| PLAUSIBLE_ANALYTICS_ENDPOINT, { |
There was a problem hiding this comment.
I'm surprised this doesn't require some king of API key, but maybe that's normal for tracking?
There was a problem hiding this comment.
It's pretty normal for analytics that are focused on the client-side (like Plausible), since there is no way to have any actual secrets without server-side involvement. Analytics spam is totally a thing that happens as a result, though, and as such providers like Plausible have to do a bit of spam/abuse prevention work.
| /* We intentionally do not "await fetch()" as we do not want to block | ||
| * request processing on analytics; we'd rather ignore failures. | ||
| * -trs, 28 April 2025 | ||
| */ | ||
| fetch( |
There was a problem hiding this comment.
I'm a little hesitant to use the interpreter's event loop/task queue here as our own offline work queue, as it seems like badness awaits if we start clogging it up with requests that take a long time to complete (e.g. if network cxn to Plausible is very slow to connect or transfer data). And it's not a queue we can manage on our own or have much insight into by default. But it seems an ok place to start, probably, esp. in the absence of some other obvious work queue in our stack.
These will help us in the future gain insight into Nextstrain CLI version usage and update patterns as well as pathogen repository setup and update patterns.
Checklist