Add GA event tracking for the Audience Selection Panel
Feature Description
GA events should be added to keep track of interaction with the Audience Selection Panel.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
The following GA events should be tracked for the given actions. See the GA events sheet.
| Event Name | Category | Label | Trigger | Condition | Description/details |
|---|---|---|---|---|---|
| change_groups | {viewContext}_audiences-sidebar | Click | User clicks the "Change groups" CTA to open the Selection Panel | ||
| audiences_sidebar_view | {viewContext}_audiences-sidebar | Element visibility | User views the Audiences Selection Panel | "Sidebar" events named for consistency with the corresponding event for KMW | |
| audiences_sidebar_save | {viewContext}_audiences-sidebar | count of audiences by category in the format "user:123,site-kit:456,default:789" | Click | User clicks "Save selection" in the Selection Panel | |
| audiences_sidebar_cancel | {viewContext}_audiences-sidebar | Click | User clicks "Cancel" in the Selection Panel | ||
| insufficient_permissions_error | {viewContext}_audiences-sidebar | Element visibility | User views the insufficient permissions error when loading the Selection Panel data | ||
| insufficient_permissions_error_request_access | {viewContext}_audiences-sidebar | Click | User clicks "Request access" on the error | ||
| data_loading_error | {viewContext}_audiences-sidebar | Element visibility | User views the generic error when loading the Selection Panel data | ||
| data_loading_error_retry | {viewContext}_audiences-sidebar | Click | User clicks "Retry" on the error | ||
| view_notice | {viewContext}_audiences-sidebar-create-audiences | Element visibility | User views the Audience Creation Notice in the Selection Panel | ||
| create_audience | {viewContext}_audiences-sidebar-create-audiences | one of "new-visitors", "returning-visitors" | Click | User clicks "Create" for one of the audiences in the notice | |
| view_oauth_notice | {viewContext}_audiences-sidebar-create-audiences | Element visibility | User views the OAuth notice in the Audiences Creation Notice | ||
| dismiss_oauth_notice | {viewContext}_audiences-sidebar-create-audiences | User clicks "Got it" on the OAuth notice | |||
| view_notification | {viewContext}_audiences-sidebar-create-audiences-success | User views the success notification in the Audience Creation Notice | |||
| dismiss_notification | {viewContext}_audiences-sidebar-create-audiences-success | User clicks "Got it" on the notification | |||
| auth_error | {viewContext}_audiences-sidebar-create-audiences | Element visibility | User views the OAuth error notice in the Audience Creation Notice when an error occurs during audience creation | ||
| insufficient_permissions_error | {viewContext}_audiences-sidebar-create-audiences | Element visibility | User views the insufficient permissions error notice in the Audience Creation Notice when an error occurs during audience creation | ||
| insufficient_permissions_error_request_access | {viewContext}_audiences-sidebar-create-audiences | Click | User clicks "Request access" on the error notice | ||
| setup_error | {viewContext}_audiences-sidebar-create-audiences | Element visibility | User views the generic error notice in the Audience Creation Notice when an error occurs during audience creation |
Implementation Brief
- [ ] In the
ChangeGroupsLinkcomponent:- Call
trackEvent( '${viewContext}_audiences-sidebar', 'change_groups' )in theopenAudiencesSelectionPanel()callback.
- Call
- [ ] In the
AudienceSelectionPanelcomponent:- Call
trackEvent( '${viewContext}_audiences-sidebar', 'audiences_sidebar_view' )in theonSideSheetOpen()callback.
- Call
- [ ] In the
AudienceSelectionPanel/Footercomponent:- Retrieve
availableAudiencesvia thegetAvailableAudiences()selector. - Add an
onSaveSuccesscallback prop to the renderedSelectionPanelFooter:- Determine the
labelfor the GA event in the formatuser:123,site-kit:456,default:789by mappingconfiguredAudiencesto the number of audiences of the given type in the saved selection. The type can be determined by looking up theaudienceTypefor an audience viaavailableAudiences;123/456/789are of course the number of audiences of the given type. - Call
trackEvent( '${viewContext}_audiences-sidebar', 'audiences_sidebar_save', label ).
- Determine the
- Add an
onCancelcallback prop to the renderedSelectionPanelFooter. In the callback, calltrackEvent( '${viewContext}_audiences-sidebar', 'audiences_sidebar_cancel' ).
- Retrieve
- [ ] In the
AudienceSelectionPanel/ErrorNoticecomponent:- Retrieve the selection panel's open state via the
CORE_UIAUDIENCE_SELECTION_PANEL_OPENED_KEYvalue. - Create a variable,
hasErrorswhich contains the value oferrors.length > 0. This is to use in theuseEffect()hook below to avoid passingerrorsas a dependency aserrorswill change more often. - Add a
useEffect()hook.- Return early if the panel is closed or
hasErrorsis false. - If
hasInsufficientPermissionsErroris true, calltrackEvent( '${viewContext}_audiences-sidebar', 'insufficient_permissions_error' ). - Otherwise, call
trackEvent( '${viewContext}_audiences-sidebar', 'data_loading_error' ).
- Return early if the panel is closed or
- Retrieve the selection panel's open state via the
- [ ] In the
AudienceSelectionPanel/RequestAccessButtoncomponent:- Add an
onClickcallback prop to the renderedButton. In the callback, calltrackEvent( '${viewContext}_audiences-sidebar', 'insufficient_permissions_error_request_access' ).
- Add an
- [ ] In the
AudienceSelectionPanel/RetryButtoncomponent:- Add an
onClickcallback prop to the renderedButton. In the callback, calltrackEvent( '${viewContext}_audiences-sidebar', 'data_loading_error_retry' ).
- Add an
- [ ] In the
AudienceCreationNoticecomponent:- Retrieve the selection panel's open state via the
CORE_UIAUDIENCE_SELECTION_PANEL_OPENED_KEYvalue. - Add a
useEffect()hook.- If the panel is open and
shouldShowNoticeis true, calltrackEvent( '${viewContext}_audiences-sidebar-create-audiences', 'view_notice' ).
- If the panel is open and
- Amend the
onClickhandler for theSpinnerButtoncomponent:- Determine the
labelfor the event, which should benew-visitorsorreturning-visitorsdepending on which audience is being created. - Call
trackEvent( '${viewContext}_audiences-sidebar-create-audiences', 'create_audience', label )prior to the call tohandleCreateAudience. Chain the two calls using.finally().
- Determine the
- Add another
useEffect()hook.- Return early if the panel is closed.
- If the conditions for showing the
SubtleNotificationare true (i.e. if! hasAnalytics4EditScope && ! isEditScopeNoticeDismissed) calltrackEvent( '${viewContext}_audiences-sidebar-create-audiences', 'view_oauth_notice' ).
- Amend the
handleDismissEditScopeNotice()callback:- Call
trackEvent( '${viewContext}_audiences-sidebar-create-audiences', 'dismiss_oauth_notice' )prior to the call todismissItem. Chain the two calls using.finally().
- Call
- Retrieve the selection panel's open state via the
- [ ] In the
AudienceCreationSuccessNoticecomponent:- Retrieve the selection panel's open state via the
CORE_UIAUDIENCE_SELECTION_PANEL_OPENED_KEYvalue. - Add a
useEffect()hook.- If the panel is open and
showSuccessNoticeis true, calltrackEvent( '${viewContext}_audiences-sidebar-create-audiences-success', 'view_notification' ).
- If the panel is open and
- Amend the
onClickhandler for theButtoncomponent:- Call
trackEvent( '${viewContext}_audiences-sidebar-create-audiences-success', 'dismiss_notification' )prior to the call tosetValue. Chain the two calls using.finally().
- Call
- Retrieve the selection panel's open state via the
- [ ] In the
AudienceCreationErrorNoticecomponent:- Create a variable,
hasErrorswhich contains the value oferrors.length > 0. This is to use in theuseEffect()hook below to avoid passingerrorsas a dependency aserrorswill change more often. - Add a
useEffect()hook.- Return early if
hasErrorsis false. - If
hasOAuthErroris true, calltrackEvent( '${viewContext}_audiences-sidebar-create-audiences', 'auth_error' ). - Otherwise, if
hasInsufficientPermissionsErroris true, calltrackEvent( '${viewContext}_audiences-sidebar-create-audiences', 'insufficient_permissions_error' ). - Otherwise, call
trackEvent( '${viewContext}_audiences-sidebar-create-audiences', 'setup_error' ).
- Return early if
- Add an
onClickcallback prop to the renderedButton. In the callback, calltrackEvent( '${viewContext}_audiences-sidebar-create-audiences', 'insufficient_permissions_error_request_access' ).
- Create a variable,
Test Coverage
- Add JS test coverage for the above changes where tests exist for the affected components.
QA Brief
Changelog entry
IB ✅
QA Update ⚠
Tested this and while the events are being tracked accordingly, I do have a couple of queries:
ITEM 1: For the audiences_sidebar_save event, we are expecting the label to be a count of audiences by category in the format "user:123,site-kit:456,default:789"
My question is what do the numbers represent? What is the expectation for these? Currently during my testing, I had "user:0,site-kit:2,default:0" I am unable to verify the accuracy of those numbers.
ITEM 2: For the dismiss_oauth_notice event, it would be when User clicks "Got it" on the OAuth notice. Per my testing, I could not see the 'Got it' button from the oauth_notice. Could you double check the attached image and let me know if that's the correct notice to check or we indeed do not have a 'Got it' button?
ITEM 3: For the view_notification event, it triggers when user views the success notification in the Audience Creation Notice.
Let's say there are 2 audiences to be created: New and Returning
- If I create for the 'New' audience, the event is fired accordingly.
- Now, if I go on to create for 'Returning' audience, the success message remains but there is a no new firing of the event. Should we be firing it one more time?
https://github.com/user-attachments/assets/1a0fe227-14a1-4b70-a39f-37a57aa298a1
Thank you for sharing your observations, @kelvinballoo !
ITEM 1: For the audiences_sidebar_save event, we are expecting the label to be a count of audiences by category in the format "user:123,site-kit:456,default:789"
My question is what do the numbers represent? What is the expectation for these? Currently during my testing, I had "user:0,site-kit:2,default:0" I am unable to verify the accuracy of those numbers.
The numbers represent the number of audiences under each category. In your case, you seem to have saved the audience selection with 0 user audiences, 2 Site Kit audiences, and 0 default audiences. Does that help?
ITEM 2: For the dismiss_oauth_notice event, it would be when User clicks "Got it" on the OAuth notice. Per my testing, I could not see the 'Got it' button from the oauth_notice. Could you double check the attached image and let me know if that's the correct notice to check or we indeed do not have a 'Got it' button?
The oauth_notice actually refers to this notice:
The notice you're referring to in your screenshot will have the following tracking criteria:
| auth_error | {viewContext}_audiences-sidebar-create-audiences | Element visibility | User views the [OAuth error notice](https://www.figma.com/design/7pSrkEy8t00BcYRAi9LjjH/Audience-Segmentation?node-id=1821-26925&node-type=frame&t=PNTGwXm0OYTItlYB-0) in the Audience Creation Notice when an error occurs during audience creation |
ITEM 3: For the view_notification event, it triggers when user views the success notification in the Audience Creation Notice.
Let's say there are 2 audiences to be created: New and Returning
- If I create for the 'New' audience, the event is fired accordingly.
- Now, if I go on to create for 'Returning' audience, the success message remains but there is a no new firing of the event. Should we be firing it one more time?
With the way it is currently built, the notice doesn't reappear once it is already visible, hence, the event is also tracked once. It might be worth checking with @techanvil to see if the notice should reappear, and if so, a new issue is warranted here.
Please let me know if you have any other questions, thanks!
ITEM 3: For the view_notification event, it triggers when user views the success notification in the Audience Creation Notice. Let's say there are 2 audiences to be created: New and Returning
- If I create for the 'New' audience, the event is fired accordingly.
- Now, if I go on to create for 'Returning' audience, the success message remains but there is a no new firing of the event. Should we be firing it one more time?
With the way it is currently built, the notice doesn't reappear once it is already visible, hence, the event is also tracked once. It might be worth checking with @techanvil to see if the notice should reappear, and if so, a new issue is warranted here.
Please let me know if you have any other questions, thanks!
Thanks @kelvinballoo and @nfmohit. As Nahid has pointed out the notice is already visible, there's no need to hide/reshow it in response to the second audience creation and we don't need to track an additional event in the above scenario.
When it comes to analysing the GA events we should be able to recognise that a second audience was successfully created within the span of the current selection panel opening as we have events for the panel opening, the Create CTA being clicked, and the success notification being shown/dismissed and the error notification being shown, all of which should be sufficient to reconstruct the journey.
QA Update ⚠
Hi @nfmohit ,
ITEM 1: It does help but there seems to be a discrepancy between the audiences that I saved and what is being tracked. If you see in my previous screenshot, the audience selected was only 'New Visitors' but it registered 2. It should have been 1. I have documented other discrepancies in the attached video for you to review.
https://github.com/user-attachments/assets/ee9515ee-e9ca-476f-986c-4accc95729d4
ITEM 2:
I was trying to look into steps to re-create that oAuth notice but could not successfully find the steps from other tickets.
Could you elaborate on the steps to get the oauth_notice that you pointed out please.
ITEM 3: Noted on that.
Thank you for the follow-up, @kelvinballoo!
ITEM 1: It does help but there seems to be a discrepancy between the audiences that I saved and what is being tracked. If you see in my previous screenshot, the audience selected was only 'New Visitors' but it registered 2. It should have been 1. I have documented other discrepancies in the attached video for you to review.
I investigated, was able to replicate the issue, and opened a follow-up PR.
ITEM 2: I was trying to look into steps to re-create that oAuth notice but could not successfully find the steps from other tickets. Could you elaborate on the steps to get the
oauth_noticethat you pointed out please.
You should be able to see this by deleting the wp_googlesitekit_additional_auth_scopes option from the PREFIX_usermeta table for your user.
Back to you for another pass, @kelvinballoo!
QA Update ✅
Tested ITEM 1 and the audiences saved are now reflecting accordingly on the label.
Other than that, all the events are being tracked accordingly too as detailed further down. The screenshots include ITEM 2 as well.
Moving ticket to approval.
-
change_groups
-
audiences_sidebar_view
-
audiences_sidebar_save
-
audiences_sidebar_cancel
-
insufficient_permissions_error (audiences-sidebar)
-
insufficient_permissions_error_request_access (audiences-sidebar)
-
data_loading_error
-
data_loading_error_retry
-
view_notice
-
create_audience
-
view_oauth_notice
-
dismiss_oauth_notice
-
view_notification
-
dismiss_notification
-
auth_error
-
insufficient_permissions_error (audiences-sidebar-create-audiences)
-
insufficient_permissions_error_request_access (audiences-sidebar-create-audiences)
-
setup_error (audiences-sidebar-create-audiences)