Skip to content
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

Track chat routes on Plausible #713

Merged
merged 3 commits into from
Jul 3, 2024
Merged

Conversation

rachaelcodes
Copy link
Contributor

Context

This allows us to track the route used in a chat message on Plausible in streamed chat.

Changes proposed in this pull request

Sends the route to the JS app for non-staff users in a new 'hidden-route' event type (this can be removed when the route is available to all users).

For both the 'route' and 'hidden-route' event types, trigger a custom Chat-message-route-[ROUTE NAME] event in Plausible:
https://plausible.io/docs/custom-event-goals#trigger-custom-events-manually-with-a-javascript-function

Guidance to review

  • For someone with experience with Plausible (@KevinEtchells) : Does this look like it will work?
  • Does the code run locally (without Plausible) without triggering console errors?

Relevant links

https://technologyprogramme.atlassian.net/browse/REDBOX-439
https://plausible.io/docs/custom-event-goals#trigger-custom-events-manually-with-a-javascript-function

Things to check

  • I have added any new ENV vars in all deployed environments
  • I have tested any code added or changed
  • I have run integration tests

@rachaelcodes rachaelcodes marked this pull request as ready for review July 2, 2024 11:49
@KevinEtchells
Copy link
Contributor

KevinEtchells commented Jul 2, 2024

The Plausible bits look good. For every route, we'll need to manually add a custom event/goal in the Plausible dashboard. It looks like there's 8 routes currently?

If you feel this will be burdensome in future (e.g. if we're adding lots of routes, having to remember to add the custom events each time etc.) then it may be worth considering just having a single route event with additional props: https://plausible.io/docs/custom-props/for-custom-events#2-using-the-manual-method

Do we need the hidden-route message type in the webSocket.onmessage callback? I appreciate you've commented that this is only temporary, but as this is already hidden perhaps we don't need it at all? I'd be keen to not add any more complexity to this function than we need to, but my question may be due to my lack of understanding of the problem.

Copy link
Contributor

@brunns brunns left a comment

Choose a reason for hiding this comment

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

Looks good for now.

@rachaelcodes
Copy link
Contributor Author

If you feel this will be burdensome in future (e.g. if we're adding lots of routes, having to remember to add the custom events each time etc.) then it may be worth considering just having a single route event with additional props: https://plausible.io/docs/custom-props/for-custom-events#2-using-the-manual-method

Do we need the hidden-route message type in the webSocket.onmessage callback? I appreciate you've commented that this is only temporary, but as this is already hidden perhaps we don't need it at all? I'd be keen to not add any more complexity to this function than we need to, but my question may be due to my lack of understanding of the problem.

@KevinEtchells given that we sometimes add new routes for testing, I'm tempted to use the single 'route' approach you mentioned above

The difference between the hidden-route and the route event is that the hidden-route doesn't remove the 'hidden' attribute from the route object. The other option would be to pass the 'show_route' boolean from Python to JS, which I felt would be even more fiddly to unpick when we're removing it. Let me know if you think otherwise though.

@@ -8433,7 +8433,6 @@ body:has(.iai-environment-warning) main {
.iai-chat-bubble__route {
font-size: 0.625rem;
line-height: 0.825rem;
display: none;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was removed as part of #698 and I think might have got re-added during a rebase

@rachaelcodes rachaelcodes merged commit 15e48b5 into main Jul 3, 2024
7 checks passed
@rachaelcodes rachaelcodes deleted the feature/track-routes-on-plausible branch July 3, 2024 06:21
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.

3 participants