-
Notifications
You must be signed in to change notification settings - Fork 328
[11722] Add GA event tracking for the Analytics setup screen. #11776
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
Changes from 7 commits
f8b25f2
6b6aa0c
de48db5
c18d236
5daa659
00d55fe
54cd414
0c0865f
66a9748
8867812
8d9b9ee
5087bf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,13 +36,18 @@ import { VIEW_CONTEXT_MODULE_SETUP } from '@/js/googlesitekit/constants'; | |
| import { mockLocation } from '../../../../tests/js/mock-browser-utils'; | ||
| import { CORE_USER } from '@/js/googlesitekit/datastore/user/constants'; | ||
| import { CORE_MODULES } from '@/js/googlesitekit/modules/datastore/constants'; | ||
| import * as tracking from '@/js/util/tracking'; | ||
|
|
||
| const mockTrackEvent = jest.spyOn( tracking, 'trackEvent' ); | ||
| mockTrackEvent.mockImplementation( () => Promise.resolve() ); | ||
|
|
||
| describe( 'ModuleSetup', () => { | ||
| mockLocation(); | ||
|
|
||
| let registry; | ||
|
|
||
| beforeEach( () => { | ||
| mockTrackEvent.mockClear(); | ||
|
||
| registry = createTestRegistry(); | ||
| registry.dispatch( CORE_USER ).receiveGetDismissedItems( [] ); | ||
| registry.dispatch( CORE_USER ).receiveGetDismissedPrompts( {} ); | ||
|
|
@@ -175,6 +180,20 @@ describe( 'ModuleSetup', () => { | |
| it( 'should match the snapshot', () => { | ||
| expect( container ).toMatchSnapshot(); | ||
| } ); | ||
|
|
||
| it( 'tracks only the initial setup analytics view event', () => { | ||
| expect( mockTrackEvent ).toHaveBeenCalledWith( | ||
| `${ VIEW_CONTEXT_MODULE_SETUP }_setup`, | ||
| 'setup_flow_v3_view_analytics_step' | ||
| ); | ||
| const genericViewCall = mockTrackEvent.mock.calls.find( | ||
| ( call ) => | ||
| call[ 0 ] === 'moduleSetup' && | ||
| call[ 1 ] === 'view_module_setup' && | ||
| call[ 2 ] === MODULE_SLUG_ANALYTICS_4 | ||
| ); | ||
| expect( genericViewCall ).toBeUndefined(); | ||
techanvil marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } ); | ||
| } ); | ||
|
|
||
| describe( 'not initial setup flow', () => { | ||
|
|
@@ -230,6 +249,20 @@ describe( 'ModuleSetup', () => { | |
| it( 'should match the snapshot', () => { | ||
| expect( container ).toMatchSnapshot(); | ||
| } ); | ||
|
|
||
| it( 'tracks only the generic module setup view event', () => { | ||
| expect( mockTrackEvent ).toHaveBeenCalledWith( | ||
| 'moduleSetup', | ||
| 'view_module_setup', | ||
| MODULE_SLUG_ANALYTICS_4 | ||
| ); | ||
| const initialAnalyticsCall = mockTrackEvent.mock.calls.find( | ||
| ( call ) => | ||
| call[ 0 ] === `${ VIEW_CONTEXT_MODULE_SETUP }_setup` && | ||
| call[ 1 ] === 'setup_flow_v3_view_analytics_step' | ||
| ); | ||
| expect( initialAnalyticsCall ).toBeUndefined(); | ||
techanvil marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } ); | ||
| } ); | ||
| } ); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,6 +155,7 @@ export default function AccountCreate( { className } ) { | |
| }, [ hasAccountCreateForm, siteName, siteURL, timezone, setValues ] ); | ||
|
|
||
| const showProgress = getQueryArg( location.href, 'showProgress' ); | ||
| const isInitialSetupFlow = !! showProgress && setupFlowRefreshEnabled; | ||
|
|
||
| const handleSubmit = useCallback( async () => { | ||
| const scopes = []; | ||
|
|
@@ -192,11 +193,14 @@ export default function AccountCreate( { className } ) { | |
| } | ||
|
|
||
| setValues( FORM_ACCOUNT_CREATE, { autoSubmit: false } ); | ||
| await trackEvent( | ||
| `${ viewContext }_analytics`, | ||
| 'create_account', | ||
| 'proxy' | ||
| ); | ||
|
|
||
| const createAccountEventArgs = isInitialSetupFlow | ||
|
||
| ? [ | ||
| `${ viewContext }_setup`, | ||
| 'setup_flow_v3_create_analytics_account', | ||
| ] | ||
| : [ `${ viewContext }_analytics`, 'create_account', 'proxy' ]; | ||
| await trackEvent( ...createAccountEventArgs ); | ||
|
|
||
| const { error } = await createAccount( { | ||
| showProgress: showProgress === 'true', | ||
|
|
@@ -210,10 +214,11 @@ export default function AccountCreate( { className } ) { | |
| hasEditScope, | ||
| hasGTMScope, | ||
| setValues, | ||
| viewContext, | ||
| isInitialSetupFlow, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason why you added
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good catch @abdelmalekkkkk , thanks for spotting it. I've added it now. |
||
| createAccount, | ||
| showProgress, | ||
| setPermissionScopeError, | ||
| viewContext, | ||
| setConversionTrackingEnabled, | ||
| saveConversionTrackingSettings, | ||
| ] ); | ||
|
|
@@ -242,8 +247,6 @@ export default function AccountCreate( { className } ) { | |
| return <ProgressBar />; | ||
| } | ||
|
|
||
| const isInitialSetupFlow = !! showProgress && setupFlowRefreshEnabled; | ||
|
|
||
| return ( | ||
| <div className={ className }> | ||
| <StoreErrorNotices | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a simple if/else here? It would be more readable in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion @abdelmalekkkkk.
I think we should stick to ternary operator here because of following reasons:
if...elsestatement we may have to either calltrackEventtwice or need to uselet completionEventArgswhich is susceptible to change which is a source of potential side-effect bugs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ankitrox, thanks for explaining your rationale here, however, I would agree with @abdelmalekkkkk that it would be more readable to use an
if/else. It won't result in callingtrackEvent()twice, simply writing it twice, which seems fine when considering the improved legibility: