Skip to content

Record Plausible analytics events for endpoints intended for Nextstrain CLI#1161

Merged
tsibley merged 1 commit intomasterfrom
trs/cli-analytics
May 5, 2025
Merged

Record Plausible analytics events for endpoints intended for Nextstrain CLI#1161
tsibley merged 1 commit intomasterfrom
trs/cli-analytics

Conversation

@tsibley
Copy link
Contributor

@tsibley tsibley commented Apr 29, 2025

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

@nextstrain-bot nextstrain-bot temporarily deployed to nextstrain-s-trs-cli-an-7zooyl April 29, 2025 20:32 Inactive
@tsibley tsibley force-pushed the trs/cli-version-endpoint branch from 75438cb to cd7aa5b Compare April 30, 2025 03:15
@tsibley tsibley force-pushed the trs/cli-analytics branch from 7718729 to 5199543 Compare April 30, 2025 03:15
@tsibley tsibley temporarily deployed to nextstrain-s-trs-cli-an-7zooyl April 30, 2025 03:15 Inactive
@tsibley
Copy link
Contributor Author

tsibley commented Apr 30, 2025

This appears to work with actual submission to Plausible, BTW.

With Nextstrain CLI built from nextstrain/cli#434, I ran:

envd mitmproxy NEXTSTRAIN_DOT_ORG=https://nextstrain-s-trs-cli-an-7zooyl.herokuapp.com/ -- nextstrain check-setup docker

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.
@tsibley tsibley force-pushed the trs/cli-analytics branch from 5199543 to 55e096d Compare April 30, 2025 04:20
@tsibley tsibley temporarily deployed to nextstrain-s-trs-cli-an-7zooyl April 30, 2025 04:20 Inactive
Base automatically changed from trs/cli-version-endpoint to master April 30, 2025 04:22
Comment on lines +66 to +72
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"],
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this doesn't require some king of API key, but maybe that's normal for tracking?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +34 to +38
/* 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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tsibley tsibley merged commit ed5581a into master May 5, 2025
8 checks passed
@tsibley tsibley deleted the trs/cli-analytics branch May 5, 2025 18:40
@tsibley
Copy link
Contributor Author

tsibley commented May 5, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants