google / site-kit-wp

Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
https://sitekit.withgoogle.com
Apache License 2.0
1.25k stars 292 forks source link

Custom Dimension not synced and created after enabling Audience Segmentation without dashboard refresh #9597

Open techanvil opened 3 weeks ago

techanvil commented 3 weeks ago

Bug Description

The googlesitekit_post_type custom dimension is not synced or created when Audience Segmentation is enabled from the dashboard setup CTA without refreshing the Site Kit dashboard after archiving the custom dimension. This also happens from the settings CTA if we don't refresh the page.

See the related Asana task.

Steps to reproduce

  1. Set up Site Kit with Analytics connected, and set up the Audience Segmentation feature to ensure the googlesitekit_post_type custom dimension is created for the connected property.
  2. Reset Site Kit and connect the same Analytics property.
  3. Ensure the list of available custom dimensions is synced - this could be through setting up Key Metrics with a tile that depends on a custom dimension, or running the following snippet in the JS console: googlesitekit.data.dispatch( 'modules/analytics-4' ).fetchSyncAvailableCustomDimensions().
  4. Go to the Site Kit dashboard and ensure the setup CTA banner is displayed (alternatively, navigate to the Settings screen and ensure the setup CTA is displayed there).
  5. In a separate tab, go to the Analytics console and archive the googlesitekit_post_type custom dimension.
  6. Back on Site Kit, enable Audience Segmentation from the setup CTA without refreshing page.
  7. Observe that the custom dimension is not synced or created as expected.

Screenshots

https://github.com/user-attachments/assets/37126deb-7b0c-46e8-988d-e7cc44a3e592

Additional Context


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation Brief

Test Coverage

QA Brief

  1. Set up Site Kit with Analytics connected, and set up the Audience Segmentation feature to ensure the googlesitekit_post_type custom dimension is created for the connected property.
  2. Reset Site Kit and connect the same Analytics property.
  3. Ensure the list of available custom dimensions is synced - this could be through setting up Key Metrics with a tile that depends on a custom dimension, or running the following snippet in the JS console: googlesitekit.data.dispatch( 'modules/analytics-4' ).fetchSyncAvailableCustomDimensions().
  4. Go to the Site Kit dashboard and ensure the setup CTA banner is displayed (alternatively, navigate to the Settings screen and ensure the setup CTA is displayed there).
  5. In a separate tab, go to the Analytics console and archive the googlesitekit_post_type custom dimension.
  6. Back on Site Kit, enable Audience Segmentation from the setup CTA without refreshing page.
  7. Confirm in Google analytics console that the googlesitekit_post_type is created again.

Changelog entry

techanvil commented 2 weeks ago

Hi @ankitrox, thanks for drafting this IB. A couple of points:

https://github.com/google/site-kit-wp/blob/9a919e78e856ee0f7625e47200bd888288955c85/assets/js/modules/analytics-4/datastore/audiences.js#L385-L392

ankitrox commented 1 week ago

Thank you @techanvil . I've updated the IB as per your suggestions.

techanvil commented 1 week ago

Thanks @ankitrox, that LGTM. I've amended the Test Coverage section as we should include test coverage for the changes similar to how we test for the audiences being synced in the action.

IB ✅