Skip to content

Conversation

@jkachel
Copy link
Contributor

@jkachel jkachel commented Sep 23, 2024

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/5520
Closes https://github.com/mitodl/hq/issues/5283
https://github.com/mitodl/hq/issues/5254

Description (What does it do?)

We need some events to fire when certain events happen in the frontend. These include:

  • When a learner adds a course to a list (bookmarks it)
  • When a learner adjusts their search parameters, including term

These aren't necessarily captured in an intuitive way automatically by PostHog, so this adds explicit events to capture these interactions.

  • For list adds, this will capture a lr_add_to_list event. This contains the same data as lrd_view (so, basic resource info) plus the type of list the resource was added to (either a user list or a learning path).
  • For search query changes, this captures a search_updated event. This captures:
    • No extra data for facet changes.
    • An isEnter flag if the learner has adjusted their search term - this is True if they have submitted via Enter key, or False if they clicked the submit button/icon.

How can this be tested?

If you don't have your own PostHog account set up, you can either set one up for this or use the MIT Learn Test project in the OL PostHog account.

Note

If you're rolling your own, it is imperative that you also set up this transformation in Data Pipelines - it should exist in the list if you hit Add Transformation in PostHog.

The URL parameters to convert should be set to q,resource_type,certification_type,delivery,department,topic,offered_by,free,professional and the Prefix should be set to search_param_. I also turn on Ignore case and Add to user properties but these aren't strictly required.

Test lr_add_to_list by adding a course to a list. You should see the event pop up in the Activity view (note that it may take a bit of time for it to show up).

Test search_update by making changes to your search - select some facets, update your term. This should result in some events being captured in PostHog.

Additional Context

search_update will fire once for each facet that is chosen. So, if you select multiple items in a row, you will end up with events for all of those individual selections. This is by design at this point - we will revisit later if we need to but we're explicitly not debouncing it now.

In testing, I noticed that there's a bug in https://github.com/PostHog/posthog-app-url-parameters-to-event-properties with regard to query parameter arrays: it does not handle them properly, so you only see whatever the first one is from the param. The facets code appends to the list rather than prepends so this means if you choose more than one of a given type of facet you'll only ever see the first one you chose. (This is especially noticeable for Topics.) This should really be fixed upstream so will work that out separately.

This fires an event called `lr_add_to_list` that captures the same data as `lrd_view` except adding the listType that was added to (LearningPath or UserList).
…t. Add PostHog dependency to ol-components.

In either case, this depends on a transformer being installed to convert the query string to the properties needed to do reporting on. The event fires without any additional data for facets, and only with a flag (isEnter) to determine how the user submitted their request when fired by the search term input.

This also adds PostHog as a requirement for the ol-components workspace - we need to know whether or not the user hit Enter or clicked the Submit icon, so we're capturing the PH event in the ol-components code.
@jkachel jkachel marked this pull request as ready for review September 25, 2024 18:47
@shanbady shanbady self-requested a review September 30, 2024 13:20
@shanbady shanbady self-assigned this Sep 30, 2024
Copy link
Contributor

@shanbady shanbady left a comment

Choose a reason for hiding this comment

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

👍

@jkachel jkachel merged commit 8045dcb into main Sep 30, 2024
@jkachel jkachel deleted the jkachel/add-more-analytics-events branch September 30, 2024 15:16
@odlbot odlbot mentioned this pull request Oct 1, 2024
10 tasks
mbertrand pushed a commit that referenced this pull request Oct 4, 2024
Adds event capturing for facet selection and search term updating, so we can track these more efficiently in PostHog.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants