Trigger the custom GA `view_notification` event only when the banner notifications are visible
See original GitHub issueBug Description
Currently, some banner notifications trigger the custom GA view_notification
event using the useMount
hook. However, the view_notification
event will be triggered even if the banner notification is not displayed due to the respective component returning null
if the data is unavailable.
The above event should be triggered if the respective banner notification is displayed.
Steps to reproduce
- Go to the Site Kit dashboard.
- Ensure the Google Analytics Debugger is enabled.
- Open the dev tools->console and filter by
view_notification
. - Notice some GA events are triggered even though respective banner notifications aren’t displayed. For example,
mainDashboard_wp52-version-notification
is triggered.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- All the banner notifications that trigger the custom GA
view_notification
event should be triggered if the respective banner notification is displayed. The following notification events should be checked to only send when the component actually renders and doesn’treturn null
- https://github.com/google/site-kit-wp/blob/5841f2b67715762c98a76e644f534ed000b47a03/assets/js/components/activation/activation-app.js#L62
- https://github.com/google/site-kit-wp/blob/a7a6f45123b24b9c767ac62ae4dcd2c6c5a1bd6a/assets/js/components/notifications/SetupSuccessBannerNotification.js#L99-L102
- https://github.com/google/site-kit-wp/blob/a7a6f45123b24b9c767ac62ae4dcd2c6c5a1bd6a/assets/js/components/notifications/WPVersionBumpNotification.js#L53
Implementation Brief
- We should trigger the
trackEvent
call within auseEffect
instead of theuseMount
hook, conditionally on the same code path that causes the component to actually render. An example of how we have done this is in theThankWithGoogleSupporterWallNotification
component. - This should be done in the following places:
- https://github.com/google/site-kit-wp/blob/5841f2b67715762c98a76e644f534ed000b47a03/assets/js/components/activation/activation-app.js#L62
- Change the
useMount
that callstrackEvent
to be auseEffect
that only runs whenbuttonURL
is truthy.
- Change the
- https://github.com/google/site-kit-wp/blob/a7a6f45123b24b9c767ac62ae4dcd2c6c5a1bd6a/assets/js/components/notifications/SetupSuccessBannerNotification.js#L99-L102
- Change the
useMount
to auseEffect
here: https://github.com/google/site-kit-wp/blob/5841f2b67715762c98a76e644f534ed000b47a03/assets/js/components/notifications/SetupSuccessBannerNotification.js#L99-L102 so it only runs when the conditions to notreturn null
are met (starts withmodules !== undefined && !! notification
, but also includes conditions in this switch case). It might be worth cleaning up the switch case here and returning early in a few places, as the current logic is a bit hard to read.
- Change the
- https://github.com/google/site-kit-wp/blob/a7a6f45123b24b9c767ac62ae4dcd2c6c5a1bd6a/assets/js/components/notifications/WPVersionBumpNotification.js#L53
- Update the
useMount
to auseEffect
that only callstrackEvent
whenhasMinimumWPVersion === false && version !== undefined
- Update the
- https://github.com/google/site-kit-wp/blob/5841f2b67715762c98a76e644f534ed000b47a03/assets/js/components/activation/activation-app.js#L62
Test Coverage
- No new tests needed.
QA Brief
- Install Site Kit via the plugin directory and activate it. Ensure the
view_notification
GA event for theactivation
category is triggered only when theActivationApp
notification is displayed. (This notification will have theCongratulations, the Site Kit plugin is now activated.
title). - Ensure the
view_notification
GA event for themainDashboard_wp52-version-notification
event category is triggered only when theWPVersionBumpNotification
is displayed. - Ensure the following events are triggered only when the
SetupSuccessBannerNotification
is displayed:view_notification
-mainDashboard_authentication-success-notification
complete_user_setup
-mainDashboard_authentication-success-notification
complete_site_setup
-mainDashboard_authentication-success-notification
Changelog entry
- Fix bug that could cause a notification view event to be sent even when the notification doesn’t appear.
Issue Analytics
- State:
- Created a year ago
- Comments:8
Top Results From Across the Web
Create and manage custom alerts - Analytics Help
Create custom alerts · Sign in to Google Analytics. · Navigate to your view. · Open Reports. · Click CUSTOMIZATION > Custom Alerts....
Read more >A User's Guide to Google Analytics Custom Alerts - The Good
Custom alerts tell Google Analytics to send notifications (email or text) when signals you've predetermined on your website are triggered.
Read more >Custom Alerts in Google Analytics 4 - (The Complete Guide)
In GA4, custom alerts are called Custom Insights. Learn what's new, how to set them up and how to put insight notifications at...
Read more >Change notification settings on iPhone - Apple Support (JO)
Go to Settings > Notifications. Choose how you want notifications displayed on the Lock Screen: View just the number of notifications: Tap Count....
Read more >The Element Visibility Trigger In Google Tag Manager
What do you mean? Custom Dimensions don't exist outside hits sent to GA, and a hit sent to GA requires a tag such...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Good spot there @aaemnnosttv. I have looked into this and it’s not a regression as I can see the same behaviour in the previous release. I’ve created a followup issue to address this: https://github.com/google/site-kit-wp/issues/6109
Thanks, @tofumatt. Could you please add more information to IB? I think that each components have different circumstances when we can consider them as rendered, right? Let’s write them down in IB.