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

feat: track allow list answers #2597

Merged
merged 5 commits into from
Jan 11, 2024

Conversation

Mike-Heneghan
Copy link
Contributor

@Mike-Heneghan Mike-Heneghan commented Dec 21, 2023

What

  • Track the node_fn in analytics_log table to tie together nodes and the passport variables they relate to
  • Track allow_list_answers in analytics when a user directly answers a question

Why

  • Adding node_fn makes it easier to reason about how nodes can affect the passport.
  • Metrics requested the allow_list_answers

Note

@Mike-Heneghan Mike-Heneghan requested a review from a team December 21, 2023 15:53
@Mike-Heneghan Mike-Heneghan self-assigned this Dec 21, 2023
Copy link

github-actions bot commented Dec 21, 2023

🤖 Hasura Change Summary compared a subset of table metadata including permissions:

Updated Tables (1)

  • public.analytics_logs permissions:

    insert select update delete
    public / / /
    3 added column permissions
    insert select update
    public ➕ node_fn ➕ node_id ➕ allow_list_answers

@Mike-Heneghan
Copy link
Contributor Author

Copy link

github-actions bot commented Dec 21, 2023

Removed vultr server and associated DNS entries

Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

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

A few quick comments - can't currently test the pizza as I'm getting CORS issues - I suspect it just needs a rebase as this was something I broke when working on auth before Christmas I think! 👍

@@ -410,6 +421,50 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({
}
}

