Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Site Health section #8181

Closed
7 tasks
techanvil opened this issue Jan 25, 2024 · 13 comments
Closed
7 tasks

Add Site Health section #8181

techanvil opened this issue Jan 25, 2024 · 13 comments
Labels
Module: Analytics Google Analytics module related issues P1 Medium priority Team M Issues for Squad 2 Type: Enhancement Improvement of an existing feature

Comments

@techanvil
Copy link
Collaborator

techanvil commented Jan 25, 2024

Feature Description

Add the new “Analytics 4 site created audiences” section to Site Health.

See Site Health in the design doc.


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

Acceptance criteria

  • When the audienceSegmentation feature flag is enabled, the Site Health section for Site Kit should contain a new section.
  • The title for the section should be: Analytics site created audiences.
  • The value of the section should a list of the audiences that Site Kit has created, i.e. the "new visitors" and "returning visitors" audiences, if they exist.
  • The names of these audiences should be displayed as they are in Analytics (i.e. their display names should be presented in the list).

Implementation Brief

  • In includes/Modules/Analytics_4.php, inside the get_debug_fields method:
    • Check if the audienceSegmentation feature flag is enabled.
    • If it is enabled, add a new entry in $debug_fields with following:
      • label as Analytics site created audiences.
      • value as comma separated string, containing the displayName fields from the audiences stored in the availableAudiences setting whose audienceType is 'SITE_KIT_AUDIENCE'. Feel free to add an additional method to retrieve these, or it can be inlined.
      • debug should be the same value.
    • An example of adding a debug field conditionally can be seen here.

Test Coverage

  • In tests/phpunit/integration/Modules/Analytics_4Test.php fix the test_get_debug_fieldss test.
  • Fix any other failing tests.

QA Brief

  • Ensure that you have access to analytics 4 property where you can create the audiences. This will require write permission. Connect such a property in Google analytics in site kit.

  • Run the following command in browser console.

const newAudience = {
    "description": "People who visited the site for the first time",
    "displayName": "New visitors",
    "exclusionDurationMode": null,
    "membershipDurationDays": 30,
    "filterClauses": [
        {
            "clauseType": "INCLUDE",
            "simpleFilter": {
                "scope": "AUDIENCE_FILTER_SCOPE_ACROSS_ALL_SESSIONS",
                "filterExpression": {
                    "andGroup": {
                        "filterExpressions": [
                            {
                                "orGroup": {
                                    "filterExpressions": [
                                        {
                                            "dimensionOrMetricFilter": {
                                                "atAnyPointInTime": null,
                                                "fieldName": "newVsReturning",
                                                "inAnyNDayPeriod": null,
                                                "stringFilter": {
                                                    "caseSensitive": null,
                                                    "matchType": "EXACT",
                                                    "value": "new"
                                                }
                                            }
                                        }
                                    ]
                                }
                            },
                            {
                                "orGroup": {
                                    "filterExpressions": [
                                        {
                                            "notExpression": {
                                                "dimensionOrMetricFilter": {
                                                    "fieldName": "groupId",
                                                    "stringFilter": {
                                                        "matchType": "EXACT",
                                                        "value": "created_by_googlesitekit:new_visitors"
                                                    }
                                                }
                                            }
                                        }
                                    ]
                                }
                            }
                        ]
                    }
                }
            }
        }
    ]
};

const returningAudience = {
    "description": "People who have visited your site at least once before",
    "displayName": "Returning visitors",
    "exclusionDurationMode": null,
    "membershipDurationDays": 30,
    "filterClauses": [
        {
            "clauseType": "INCLUDE",
            "simpleFilter": {
                "scope": "AUDIENCE_FILTER_SCOPE_ACROSS_ALL_SESSIONS",
                "filterExpression": {
                    "andGroup": {
                        "filterExpressions": [
                            {
                                "orGroup": {
                                    "filterExpressions": [
                                        {
                                            "dimensionOrMetricFilter": {
                                                "atAnyPointInTime": null,
                                                "fieldName": "newVsReturning",
                                                "inAnyNDayPeriod": null,
                                                "stringFilter": {
                                                    "caseSensitive": null,
                                                    "matchType": "EXACT",
                                                    "value": "returning"
                                                }
                                            }
                                        }
                                    ]
                                }
                            },
                            {
                                "orGroup": {
                                    "filterExpressions": [
                                        {
                                            "notExpression": {
                                                "dimensionOrMetricFilter": {
                                                    "fieldName": "groupId",
                                                    "stringFilter": {
                                                        "matchType": "EXACT",
                                                        "value": "created_by_googlesitekit:returning_visitors"
                                                    }
                                                }
                                            }
                                        }
                                    ]
                                }
                            }
                        ]
                    }
                }
            }
        }
    ]
}

googlesitekit.data.dispatch('modules/analytics-4').createAudience(newAudience);
googlesitekit.data.dispatch('modules/analytics-4').createAudience(returningAudience);

This will trigger two requests to modules/analytics-4/data/create-audience in the browser which should create two new audiences New visitors and Returning visitors in Google Analytics.

  • Once above requests are executed successfully with 200 response code, run following command in browser console.
googlesitekit.data.dispatch('modules/analytics-4').syncAvailableAudiences();

It will sync audiences from Google Analytics to Site Kit.

  • Go to Tools > Site Health > Info > Site Kit by Google, you must see the section Analytics site created audiences with value New visitors, Returning visitors.

Changelog entry

  • Add a Site Health section which lists the Site Kit-created audiences.
@techanvil techanvil added Module: Analytics Google Analytics module related issues P1 Medium priority Type: Enhancement Improvement of an existing feature labels Jan 25, 2024
@ivonac4 ivonac4 added the Team M Issues for Squad 2 label Apr 9, 2024
@techanvil techanvil assigned techanvil and unassigned techanvil Apr 19, 2024
@ankitrox ankitrox assigned ankitrox and unassigned ankitrox May 2, 2024
@techanvil techanvil self-assigned this May 7, 2024
@techanvil
Copy link
Collaborator Author

Hi @ankitrox, thanks for drafting this IB. However, the approach you've suggested is not really necessary - we can add to the Analytics_4::get_debug_fields() method instead, where the other Analytics related Site Health fields are defined.

For example, see the "available custom dimensions" entry:

'analytics_4_available_custom_dimensions' => array(
'label' => __( 'Analytics available custom dimensions', 'google-site-kit' ),
'value' => empty( $settings['availableCustomDimensions'] )
? __( 'None', 'google-site-kit' )
: join(
/* translators: used between list items, there is a space after the comma */
__( ', ', 'google-site-kit' ),
$settings['availableCustomDimensions']
),
'debug' => empty( $settings['availableCustomDimensions'] )
? 'none'
: join( ', ', $settings['availableCustomDimensions'] ),
),

image

@techanvil techanvil assigned ankitrox and unassigned techanvil May 7, 2024
@ankitrox ankitrox assigned techanvil and unassigned ankitrox May 7, 2024
@techanvil
Copy link
Collaborator Author

Thanks @ankitrox, this is looking better, one thing though - we try to avoid including literal code blocks in IBs. I would say this IB can be written without the code block, please can you remove/rewrite that aspect? You can simply say to take the existing custom dimension entry as a reference, for example and permalink to the entry.

@techanvil techanvil removed their assignment May 8, 2024
@nfmohit nfmohit assigned nfmohit and unassigned nfmohit May 8, 2024
@ankitrox
Copy link
Collaborator

ankitrox commented May 9, 2024

Thank you @techanvil for reviewing the IB.

I agree that adding the literal code block is not good idea as the execution should be at the engineer's discretion.

As per your suggestion, I have removed the code block and added the list wide pointers for the implementation.

Assigning it to you for the review again.

Thank you.

@techanvil
Copy link
Collaborator Author

Thanks @ankitrox!

I've made some additional changes to the IB. Notably I've removed the explicit definition for the new method and left this optional, and also removed the point about calling redact_debug_value() for the debug field, this is not needed here as the names are not personal data, rather they are standard names that all Site Kit users may see. I've also made a few minor grammatical tweaks.

Please review the changes and if you are happy feel free to move this to the EB.

IB ✅

@techanvil techanvil assigned ankitrox and unassigned techanvil May 9, 2024
@ankitrox
Copy link
Collaborator

ankitrox commented May 9, 2024

Looking everything good. Thanks @techanvil

Moving this to EB.

@ankitrox ankitrox assigned ankitrox and unassigned ankitrox May 9, 2024
@ankitrox ankitrox removed their assignment May 15, 2024
@techanvil techanvil self-assigned this May 21, 2024
@techanvil
Copy link
Collaborator Author

techanvil commented May 21, 2024

Hi @ankitrox, as well as addressing the feedback left on the PR, please can you update the QAB for this issue as follows:

  • Rather than providing an audience configuration for "SiteKit Audience", provide instructions for creating audiences with the configuration for the "new visitors" and "returning visitors" audiences. This will be more representative of the real world expectations, and also allow testing the comma separated list rather than a single audience.
  • Ensure that names are correctly formatted with uppercase initials. In this case "Analytics" (referring to Google Analytics) and "Site Kit" are lowercased where they should be name-cased.

@techanvil techanvil assigned ankitrox and unassigned techanvil May 21, 2024
@ankitrox
Copy link
Collaborator

Hi @techanvil ,

Thank you for the review.

I have addressed your feedback on the PR and also updated QAB so that we create New visitors and Returning visitors audiences in Google Analytics.

Assigning this to you for the re-review.

Thank you.

@ankitrox ankitrox assigned techanvil and unassigned ankitrox May 22, 2024
@techanvil
Copy link
Collaborator Author

Thanks @ankitrox! I've left a few further comments on the PR, please take a look.

I've also tweaked the code example in the QAB slightly to follow our usual naming conventions (not essential, but might as well!), and to be slightly more verbose - we don't need to aim for DRY code in QABs, it's generally better if it's slightly more straightforward.

@techanvil techanvil assigned ankitrox and unassigned techanvil May 23, 2024
@ankitrox
Copy link
Collaborator

Thank you @techanvil for reviewing the PR.

I have addressed the comments in the PR and QAB code is looking good.

Assigning this back to you for review.

Thanks.

@ankitrox ankitrox assigned techanvil and unassigned ankitrox May 23, 2024
@techanvil
Copy link
Collaborator Author

Thanks @ankitrox! The PR needs one last update and this should be good to go.

@techanvil techanvil assigned ankitrox and unassigned techanvil May 23, 2024
@ankitrox
Copy link
Collaborator

Thank you @techanvil for reviewing the PR.

I've made the suggested change and assigning this to you for the review.

Thanks.

@ankitrox ankitrox assigned techanvil and unassigned ankitrox May 27, 2024
@techanvil techanvil removed their assignment Jun 3, 2024
@kelvinballoo
Copy link
Collaborator

QA Update ❌

Hi @ankitrox , tested this and I was able to do all the steps but in the end, there was not section with the values 'New visitors' and 'Returning visitors' in the Tools > Info section. The details are below:

  • I created the 2 audiences successfully.

    Screenshot 2024-06-05 at 14 45 21

    All requests were with 200 status:
    Screenshot 2024-06-05 at 14 40 31

  • I synced the audiences accordingly with status 200:

    Screenshot 2024-06-05 at 14 45 15
  • However, I could not see the expected values in the Tools > Site Health > Info > Site Kit by Google section

    Screenshot 2024-06-05 at 14 47 05 Screenshot 2024-06-05 at 14 47 20

Assigning ticket to you for further check.

@kelvinballoo
Copy link
Collaborator

QA Update ✅

After reviewing together with @ankitrox , it seems like my branch was not properly connected to Develop.
I re-set it to 'Develop' and it worked fine then.

  • All the scripts are successfully executed
  • Going to Tools > Site Health > Info > Site Kit by Google, I can see the section Analytics site created audiences with value New visitors, Returning visitors.

Moving this ticket to Approval

Scripts are successful: Screenshot 2024-06-05 at 14 40 31

Audiences created successfully:
Screenshot 2024-06-05 at 14 45 21

Values appear at Tools > Site Health > Info > Site Kit by Google
Screenshot 2024-06-05 at 15 14 56

@kelvinballoo kelvinballoo removed their assignment Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module: Analytics Google Analytics module related issues P1 Medium priority Team M Issues for Squad 2 Type: Enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

6 participants