openedx / wg-frontend

Open edX Frontend Working Group
4 stars 1 forks source link

Modular Web Analytics #148

Closed arbrandes closed 1 year ago

arbrandes commented 1 year ago

Motivation

To begin, Google Universal Analytics will stop working on July 1, 2023, and it's all the current snippet in the LMS supports. We'll either need to deprecate/remove this by then, or move to support Google Analytics 4 (as has been requested in the forum).

In parallel, we need to investigate the possibility of supporting GA in MFEs (something that has also been requested explicitly).

Possible solutions

Loading arbitrary javascript

One could allow operators to define custom external scripts to be loaded in the head of server-side rendered pages or MFEs; the operator would be able to load any arbitrary analytics engines that way.

OEP-15 proposed a way to do this for entires courses; see its implementation. A similar thing could be done for both LMS server-side pages and MFEs. The latter, in particular, could be served a list of custom JS (maybe even snippets) via runtime configuration, which in turn supports site configuration, thus allowing for per-domain analytics configuration.

However, an attempt to bring this into the Learning MFE was rejected at the time for good reasons. Loading generic scripts can throw a wrench into SPA react apps.

Questions:

Explicit support for analytics engines in MFEs

frontend-platform already has explicit support for Segment in what looks to be a modular analytics service framework. frontend-app-learning, for instance, tracks clicks using it.

It should be possible to implement GA and others using this method. However, each MFE would have to be modified to support the desired tracking.

Support for analytics engines in a containing SPA

Once Modular MFE Domains are a thing, it would be relatively simple to support modular analytics engines at the containing SPA level. Because routing would be done for MFEs at this level, page tracking need not be done in an MFE itself. Event tracking would still have to be done by the MFE, of course, but all MFEs would use the same instance of the analytics service interface.

#### Foundational
- [ ] https://github.com/openedx/frontend-platform/pull/472
#### PRs against master
- [ ] https://github.com/openedx/edx-platform/pull/32032
- [ ] https://github.com/openedx/frontend-app-learning/pull/1102
- [ ] https://github.com/openedx/frontend-app-profile/pull/733
- [ ] https://github.com/openedx/frontend-app-authn/pull/876
- [ ] https://github.com/openedx/frontend-app-account/pull/779
- [ ] https://github.com/openedx/frontend-app-discussions/pull/501
#### PRs against Palm
- [ ] https://github.com/openedx/edx-platform/pull/32107
- [ ] https://github.com/openedx/frontend-app-learning/pull/1105
- [ ] https://github.com/openedx/frontend-app-profile/pull/737
- [ ] https://github.com/openedx/frontend-app-authn/pull/879
- [ ] https://github.com/openedx/frontend-app-account/pull/780
- [ ] https://github.com/openedx/frontend-app-discussions/pull/503
#### PRs agains Olive
- [ ] https://github.com/openedx/edx-platform/pull/32106
- [ ] https://github.com/openedx/frontend-app-learning/pull/1106
- [ ] https://github.com/openedx/frontend-app-profile/pull/738
- [ ] https://github.com/openedx/frontend-app-authn/pull/880
- [ ] https://github.com/openedx/frontend-app-account/pull/781
- [ ] https://github.com/openedx/frontend-app-discussions/pull/504
arbrandes commented 1 year ago

@bmtcril, some food for thought. Might become an ADR or even an OEP. I no longer think our original approach is the best idea, but it's listed as the first possible solution, above.

The second one is probably the best we'd be able to do before Modular MFE Domains kick in. It looks reasonably self-contained, so we should be able to make a funded project out of it.

Definitely not for Olive, though. And we'd need to get things rolling pretty quickly if we want to get ready by Palm - which we pretty much have to if we want to continue supporting Google Analytics in any fashion.

arbrandes commented 1 year ago

Forum thread to go with this: https://discuss.openedx.org/t/google-universal-analytics-google-analytics-4-and-all-mfes/8749

bmtcril commented 1 year ago

Thanks for writing all of this up @arbrandes ! I agree the second option will get us out of the current problem, but there are so many players in the analytics space that operators might want to integrate with I don't think it will scale for us in the long term. I'll definitely keep an eye on the MFE Domains planning to see what we can do to keep this use case in mind during the process, but in the meantime I'd be ok with implementing the Segment-style integration for GA to get us through.

arbrandes commented 1 year ago

@bmtcril, I believe all PRs are merged, now. Can you check and see if I missed anything?

bmtcril commented 1 year ago

This looks good to me, let me just double check with RG that there's nothing outstanding and we can close this beast! Thanks for the heroic efforts.

bmtcril commented 1 year ago

Raccoon Gang believes this is done as well and has sent the close out report. Closing!