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

Stepper: Apply extended props to calypso_page_view #94229

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/landing/stepper/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const STEPPER_TRACKS_EVENT_STEP_NAV_EXIT_FLOW = 'calypso_signup_step_nav_
export const STEPPER_TRACKS_EVENT_SIGNUP_START = 'calypso_signup_start';
export const STEPPER_TRACKS_EVENT_SIGNUP_STEP_START = 'calypso_signup_step_start';
export const STEPPER_TRACKS_EVENT_FLOW_START = 'calypso_stepper_flow_start';
export const STEPPER_TRACKS_EVENT_PAGE_VIEW = 'calypso_page_view';

export const STEPPER_TRACKS_EVENTS_STEP_NAV = < const >[
STEPPER_TRACKS_EVENT_STEP_NAV_SUBMIT,
Expand All @@ -42,4 +43,5 @@ export const STEPPER_TRACKS_EVENTS = < const >[
STEPPER_TRACKS_EVENT_SIGNUP_START,
STEPPER_TRACKS_EVENT_SIGNUP_STEP_START,
STEPPER_TRACKS_EVENT_FLOW_START,
STEPPER_TRACKS_EVENT_PAGE_VIEW,
];
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { isAnyHostingFlow } from '@automattic/onboarding';
import { resolveDeviceTypeByViewPort } from '@automattic/viewport';
import { useCallback } from '@wordpress/element';
import { useEffect } from 'react';
import { STEPPER_TRACKS_EVENT_SIGNUP_STEP_START } from 'calypso/landing/stepper/constants';
import {
STEPPER_TRACKS_EVENT_PAGE_VIEW,
STEPPER_TRACKS_EVENT_SIGNUP_STEP_START,
} from 'calypso/landing/stepper/constants';
import { getStepOldSlug } from 'calypso/landing/stepper/declarative-flow/helpers/get-step-old-slug';
import { getAssemblerSource } from 'calypso/landing/stepper/declarative-flow/internals/analytics/record-design';
import { useIntent } from 'calypso/landing/stepper/hooks/use-intent';
Expand Down Expand Up @@ -45,11 +48,9 @@ export const useStepRouteTracking = ( { flow, stepSlug, skipTracking }: Props )
const { site, siteSlugOrId } = useSiteData();
const isRequestingSelectedSite = useIsRequestingSelectedSite( siteSlugOrId, site );
const hasRequestedSelectedSite = siteSlugOrId ? !! site && ! isRequestingSelectedSite : true;
const signupStepStartProps = useSnakeCasedKeys( {
input: flow.useTracksEventProps?.()?.[ STEPPER_TRACKS_EVENT_SIGNUP_STEP_START ],
} );
const eventPropsFromFlow = useSnakeCasedKeys( { input: flow.useTracksEventProps?.() } );

const recordStepStart = useCallback(
const handleRecordStepStart = useCallback(
( step: string ) => {
recordTracksEvent( STEPPER_TRACKS_EVENT_SIGNUP_STEP_START, {
flow: flow.name,
Expand All @@ -59,16 +60,27 @@ export const useStepRouteTracking = ( { flow, stepSlug, skipTracking }: Props )
is_in_hosting_flow: isAnyHostingFlow( flow.name ),
...( design && { assembler_source: getAssemblerSource( design ) } ),
...( flow.variantSlug && { flow_variant: flow.variantSlug } ),
...signupStepStartProps,
...( eventPropsFromFlow?.[ STEPPER_TRACKS_EVENT_SIGNUP_STEP_START ] ?? {} ),
} );
},

// We leave out intent and design from the dependency list, due to the ONBOARD_STORE being reset in the exit flow.
// The store reset causes these values to become empty, and may trigger this event again.
// eslint-disable-next-line react-hooks/exhaustive-deps
[ flow.name, flow.variantSlug, signupStepStartProps ]
[ flow.name, flow.variantSlug, eventPropsFromFlow ]
);

const handleRecordPageView = useCallback( () => {
const pathname = window.location.pathname;
const pageTitle = `Setup > ${ flow.name } > ${ stepSlug }`;

recordPageView(
pathname,
pageTitle,
eventPropsFromFlow?.[ STEPPER_TRACKS_EVENT_PAGE_VIEW ] ?? {}
);
}, [ flow.name, stepSlug, eventPropsFromFlow ] );

useEffect( () => {
// We record the event only when the step is not empty. Additionally, we should not fire this event whenever the intent is changed
if ( ! hasRequestedSelectedSite || skipTracking ) {
Expand All @@ -82,17 +94,22 @@ export const useStepRouteTracking = ( { flow, stepSlug, skipTracking }: Props )
signupCompleteFlowName === flow.name && signupCompleteStepName === stepSlug;

if ( ! isReEnteringStep ) {
recordStepStart( stepSlug );
handleRecordStepStart( stepSlug );

const stepOldSlug = getStepOldSlug( stepSlug );
if ( stepOldSlug ) {
recordStepStart( stepOldSlug );
handleRecordStepStart( stepOldSlug );
}
}

// Also record page view for data and analytics
const pathname = window.location.pathname;
const pageTitle = `Setup > ${ flow.name } > ${ stepSlug }`;
recordPageView( pathname, pageTitle );
}, [ flow.name, hasRequestedSelectedSite, stepSlug, skipTracking, recordStepStart ] );
handleRecordPageView();
}, [
flow.name,
hasRequestedSelectedSite,
stepSlug,
skipTracking,
handleRecordStepStart,
handleRecordPageView,
] );
};
Loading