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

Create property and measurement ID from SetupBanner #5717

Merged
merged 14 commits into from
Sep 6, 2022

Conversation

nfmohit
Copy link
Collaborator

@nfmohit nfmohit commented Aug 19, 2022

Summary

Addresses issue:

Relevant technical choices

This PR adds the property and measurement ID creation mechanism in SetupBanner of GA4 Activation Banner.

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 4.7 and PHP 5.6.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

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

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

@github-actions
Copy link

github-actions bot commented Aug 19, 2022

Size Change: +1.07 kB (0%)

Total Size: 1.5 MB

Filename Size Change
./dist/assets/js/googlesitekit-activation-********************.js 28 kB +20 B (0%)
./dist/assets/js/googlesitekit-adminbar-********************.js 36 kB +6 B (0%)
./dist/assets/js/googlesitekit-api-********************.js 9.24 kB -5 B (0%)
./dist/assets/js/googlesitekit-dashboard-details-********************.js 61.1 kB +521 B (+1%)
./dist/assets/js/googlesitekit-dashboard-********************.js 68.9 kB +500 B (+1%)
./dist/assets/js/googlesitekit-dashboard-splash-********************.js 70.8 kB +43 B (0%)
./dist/assets/js/googlesitekit-data-********************.js 2.09 kB +3 B (0%)
./dist/assets/js/googlesitekit-datastore-forms-********************.js 8.88 kB -1 B (0%)
./dist/assets/js/googlesitekit-datastore-ui-********************.js 8.97 kB -3 B (0%)
./dist/assets/js/googlesitekit-datastore-user-********************.js 30.3 kB -4 B (0%)
./dist/assets/js/googlesitekit-idea-hub-post-list-********************.js 26.1 kB +17 B (0%)
./dist/assets/js/googlesitekit-modules-adsense-********************.js 69.6 kB -57 B (0%)
./dist/assets/js/googlesitekit-modules-analytics-4-********************.js 19.1 kB +1 B (0%)
./dist/assets/js/googlesitekit-modules-analytics-********************.js 68.2 kB +9 B (0%)
./dist/assets/js/googlesitekit-modules-idea-hub-********************.js 27.6 kB +1 B (0%)
./dist/assets/js/googlesitekit-modules-optimize-********************.js 19.4 kB +9 B (0%)
./dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 18.5 kB +5 B (0%)
./dist/assets/js/googlesitekit-modules-search-console-********************.js 38.5 kB -5 B (0%)
./dist/assets/js/googlesitekit-modules-tagmanager-********************.js 32.1 kB +2 B (0%)
./dist/assets/js/googlesitekit-modules-thank-with-google-********************.js 24.8 kB -4 B (0%)
./dist/assets/js/googlesitekit-polyfills-********************.js 379 B -1 B (0%)
./dist/assets/js/googlesitekit-settings-********************.js 50.1 kB +53 B (0%)
./dist/assets/js/googlesitekit-user-input-********************.js 44.9 kB -8 B (0%)
./dist/assets/js/googlesitekit-vendor-********************.js 323 kB +2 B (0%)
./dist/assets/js/googlesitekit-widgets-********************.js 19.6 kB +3 B (0%)
./dist/assets/js/googlesitekit-wp-dashboard-********************.js 59.8 kB -41 B (0%)
ℹ️ View Unchanged
Filename Size
./dist/assets/css/googlesitekit-admin-css-********************.min.css 48.4 kB
./dist/assets/css/googlesitekit-adminbar-css-********************.min.css 11.1 kB
./dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 5.97 kB
./dist/assets/js/31-********************.js 2.8 kB
./dist/assets/js/32-********************.js 2.28 kB
./dist/assets/js/33-********************.js 3.72 kB
./dist/assets/js/34-********************.js 51.9 kB
./dist/assets/js/35-********************.js 16.1 kB
./dist/assets/js/36-********************.js 70.9 kB
./dist/assets/js/37-********************.js 31.6 kB
./dist/assets/js/38-********************.js 3.12 kB
./dist/assets/js/analytics-advanced-tracking-********************.js 769 B
./dist/assets/js/googlesitekit-base-********************.js 1.13 kB
./dist/assets/js/googlesitekit-datastore-location-********************.js 2.08 kB
./dist/assets/js/googlesitekit-datastore-site-********************.js 14.9 kB
./dist/assets/js/googlesitekit-i18n-********************.js 3.92 kB
./dist/assets/js/googlesitekit-idea-hub-notice-********************.js 45.1 kB
./dist/assets/js/googlesitekit-modules-********************.js 19.5 kB
./dist/assets/js/runtime-********************.js 1.34 kB

compressed-size-action

Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the QA steps but the "Create Property" button doesn't seem to show the spinner:

CleanShot 2022-08-22 at 23 57 05

(Additionally, the padding/margins seem off, there's more padding once the "Set up now" button is clicked.)

@nfmohit
Copy link
Collaborator Author

nfmohit commented Aug 24, 2022

Additionally, the padding/margins seem off, there's more padding once the "Set up now" button is clicked.

This existed in develop and has been fixed by #5276. I've merged develop into this PR branch and this issue is resolved now.

I tried the QA steps but the "Create Property" button doesn't seem to show the spinner:

I wasn't able to make it show up in my local setup normally as well, so I thought it must be something wrong on my end. In my local setup, both getPropertyID() and getWebDataStreamID() selectors of the modules/analytics-4 store return an empty string. So I basically just altered this condition and the spinner showed up. Do you have any idea how I could remedy this?

Thank you, @tofumatt!

@nfmohit nfmohit requested a review from tofumatt August 25, 2022 08:29
Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @nfmohit, thanks for the comment. Looking at the issue, indeed, that's largely what this issue is about: adding the "Create property" functionality when there is no property (your scenario when you have no propertyID/webStreamID.

I've left a comment and asked for clarification from @techanvil, but you'll need to add that feature into this PR to get things working.

Let me know if you want a hand with that, we can talk it through either here or on a call if that helps 🙂

Comment on lines 60 to 66
const handleSubmitChanges = useCallback( async () => {
const { error } = await submitChanges();

if ( error ) {
setErrorNotice( error );
}
}, [ submitChanges ] );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the code you added as an action, but submitChanges on its own won't do anything if there are no changes made, which is the case here when there is no GA4 properties setup and the user doesn't have a propertyID/webDataStreamID like you mentioned.

From the Design Doc and Figma Design, it doesn't look like there's any specific UI for this, so the "Create Property" should do whatever the Settings page in Analytics does to create a new property. That means clicking it, UX-wise, should prompt the user for extra permissions and create a GA4 property by redirecting them to Analytics I think.

Whatever the Analytics Settings component already does can be used here I think.

Maybe @techanvil can confirm since he wrote up the Design Doc and has more context, but that should do the trick.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tofumatt & @nfmohit - it looks like an implementation detail that is mentioned in the Feature Description has been missed along the way here. This does correlate with what the PropertySelect component is already doing:

For the "no existing GA4 property" variants, i.e when the CTA is Create property, ensure the GA4 propertyID is set to PROPERTY_CREATE prior to calling submitChanges.

Dispatching selectProperty( PROPERTY_CREATE ) will ensure the execution path to create the property will be taken within submitChanges.

if ( propertyID === PROPERTY_CREATE ) {
const accountID = select( MODULES_ANALYTICS ).getAccountID();
const { response: property, error } = await dispatch(
MODULES_ANALYTICS_4
).createProperty( accountID );

Make sure to only dispatch this action for the "no existing GA4 property" variants:

} else if ( existingTag ) {
title = __(
'No existing Google Analytics 4 property found, Site Kit will help you create a new one and insert it on your site',
'google-site-kit'
);
ctaLabel = __( 'Create property', 'google-site-kit' );
footer = sprintf(
/* translators: %s: The existing tag ID. */
__(
'A GA4 tag %s is found on this site but this property is not associated with your Google Analytics account. You can always add/edit this in the Site Kit Settings.',
'google-site-kit'
),
existingTag
);
} else {
title = __(
'No existing Google Analytics 4 property found, Site Kit will help you create a new one and insert it on your site',
'google-site-kit'
);
ctaLabel = __( 'Create property', 'google-site-kit' );
footer = __(
'You can always add/edit this in the Site Kit Settings.',
'google-site-kit'
);
}

I'd refactor it slightly so it's:

} else {
  selectProperty( PROPERTY_CREATE );

  if ( existingTag ) {
    // ...
  } else {
    // ...
  }
}

One more aspect to be aware of is that the case where the edit scope is not available is handled in #5278. So this issue only really needs to handle the case where the permission already exists.

In terms of UX the expectation is for the property creation to happen in the background while the spinner is active, it's not necessary to redirect to Analytics for this, although of course a redirect to the OAuth flow will be necessary to grant permissions but as mentioned this will be handled via #5278.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @tofumatt and @techanvil! I have updated this PR to set the GA4 propertyID to PROPERTY_CREATE for no existing GA4 property. The spinner now shows up to create a measurement ID, but shows an OAuth flow or a permissions error, which I believe will be handled in #5278.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one @nfmohit. In terms of exercising the happy path - I would have thought you'd be able to run through the OAuth flow, grant the permission, and then reload Site Kit with the permissions now granted, at which point you could successfully run through the "Create property" flow...

@nfmohit nfmohit requested a review from tofumatt August 31, 2022 19:21
Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good, but one UX question here after a property is successfully created:

CleanShot.2022-08-31.at.21.58.30.mp4

Should we change the text of the "Cancel" button to "Close" or "OK, got it!" once the property has been created? Given the user can't actually update the property once it's made, I wonder if it's even better not to show the select? Here's what happens if I try to create another new property and select it:

CleanShot.2022-08-31.at.22.01.33.mp4

It doesn't allow me to select a property and since there isn't a save button doesn't allow me to update it anyway.


Maybe this is all out-of-scope for this particular issue? If this will be covered by #5621 and other issues then this looks good-to-go mostly, but the current UX feels a bit incomplete and I want to make sure it's alright…

If you think it's good let me know and maybe I'll get @techanvil to do a merge review since he's more familiar 🙂

@nfmohit
Copy link
Collaborator Author

nfmohit commented Sep 1, 2022

Thank you so much for pointing that out, @tofumatt!

In the screen where the user gets to select a property (i.e. a measurement ID has been created and is available), I believe we want to show a CTA there that says Connect (Figma), clicking on which should dispatch the submitChanges action of the modules/analytics-4 store. This functionality is being implemented in #5282:

const { setValues } = useDispatch( CORE_FORMS );
const { submitChanges } = useDispatch( MODULES_ANALYTICS_4 );
const submitForm = useCallback(
async ( event ) => {
event.preventDefault();
const { error } = await submitChanges();
if ( isPermissionScopeError( error ) ) {
setValues( FORM_SETUP, { autoSubmit: true } );
}
if ( ! error ) {
setValues( FORM_SETUP, { autoSubmit: false } );
// TODO: Check with Tom as it asks to call finishSetup()
onCTAClick();
}
},
[ onCTAClick, setValues, submitChanges ]
);

Do you agree that would cover it? I can surely go ahead and add it in this PR, but that would be a little duplicate/similarily between both PRs.

I'm open to your and @techanvil's suggestions. Thank you!

Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#5282 is about continuing the flow if OAuth permissions aren't set, but there's nothing there about a final "connect" step/button.

The issue I see here is that the existing implementation does more than "create" the property, it actually selects it and saves it in the settings. This can be seen in my previous video, but here's a more clear one where GA4 settings aren't set, and then clicking on the "Create property" button actually saves the setting:

CleanShot.2022-09-01.at.13.37.45.mp4

It seems like that property shouldn't be saved to settings until we hook up the "connect" button, which I think should be a part of this issue as I don't see it mentioned elsewhere.

What I expect to happen is that after clicking "Create property" the user is sent to a screen that looks like this:

CleanShot 2022-09-01 at 13 40 41

Before then, the property would be created but it would NOT be saved in the WordPress/Site Kit settings. The user should need to click "Connect" to actually complete the process. Right now, it happens as soon as they click "Create property".

@nfmohit
Copy link
Collaborator Author

