Skip to content

Commit

Permalink
Simplify new user site tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
escapemanuele committed Dec 5, 2024
1 parent 6396222 commit b6b8ee3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 44 deletions.
31 changes: 6 additions & 25 deletions client/landing/stepper/hooks/use-record-signup-complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,30 @@ import { useSelect } from '@wordpress/data';
import { useCallback } from 'react';
import { USER_STORE, ONBOARD_STORE } from 'calypso/landing/stepper/stores';
import { SIGNUP_DOMAIN_ORIGIN, recordSignupComplete } from 'calypso/lib/analytics/signup';
import { clearSignupIsNewUser, getSignupIsNewUser } from 'calypso/signup/storageUtils';
import { useSelector } from 'calypso/state';
import isUserRegistrationDaysWithinRange from 'calypso/state/selectors/is-user-registration-days-within-range';
import { getSignupIsNewUserAndClear } from 'calypso/signup/storageUtils';
import { useSite } from './use-site';
import type { UserSelect, OnboardSelect } from '@automattic/data-stores';

export const useRecordSignupComplete = ( flow: string | null ) => {
const site = useSite();
const siteId = site?.ID || null;
const theme = site?.options?.theme_slug || '';
const { username, siteCount, domainCartItem, planCartItem, selectedDomain, signupDomainOrigin } =
useSelect( ( select ) => {
const { username, domainCartItem, planCartItem, selectedDomain, signupDomainOrigin } = useSelect(
( select ) => {
return {
username: ( select( USER_STORE ) as UserSelect ).getCurrentUser()?.username,
siteCount: ( select( USER_STORE ) as UserSelect ).getCurrentUser()?.site_count,
domainCartItem: ( select( ONBOARD_STORE ) as OnboardSelect ).getDomainCartItem(),
planCartItem: ( select( ONBOARD_STORE ) as OnboardSelect ).getPlanCartItem(),
selectedDomain: ( select( ONBOARD_STORE ) as OnboardSelect ).getSelectedDomain(),
signupDomainOrigin: ( select( ONBOARD_STORE ) as OnboardSelect ).getSignupDomainOrigin(),
};
}, [] );

const isNewishUser = useSelector( ( state ) =>
isUserRegistrationDaysWithinRange( state, null, 0, 7 )
},
[]
);

return useCallback(
( signupCompletionState: Record< string, unknown > ) => {
const siteSlug = site?.slug ?? signupCompletionState?.siteSlug;
const isNewUser = getSignupIsNewUser( username );
if ( isNewUser ) {
clearSignupIsNewUser( username );
}

const isNew7DUserSite = !! (
isNewUser ||
( isNewishUser && siteSlug && siteCount && siteCount <= 1 )
);
const isNewUser = getSignupIsNewUserAndClear( username );

// Domain product slugs can be a domain purchases like dotcom_domain or dotblog_domain or a mapping like domain_mapping
// When purchasing free subdomains the product_slugs is empty (since there is no actual produce being purchased)
Expand All @@ -64,7 +50,6 @@ export const useRecordSignupComplete = ( flow: string | null ) => {
siteId: siteId ?? signupCompletionState?.siteId,
isNewUser,
hasCartItems,
isNew7DUserSite,
theme,
intent: flow,
startingPoint: flow,
Expand All @@ -77,20 +62,16 @@ export const useRecordSignupComplete = ( flow: string | null ) => {
hasPaidDomainItem && domainCartItem ? isDomainTransfer( domainCartItem ) : undefined,
signupDomainOrigin: signupDomainOrigin ?? SIGNUP_DOMAIN_ORIGIN.NOT_SET,
framework: 'stepper',
isNewishUser,
},
true
);
},
[
domainCartItem,
flow,
isNewishUser,
planCartItem,
selectedDomain,
signupDomainOrigin,
site?.slug,
siteCount,
siteId,
theme,
username,
Expand Down
8 changes: 1 addition & 7 deletions client/lib/analytics/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export function recordSignupComplete(
hasCartItems,
planProductSlug,
domainProductSlug,
isNew7DUserSite,
theme,
intent,
startingPoint,
Expand All @@ -55,7 +54,6 @@ export function recordSignupComplete(
signupDomainOrigin,
elapsedTimeSinceStart = null,
framework,
isNewishUser,
},
now
) {
Expand All @@ -75,15 +73,13 @@ export function recordSignupComplete(
hasCartItems,
planProductSlug,
domainProductSlug,
isNew7DUserSite,
theme,
intent,
startingPoint,
isTransfer,
isMapping,
signupDomainOrigin,
framework,
isNewishUser,
},
true
);
Expand Down Expand Up @@ -123,16 +119,14 @@ export function recordSignupComplete(
gaRecordEvent( 'Signup', 'calypso_signup_complete:' + flags.join( ',' ) );

// Tracks, Google Analytics
if ( isNew7DUserSite ) {
if ( isNewSite && isNewUser ) {
const device = resolveDeviceTypeByViewPort();

// Tracks
recordTracksEvent( 'calypso_new_user_site_creation', {
flow,
device,
framework,
is_new_user: isNewUser,
is_newish_user: isNewishUser,
} );
// Google Analytics
gaRecordEvent( 'Signup', 'calypso_new_user_site_creation' );
Expand Down
1 change: 0 additions & 1 deletion client/lib/signup/api/account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ export async function createAccount( {
isNewAccountCreated = false;
} else {
const username = response?.signup_sandbox_username || response?.username;

recordNewAccountCreation( {
response,
flowName,
Expand Down
12 changes: 1 addition & 11 deletions client/signup/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import { getCurrentOAuth2Client } from 'calypso/state/oauth2-clients/ui/selector
import getCurrentLocaleSlug from 'calypso/state/selectors/get-current-locale-slug';
import getWccomFrom from 'calypso/state/selectors/get-wccom-from';
import isDomainOnlySite from 'calypso/state/selectors/is-domain-only-site';
import isUserRegistrationDaysWithinRange from 'calypso/state/selectors/is-user-registration-days-within-range';
import { getSignupDependencyStore } from 'calypso/state/signup/dependency-store/selectors';
import { submitSignupStep, removeStep, addStep } from 'calypso/state/signup/progress/actions';
import { getSignupProgress } from 'calypso/state/signup/progress/selectors';
Expand Down Expand Up @@ -525,14 +524,10 @@ class Signup extends Component {
handleFlowComplete = ( dependencies, destination ) => {
debug( 'The flow is completed. Destination: %s', destination );

const { isNewishUser, existingSiteCount } = this.props;
const { existingSiteCount } = this.props;

const isNewUser = !! ( dependencies && dependencies.is_new_account );
const siteId = dependencies && dependencies.siteId;
const isNew7DUserSite = !! (
isNewUser ||
( isNewishUser && dependencies && dependencies.siteSlug && existingSiteCount <= 1 )
);
const hasCartItems = dependenciesContainCartItem( dependencies );
// @TODO: cartItem is now deprecated. Remove this once all steps and flows have been
// updated to use cartItems
Expand All @@ -548,11 +543,9 @@ class Signup extends Component {
: cartItem?.product_slug;

const debugProps = {
isNewishUser,
existingSiteCount,
isNewUser,
hasCartItems,
isNew7DUserSite,
flow: this.props.flowName,
siteId,
theme: selectedDesign?.theme,
Expand Down Expand Up @@ -582,7 +575,6 @@ class Signup extends Component {
undefined !== domainItem && domainItem.is_domain_registration
? domainItem.product_slug
: undefined,
isNew7DUserSite,
// Record the following values so that we can know the user completed which branch under the hero flow
theme: selectedDesign?.theme,
intent,
Expand All @@ -592,7 +584,6 @@ class Signup extends Component {
isTransfer: isTransfer,
signupDomainOrigin: signupDomainOriginValue,
framework: 'start',
isNewishUser,
} );
}
};
Expand Down Expand Up @@ -1008,7 +999,6 @@ export default connect(
signupDependencies,
isLoggedIn: isUserLoggedIn( state ),
isEmailVerified: isCurrentUserEmailVerified( state ),
isNewishUser: isUserRegistrationDaysWithinRange( state, null, 0, 7 ),
existingSiteCount: getCurrentUserSiteCount( state ),
isPaidPlan: isCurrentPlanPaid( state, siteId ),
sitePlanName: getSitePlanName( state, siteId ),
Expand Down
5 changes: 5 additions & 0 deletions client/signup/storageUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,8 @@ export const clearSignupIsNewUser = ( username ) =>
ignoreFatalsForSessionStorage( () =>
sessionStorage?.removeItem( `wpcom_signup_is_new_user_${ username }` )
);
export const getSignupIsNewUserAndClear = ( username ) => {
const value = getSignupIsNewUser( username );
clearSignupIsNewUser( username );
return value;
};

0 comments on commit b6b8ee3

Please sign in to comment.