async function updateLastVisibleNodeLogWithAllowListAnswers(nodeId: string) {
if (shouldTrackAnalytics && lastVisibleNodeAnalyticsLogId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'm not exactly sure how, but it would be nice to handle this repeated condition throughout this provider. Even if we just reverse it and make it a guard clause I think it would be a bit more readable / meaningful

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 think this is a great shout, I think theres a lot of nesting in the file which can make it a bit harder to parse.

I've added more guard clauses and tried to see if I could update the conditionals to be slightly more readable.

It's on this commit and it would be great to get your opinion on the changes: 7bb5ac8

Copy link
Contributor

@DafyddLlyr DafyddLlyr Jan 11, 2024

Choose a reason for hiding this comment

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

This is nice and a good improvement - more readable for sure 👍

What do you think about a change along these lines -

function trackEvent(event: MyEnumOfEventTypes): void {
  skipUpdateIfNotTracking();

  switch (event) {
    case "helpClick":
      // Handle helpClick event
      break;
    case "nextStepsLinkClick":
      // Handle nextStepsLinkClick event
      break;
    // Add more cases as needed
    default:
      // Handle default case or throw an error
      break;
  }
}

The benefits I'd see of this would be -

  • You can't miss the guard clause skipUpdateIfNotTracking() when adding a new event
  • It's a bit more self documenting - when we come back and add a new event type it should be a simpler pattern to follow (add event enum, add case in this controller function)
  • We could drop the "child" functions like trackHelpClick() from the createContext type definition and only expost the "parent" trackEvent() controller.

Super happy for the response to be "not worth it", just wanted to run the idea by you. This could also be a small refactor on a follow up PR! 👍

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 is a really interesting suggestion! I'd noticed there was quite a lot of very similar patterns and something like this could potentially resolve that. Some of the events have specific requirements for further info but I'm sure this could be managed as well.

As this piece of work has been on the burner for a long time I think I'd opt to as you say leave it for now and potentially follow up with a refactor PR in the future. I feel like I'm almost too close to the analyticsProvider file and a bit of time away from it could really help to refactor with fresh eyes

hasura.planx.uk/metadata/tables.yaml Show resolved Hide resolved
@Mike-Heneghan
Copy link
Contributor Author

A few quick comments - can't currently test the pizza as I'm getting CORS issues - I suspect it just needs a rebase as this was something I broke when working on auth before Christmas I think! 👍

Thank you very much for the review, I'll have a look at the comments now.

Strangely with testing on the pizza I wasn't seeing any CORS issues before the holidays and it still seems to be working for me 🤔 I'll double check once I've pushed commits and rebased though.

@DafyddLlyr
Copy link
Contributor

Strangely with testing on the pizza I wasn't seeing any CORS issues before the holidays and it still seems to be working for me 🤔 I'll double check once I've pushed commits and rebased though.

Ah sorry about this - there's certainly a chance I had a local cookie or something else going on - tried again and it works a charm for me now! Will take another look very shortly 👍

@Mike-Heneghan
Copy link
Contributor Author

Strangely with testing on the pizza I wasn't seeing any CORS issues before the holidays and it still seems to be working for me 🤔 I'll double check once I've pushed commits and rebased though.

Ah sorry about this - there's certainly a chance I had a local cookie or something else going on - tried again and it works a charm for me now! Will take another look very shortly 👍

Thanks for checking again @DafyddLlyr, absolutely no rush as I have some local setup issues to squash before I rebase and update as per your comments. As the testing is quite laborious it might be worth waiting until the branch is updated rather than having to do it twice 😅

Mike-Heneghan added a commit that referenced this pull request Jan 8, 2024
- As per: #2597 (comment)
- Update definition to use uppercase variable name and declare as const for consistency and more thorough type defintion
@Mike-Heneghan Mike-Heneghan force-pushed the mh/track-allowlist-guidance-services branch from 3e131e4 to 393e17b Compare January 8, 2024 14:29
Mike-Heneghan added a commit that referenced this pull request Jan 8, 2024
- As per: #2597 (comment)
- Update definition to use uppercase variable name and declare as const for consistency and more thorough type defintion
Mike-Heneghan added a commit that referenced this pull request Jan 8, 2024
- As per: #2597 (comment)
- Reduce nesting by refactoring to use guard clauses
- Abstract commonly used guard clause into it's own function.
@Mike-Heneghan Mike-Heneghan force-pushed the mh/track-allowlist-guidance-services branch from 393e17b to 7bb5ac8 Compare January 8, 2024 16:39
@Mike-Heneghan Mike-Heneghan requested review from a team and DafyddLlyr January 8, 2024 17:34
- The passport variable a node can relate to is stored either on the `fn` or the `val` of the node.
- Begin tracking this to support allow list work
- These allowlist answers will always be an empty array when the log is created
- Added update permission as on breadcrumb changes the record will be updated if the logs node_fn is in the allow_list
- When breadcrumbs change and the user has answered a question check if it's in the allow list and if so store
- Update permission to allow us to select the node_id
- This allows us to ensure that we'll only track allow list answers against the correct nodes
- As per: #2597 (comment)
- Update definition to use uppercase variable name and declare as const for consistency and more thorough type defintion
- As per: #2597 (comment)
- Reduce nesting by refactoring to use guard clauses
- Abstract commonly used guard clause into it's own function.
@Mike-Heneghan Mike-Heneghan force-pushed the mh/track-allowlist-guidance-services branch from 7bb5ac8 to 612fa87 Compare January 10, 2024 17:05
Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

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

Changes look great! Once small comment on abstracting away a few things but it's non-blocking 👌

@Mike-Heneghan Mike-Heneghan merged commit eadb2f6 into main Jan 11, 2024
12 checks passed
@Mike-Heneghan Mike-Heneghan deleted the mh/track-allowlist-guidance-services branch January 11, 2024 11:49
Mike-Heneghan added a commit that referenced this pull request Apr 4, 2024
- As per: #2597 (comment)
- Consolidating individual tracking event functions into a single function with a case statement
- Step towards clearer organisation and documentation of analyticsProvider
Mike-Heneghan added a commit that referenced this pull request Apr 4, 2024
- As per: #2597 (comment)
- Consolidating individual tracking event functions into a single function with a case statement
- Step towards clearer organisation and documentation of analyticsProvider
Mike-Heneghan added a commit that referenced this pull request Apr 4, 2024
- As per: #2597 (comment)
- Consolidating individual tracking event functions into a single function with a case statement
- Step towards clearer organisation and documentation of analyticsProvider
Mike-Heneghan added a commit that referenced this pull request Apr 4, 2024
- As per: #2597 (comment)
- Consolidating individual tracking event functions into a single function with a case statement
- Step towards clearer organisation and documentation of analyticsProvider

Co-authored-by: Dafydd Llŷr Pearson <[email protected]>
Mike-Heneghan added a commit that referenced this pull request Apr 4, 2024
- As per: #2597 (comment)
- Consolidating individual tracking event functions into a single function with a case statement
- Step towards clearer organisation and documentation of analyticsProvider

Co-authored-by: Dafydd Llŷr Pearson <[email protected]>
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.

2 participants