Add GA event tracking for the "Top content" metric area of an Audience Tile
Feature Description
GA events should be added to keep track of interaction with the "Top content" metric area of an Audience Tile.
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 | Trigger | Condition |
|---|---|---|---|
| view_cta | {viewContext}_audiences-top-content-cta | Element visibility | User views the "Update" CTA for creating the custom dimension for "Top content" on a tile |
| create_custom_dimension | {viewContext}_audiences-top-content-cta | Click | User clicks the "Update" CTA |
| auth_error | {viewContext}_audiences-top-content-cta | Element visibility | User views the OAuth error modal on the dashboard when an error occurs in response to clicking the CTA |
| auth_error_retry | {viewContext}_audiences-top-content-cta | Click | User clicks "Retry" on the modal |
| auth_error_cancel | {viewContext}_audiences-top-content-cta | Click | User clicks "Cancel" on the modal |
| insufficient_permissions_error | {viewContext}_audiences-top-content-cta | Element visibility | User views the insufficient permissions error modal on the dashboard when an error occurs in response to clicking the CTA |
| insufficient_permissions_error_request_access | {viewContext}_audiences-top-content-cta | Click | User clicks "Request access" on the modal |
| insufficient_permissions_error_cancel | {viewContext}_audiences-top-content-cta | Click | User clicks "Cancel" on the modal |
| setup_error | {viewContext}_audiences-top-content-cta | Element visibility | User views the generic error modal on the dashboard when an error occurs in response to clicking the CTA |
| setup_error_retry | {viewContext}_audiences-top-content-cta | Click | User clicks "Retry" on the modal |
| setup_error_cancel | {viewContext}_audiences-top-content-cta | Click | User clicks "Cancel" on the modal |
Implementation Brief
- [ ] Extract the conditional JSX block containing the Update CTA from the
AudienceTilePagesMetricContentcomponent to a new component e.g.CreateCustomDimensionCTA.- Wrap the
CreateCustomDimensionCTAcomponent inforwardRef()so arefcan be passed to it, and add therefto its top-level rendered element.
- Wrap the
- [ ] In the
AudienceTilePagesMetricContentcomponent:- Create a version of
CreateCustomDimensionCTAwrapped by thewithIntersectionObserver()HOC, e.g.CreateCustomDimensionCTAWithIntersectionObserver. Render this in place of the existingCreateCustomDimensionCTAinstance. - Add an
onInViewcallback prop toCreateCustomDimensionCTAWithIntersectionObserver. In the callback, calltrackEvent( '${viewContext}_audiences-top-content-cta', 'view_cta' ). - Create a
handleCreateCustomDimension()callback:- Call
trackEvent( '${viewContext}_audiences-top-content-cta', 'create_custom_dimension' ), followed byonCreateCustomDimension(). Chain the two calls using.finally().
- Call
- Pass
handleCreateCustomDimensiontoCreateCustomDimensionCTAWithIntersectionObserverinstead ofonCreateCustomDimension.
- Create a version of
- [ ] In the
ModalDialogcomponent:- Add an optional
onOpenprop of typePropTypes.func, and pass the prop to the renderedDialogcomponent. - Pass the existing
handleConfirmprop through to theButtoninstance that is rendered whenbuttonLinkis provided.
- Add an optional
- [ ] In the
AudienceErrorModalcomponent:- Add a
trackEventCategoryprop of typePropTypes.string. - Add an
onOpencallback prop toModalDialog:- Determine the
actionfor the GA event:auth_errorfor an OAuth error,insufficient_permissions_errorfor an insufficient permissions error, orsetup_errorfor any other error. - In the callback, call
trackEvent( trackEventCategory, action ).
- Determine the
- Create a
handleConfirmcallback:- Determine the
actionfor the GA event:auth_error_retryfor an OAuth error,insufficient_permissions_error_request_accessfor an insufficient permissions error, orsetup_error_retryfor any other error. - Call
trackEvent( trackEventCategory, action ), followed byonRetry()unless the error is an insufficient permissions error. Chain the two calls using.finally().
- Determine the
- Replace
onRetrywithhandleConfirmas the value for thehandleConfirmprop that is passed toModalDialog. - Create a
handleDialogcallback:- Determine the
actionfor the GA event:auth_error_cancelfor an OAuth error,insufficient_permissions_error_cancelfor an insufficient permissions error, orsetup_error_cancelfor any other error. - Call
trackEvent( trackEventCategory, action ), followed byonCancel(). Chain the two calls using.finally().
- Determine the
- Replace
onCancelwithhandleDialogas the value for thehandleDialogprop that is passed toModalDialog.
- Add a
- [ ] In the
AudienceTilePagesMetriccomponent:- Pass the
trackEventCategoryprop toAudienceErrorModalwith the value${viewContext}_audiences-top-content-cta.
- Pass the
Test Coverage
- Add JS test coverage for the above changes where tests exist for the affected components.
QA Brief
CTA events
- Set up Site Kit with the
audienceSegmentationfeature flag enabled, tracking enabled, and Analytics connected using a property which is out of the gathering data state. - Click on Enable groups to set up Audience Segmentation.
- Archive the
googlesitekit_post_typecustom dimension in Analytics. - Back on Site Kit, clear session storage and refresh the page. Verify the Update CTA appears in the "Top content" metric area for the audience tile(s).
- Using a mechanism for checking tracked Analytics events, e.g. Tag Assistant or the Google Analytics Debugger Chrome extension, verify the
view_ctaevent is tracked as per the AC. - Click on an Update CTA and verify the
create_custom_dimensionevent is tracked as per the AC.
Error Modal events
OAuth error
- Follow the steps above to show the Update CTA for the audiences tile(s).
- Delete the
{db_prefix}_googlesitekit_additional_auth_scopesentry from the{db_prefix}_usermetatable and refresh the page to ensure the edit scope is needed. - Click on an Update CTA to enter the OAuth flow. Cancel out of the OAuth flow to return to Site Kit with an OAuth error.
- Verify the
auth_errorevent is tracked as per the AC. - Click Retry on the error modal and verify the
auth_error_retryevent is tracked as per the AC. - Cancel the OAuth flow again to re-show the error modal. Click Cancel on the modal and verify the
auth_error_cancelevent is tracked as per the AC.
Insufficient permissions error
- Either use a connected GA property which you only have view access to, or simulate the insufficient permissions error using the following Tweak Chrome extension configuration:
- URL:
.*/wp-json/google-site-kit/v1/modules/analytics-4/data/create-custom-dimension.* - Enable the use of regular expression
(.*) - HTTP Method:
POST - Status code:
403 - Response payload:
{ "code": 403, "message": "Insufficient Permissions Test Error", "data": { "status": 403, "reason": "insufficientPermissions" } }
- URL:
- Follow the steps above to show the Update CTA for the audiences tile(s).
- Click on an Update CTA. Proceed through the OAuth flow if necessary. Upon returning to Site Kit the error modal should appear showing the insufficient permissions error message.
- Verify the
insufficient_permissions_errorevent is tracked as per the AC. - Click Request access on the modal and verify the
insufficient_permissions_error_request_accessevent is tracked as per the AC. - Click Cancel on the modal and verify the
insufficient_permissions_error_request_cancelevent is tracked as per the AC.
Generic error
- Simulate an API error other than the insufficient permissions error, for example a 500 error using the following Tweak configuration:
- URL:
.*/wp-json/google-site-kit/v1/modules/analytics-4/data/create-custom-dimension.* - Enable the use of regular expression
(.*) - HTTP Method:
POST - Status code:
500 - Response payload:
{ "code": "internal_server_error", "message": "Internal server error", "data": { "status": 500 } }
- URL:
- Follow the steps above to show the Update CTA for the audiences tile(s).
- Click on an Update CTA. Proceed through the OAuth flow if necessary. Upon returning to Site Kit the error modal should appear showing the generic error message.
- Verify the
setup_errorevent is tracked as per the AC. - Click Retry on the modal and verify the
setup_error_retryevent is tracked as per the AC. - Click Cancel on the modal and verify the
setup_error_request_cancelevent is tracked as per the AC.
Changelog entry
- Add opt-in event tracking for an audience tile's "Top content" metric area.
Thank you for drafting the IB, @techanvil !
In the
AudienceTilePagesMetriccomponent:
- Pass the
trackEventPropertypropAudienceErrorModalwith the value${viewContext}_audiences-top-content-cta.
Just to confirm, did you mean trackEventCategory instead of trackEventProperty?
Also, do you think it might be worth bumping up the estimate for this one by a notch considering the slightly wider surface area?
Thanks!
I certainly did, thanks for another catch! I've fixed the typo, and bumped the estimate too, that SGTM. Back over to you, cheers!
Thank you Tom! IB ✅
QA Update ⚠
Hi @techanvil , I've tried to simulate the 'Update' button for the "Top content" metric area but it won't appear. I followed the QAB and did it a couple of times but in vain.
https://github.com/user-attachments/assets/0d5edab4-b960-4158-a715-dd8590f55639
Hi @kelvinballoo, it looks like you have mock report data enabled in the Tester plugin. This scenario can't be tested using mock data as it relies on the insufficient permissions error that is returned by a real report. Please try again with mock report data disabled.
QA Update ✅
The GA events were logged successfully for all the events. Moving ticket to approval.
-
view_cta
-
create_custom_dimension
-
auth_error
-
auth_error_retry
-
auth_error_cancel
-
insufficient_permissions_error
-
insufficient_permissions_error_request_access
-
insufficient_permissions_error_cancel
-
setup_error
-
setup_error_retry
-
setup_error_cancel