Ensure the "Top content" CTA for creating the custom dimension appears when the corresponding report error shows the custom dimension is missing #9218
Description
Feature Description
The Audience Tile's "Top content" metric area has a CTA for creating the googlesitekit_post_type
custom dimension if it doesn't exist.
However, it doesn't have logic in place to determine if the custom dimension doesn't exist when requesting the report for the metric. At present it's reliant on the list of available custom dimensions being synced somewhere, which only happens during Audience Segmentation setup, or in the Key Metrics feature.
We should ensure that, if the report for the "Top content" metric returns an error because the custom dimension doesn't exist, the list of custom dimensions is resynced so the tile will immediately know that the dimension is missing and show the CTA to create it.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- If the reports for the Audience Tile's "Top content" metric return an error because the custom dimension doesn't exist:
- For an authenticated user:
- The list of available custom dimensions should be resynced.
- The Audience Tiles should remain in the loading state while the resync is happening.
- Once the resync has finished the populated tiles should show with the CTA for creating the
googlesitekit_post_type
present in the "Top content" metric area (already implemented via Implement the “Top content” metric handling for missing custom dimension #8153).
- For a view-only user, the "Top content" metric area should not be displayed.
- This is because a view-only user doesn't have permission to sync custom dimensions, and we are not going to show the "Top content" metric to them if the custom dimension doesn't exist (see Ensure the “Top content” metric doesn’t appear for view-only users if the custom dimension doesn’t exist #8175), so the logical thing to do here is not to display the metric area if the custom dimension state can't be determined.
- For an authenticated user:
Implementation Brief
Add Missing Custom Dimension to Top Content Report
- Add the
googlesitekit_post_type
dimension filter to the top content report options:
dimensionFilters: {
'customEvent:googlesitekit_post_type': {
filterType: 'stringFilter',
matchType: 'EXACT',
value: 'post',
},
},
site-kit-wp/assets/js/modules/analytics-4/hooks/useAudienceTilesReports.js
Lines 322 to 329 in 119747b
site-kit-wp/assets/js/modules/analytics-4/hooks/useAudienceTilesReports.js
Lines 346 to 353 in 119747b
Authenticated User Context
- Update
assets/js/modules/analytics-4/components/audience-segmentation/dashboard/AudienceTilesWidget/AudienceTiles.js
(note the newuseAudienceTilesReports
custom hook merged in Handle the special case for “new visitors” and “returning visitors” to avoid the “partial data” state in the Audience Tile #8144):- Add a
useEffect
withtopContentReportErrors
as a dependency.- Check if the
topContentReportErrors
contains any invalid custom dimension errors using the.find
prototype, and use theisInvalidCustomDimensionError
util to identify this error type. - If an invalid custom dimension error exists, dispatch the action
fetchSyncAvailableCustomDimensions
.
- Check if the
- Create a new boolean constant
isSyncingAvailableCustomDimensions
containing the value of theisFetchingSyncAvailableCustomDimensions
selector:
- Update the loading statement to include
isSyncingAvailableCustomDimensions
:
- Update the loading statement to include
- Add a
- Filter out invalid custom dimension errors from
topContentReportErrors
andtopContentPageTitlesReportErrors
here, using theisInvalidCustomDimensionError
util, so that the Top Cities Audience Tile will be rendered if there is only an invalid custom dimension error:
View-Only Context
- Update
assets/js/modules/analytics-4/components/audience-segmentation/dashboard/AudienceTilesWidget/AudienceTile/index.js
, use thegetErrorForSelector
selector to get any errors for the top content report for the audienceResourceName of the current tile.- Update this conditional block to not render the Top Cities metric if the user is in the view-only context and the there is a invalid custom dimension error for the Top Cities report:
- Update this conditional block to not render the Top Cities metric if the user is in the view-only context and the there is a invalid custom dimension error for the Top Cities report:
Test Coverage
- Update the tests that fail due to the addition of the custom dimension filter for the Top Content queries.
- Create a VRT when the tile is in the view-only context with an invalid custom dimension error for the Top Content report.
QA Brief
Authenticated user
- Set up Site Kit with the
audienceSegmentation
feature flag enabled and Analytics connected to a property which is out of the "gathering data" state. - Click on Enable groups to set up Audience Segmentation.
- Archive the
googlesitekit_post_type
custom dimension in Analytics. - Return to Site Kit and clear session storage:
sessionStorage.clear()
in the JS console. - Refresh the dashboard.
- Error messages including the phrase "Field customEvent:googlesitekit_post_type is not a valid dimension." will appear in the JS console, this is to be expected.
- A POST request to the
sync-custom-dimensions
endpoint should appear in the network devtools. - The Update CTA should appear in the "Top content" metric area in the Audience Tiles.
View-only user
- Having run through the steps above, share Analytics and login as a view-only user with access to the module.
- The "Top content" metric area should not appear in the Audience Tiles.
Changelog entry
- Ensure the "Top content" CTA for creating the
googlesitekit_post_type
custom dimension appears in the main dashboard when the corresponding report error indicates the missing custom dimension.