"Purchasers" audience not selected during setup for the initial admin
Bug Description
Issue discovered during bug bash. Asana task here
The "Purchasers" audience is not being selected when it should be during setup for the initial admin. I've captured an example for the setup from the dashboard, the same occurs when setting up from the Settings screen. Reviewing the code it's evident that the "Purchasers" audience will not be selected under any circumstances during setup for the initial admin.
The "Purchasers" audience is however correctly selected during the setup for a secondary user as seen in the video for the view-only case.
Screencasts
https://github.com/user-attachments/assets/0ddb1f50-e2e5-4819-986f-74f9a434aa3c
https://github.com/user-attachments/assets/006486c3-8228-4f05-ac5e-e3f659d878c8
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- When setting up Audience Segmentation via the Enable groups CTA on the dashboard or Settings screen:
- If there are any user-defined audiences with data over the past 90 days, or either of the Site Kit-created audiences have already been created, so the user's selection is populated with existing audiences
-
And, when evaluating these non-default audiences for inclusion, there is only one eligible user-defined or Site Kit-created audience available to add to the selection, so there's still one slot left to fill:
- The "Purchasers" default audience should be included in the selection if it has ever had any visitors.
Implementation Brief
- [x] In the
*enableAudienceGroupMain()action, prior to the conditional block that creates the new/returning visitors audiences, check if there is exactly one audience inconfiguredAudiences. If so, run the following code to create the "Purchasers" audience if it's ever had any users. The code can be extracted from*enableSecondaryUserAudienceGroupMain()to a separate function for reuse.
https://github.com/google/site-kit-wp/blob/dfcc37f37c0672470309e63f6f0d02b7598e4e86/assets/js/modules/analytics-4/datastore/audiences.js#L609-L627
Test Coverage
- Extend the tests for
*enableAudienceGroup()to cover the above changes.
QA Brief
-
Connect with the GA4 analytics property which has the data for "Purchaser" audience and one of the following: a. Exactly one user created audience with data. b. Exactly one Site Kit created audience.
-
Enable the Audience Segmentation feature and setup the feature.
-
"Purchaser" audience tile should be added in Audiences tile widget section, so in total there would be two tiles, one is "Purchaser" and other would be amongst
aorbstated above.
Changelog entry
- Ensure the "Purchasers" default audience can be added to the audience selection when initially setting up the Audience Segmentation feature under the right conditions.
I've estimated this an 11 to allow for testing, which could potentially be a bit time consuming.
IB ✅
QA Update ✅
This was verified good. Moving ticket to approval. Scenarios tested were as follows:
-
Property has one user-defined audience without any SK-defined audience: ✅
- The user-defined audience + Purchasers are appearing accordingly
- Verified good for view-only user as well.
https://github.com/user-attachments/assets/b17c4910-1f10-43a2-9ba3-5583b0882120
-
Property has one SK-defined audience without any user-defined audience: ✅
- The SK-defined audience + Purchasers are appearing accordingly
- Verified good for view-only user as well.
https://github.com/user-attachments/assets/857dc253-0dd1-4f3a-8eb6-a753ebc08e17
-
Property has one SK-defined audience and one user-defined audience: ✅
- The SK-defined audience + user-defined audience are appearing accordingly
- Verified good for view-only user as well.