Inconsistent behavior in GA event tracking
- Dominant language
- JavaScript
- Stars
- 1.4k
- Forks
- 383
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 80
Description
## Bug Description
When gathering the Idea Hub GA metrics into a dashboard, some of the numbers seemed off. Especially, the total (distinct) user count on events for activating the `idea-hub` module was lower than the same count on events for completing the `idea-hub` module setup - which clearly makes no sense.
After some investigation, it turns out that some of the related events are simply not being logged consistently. This is especially clear because in one case two tracking events that fire in the exact same point in the codebase, right after each other, had different counts throughout all time periods, even recent ones (so it can be ruled out that this was because e.g. one event would have been added later). Even when looking at a single site these were different.
The events that could be helpful to look at are:
1. action `activate_module`, category `dashboard_module-activation-notification`, label `idea-hub`
2. action `confirm_notification`, category `dashboard_module-activation-notification`, label `idea-hub`
2. action `confirm_notification`, category `dashboard_site-notification`, label `idea-hub-module-notification`
The 1. one is the one that we specifically added to track the Idea Hub module activations from that prompt banner (compared to other places from where the module can be activated, e.g. the widget CTA or the plugin settings), but as mentioned above it is way too low relative to how many sites completed the Idea Hub module setup. What's especially strange is that the 1. and 2. event happen in the same place in the codebase, but the 2. one, which fires earlier, has a notably higher distinct user count - these two should be _exactly_ the same if things were working correctly (see https://github.com/google/site-kit-wp/blob/1.48.1/assets/js/components/notifications/IdeaHubPromptBannerNotification.js#L80). Last but not least, the 3. one also fires with these, just right before (see https://github.com/google/site-kit-wp/blob/1.48.1/assets/js/components/notifications/BannerNotification.js#L147, the `onCTAClick` prop called afterwards is the function in the other code linked).
Here's a screenshot of these three metrics for the past 4 weeks, as an example:

What would be expected here is that all of these are pretty much the same value, but that's not at all the case. Cross-validating with the expected value for what overall activations should be, only the 3. value (which is the one fired first) is accurate.
So it looks like some events aren't reliably tracked. A potential cause could be the following navigation away from the current page (although one would expect that the GA `event_callback` logic, together with the `await` calls of `trackEvent` would ensure that this is not an issue), or it could be that maybe GA throttles event tracking if multiple events are tracked right at the same time. We'll need some debugging here, potentially test locally under which conditions some events are sent unreliably.
---------------
_Do not alter or remove anything below. The following sections will be managed by moderators only._
## Acceptance criteria
*
## Implementation Brief
*
### Test Coverage
*
## QA Brief
*
## Changelog entry
*
Contributor guide
Assessment
This issue has not been assessed yet.