nfmohit commented Sep 2, 2022

Thank you so much for clearing this, @tofumatt!

I did some more thorough reading and observation of the Design Docs and the Figma designs, and I think if there are no existing GA4 properties available and the user creates a new property, we shouldn't display the property select and directly take them to the SuccessBanner. @techanvil Could you help us confirm if that is correct?

Thank you!

@techanvil
Copy link
Collaborator

techanvil commented Sep 2, 2022

Thank you so much for clearing this, @tofumatt!

I did some more thorough reading and observation of the Design Docs and the Figma designs, and I think if there are no existing GA4 properties available and the user creates a new property, we shouldn't display the property select and directly take them to the SuccessBanner. @techanvil Could you help us confirm if that is correct?

Thank you!

Hi @nfmohit, @tofumatt - it's a fair question, but as Nahid has pointed out, in this case the intention is to click on "Create property" and then go directly to the Success banner on success.

It's more analogous to the Setup screen where selecting "Set up a new property" and clicking "Configure Analytics" will go straight through to the Congrats banner without showing the new property in the dropdown.

setup-new-property.mp4

@nfmohit
Copy link
Collaborator Author

nfmohit commented Sep 2, 2022

Thank you for the confirmation, @techanvil!

I have updated the PR to go to the SuccessBanner after a successful submission.

Copy link
Collaborator

@techanvil techanvil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @nfmohit, I just have one small suggestion and this should be good to go.

import { getBannerDismissalExpiryTime } from '../../../utils/banner-dismissal-expiry';
const { useSelect } = Data;
const { useDispatch, useSelect } = Data;

export default function SetupBanner( { onCTAClick } ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest renaming onCTAClick to something that better represents what it's used for in the component - how about onSubmitSuccess ?

@nfmohit
Copy link
Collaborator Author

nfmohit commented Sep 2, 2022

Looks good @nfmohit, I just have one small suggestion and this should be good to go.

I've updated it, thank you @techanvil!

Copy link
Collaborator

@techanvil techanvil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one @nfmohit. LGTM!

@techanvil
Copy link
Collaborator

Hi @nfmohit, apologies as I had thought this PR was good to go. However I subsequently realised the case where an existing property does exist also needs to be covered (see #5277 (comment)).

In order to try to progress this issue today I merged develop into the ticket and resolved merge conflicts. However, having done this one small aspect does stand out. I'm no longer sure this check for ! ga4MeasurementID is necessary - don't we always want to render the CTA button on this component?

! ga4MeasurementID && (
<SpinnerButton onClick={ handleSubmitChanges }>

Secondly, please can you verify the GA4 Property Select dropdown and "Connect" button work as expected in the "existing property" flow, i.e. it correctly connects the selected GA4 component, creating it as necessary? I think it should do but if not please can you make whatever change is needed to make this use case work too. With this working, please can you also update the QAB to include the "existing property" flow?

Copy link
Collaborator

@techanvil techanvil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @nfmohit, sorry to send it back after the initial approve but as mentioned a couple more areas do need to be addressed.

export default function SetupBanner( { onSubmitSuccess } ) {
const [ errorNotice, setErrorNotice ] = useState( null );

const ga4MeasurementID = useSelect( ( select ) =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed I am not sure this is needed now...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this, thank you!

ctaLink={ onCTAClick ? '#' : null }
onCTAClick={ onCTAClick }
ctaComponent={
! ga4MeasurementID && (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, I am not so sure this condition is required, it seems we should always be rendering the CTA here...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially thought we might need a different functionality for the Connect action instead of submitChanges. I've removed this, thank you!

@techanvil techanvil force-pushed the new/#5277-setupbanner-create-id branch from c6db855 to 551ae68 Compare September 5, 2022 17:38
@nfmohit
Copy link
Collaborator Author

nfmohit commented Sep 6, 2022

I've addressed the suggestions. Thank you, @techanvil!

Copy link
Collaborator

@techanvil techanvil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice one @nfmohit

@techanvil techanvil merged commit 049a013 into develop Sep 6, 2022
@techanvil techanvil deleted the new/#5277-setupbanner-create-id branch September 6, 2022 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants