| import { resolveDeviceTypeByViewPort } from '@automattic/viewport'; |
| import debug from 'debug'; |
| import { |
| adTrackSignupStart, |
| adTrackSignupComplete, |
| adTrackRegistration, |
| } from 'calypso/lib/analytics/ad-tracking'; |
| import { gaRecordEvent } from 'calypso/lib/analytics/ga'; |
| import { identifyUser } from 'calypso/lib/analytics/identify-user'; |
| import { addToQueue } from 'calypso/lib/analytics/queue'; |
| import { recordTracksEvent } from 'calypso/lib/analytics/tracks'; |
| import { setSignupStartTime, getSignupCompleteElapsedTime } from 'calypso/signup/storageUtils'; |
|
|
| const signupDebug = debug( 'calypso:analytics:signup' ); |
|
|
| export function recordSignupStart( flow, ref, optionalProps ) { |
| setSignupStartTime(); |
|
|
| |
| recordTracksEvent( 'calypso_signup_start', { |
| flow, |
| ref, |
| ...optionalProps, |
| } ); |
| |
| gaRecordEvent( 'Signup', 'calypso_signup_start' ); |
| |
| adTrackSignupStart( flow ); |
| } |
|
|
| |
| export const SIGNUP_DOMAIN_ORIGIN = { |
| USE_YOUR_DOMAIN: 'use-your-domain', |
| CHOOSE_LATER: 'choose-later', |
| FREE: 'free', |
| CUSTOM: 'custom', |
| NOT_SET: 'not-set', |
| }; |
|
|
| export function recordSignupComplete( |
| { |
| flow, |
| siteId, |
| isNewUser, |
| isBlankCanvas, |
| hasCartItems, |
| planProductSlug, |
| domainProductSlug, |
| theme, |
| intent, |
| startingPoint, |
| isTransfer, |
| isMapping, |
| signupDomainOrigin, |
| elapsedTimeSinceStart = null, |
| framework, |
| goals, |
| }, |
| now |
| ) { |
| const isNewSite = !! siteId; |
|
|
| if ( ! now ) { |
| |
| return addToQueue( |
| 'signup', |
| 'recordSignupComplete', |
| { |
| elapsedTimeSinceStart: elapsedTimeSinceStart ?? getSignupCompleteElapsedTime(), |
| flow, |
| siteId, |
| isNewUser, |
| isBlankCanvas, |
| hasCartItems, |
| planProductSlug, |
| domainProductSlug, |
| theme, |
| intent, |
| startingPoint, |
| isTransfer, |
| isMapping, |
| signupDomainOrigin, |
| framework, |
| goals, |
| }, |
| true |
| ); |
| } |
|
|
| |
| |
| |
| |
| recordTracksEvent( 'calypso_signup_complete', { |
| elapsed_time_since_start: elapsedTimeSinceStart ?? getSignupCompleteElapsedTime(), |
| flow, |
| blog_id: siteId, |
| is_new_user: isNewUser, |
| is_new_site: isNewSite, |
| is_blank_canvas: isBlankCanvas, |
| has_cart_items: hasCartItems, |
| plan_product_slug: planProductSlug, |
| domain_product_slug: domainProductSlug, |
| theme, |
| intent, |
| starting_point: startingPoint, |
| is_transfer: isTransfer, |
| is_mapping: isMapping, |
| signup_domain_origin: signupDomainOrigin, |
| framework, |
| goals, |
| } ); |
|
|
| |
| const flags = [ |
| isNewUser && 'is_new_user', |
| isNewSite && 'is_new_site', |
| hasCartItems && 'has_cart_items', |
| ].filter( Boolean ); |
|
|
| |
| gaRecordEvent( 'Signup', 'calypso_signup_complete:' + flags.join( ',' ) ); |
|
|
| |
| if ( isNewSite && isNewUser ) { |
| const device = resolveDeviceTypeByViewPort(); |
|
|
| |
| recordTracksEvent( 'calypso_new_user_site_creation', { |
| flow, |
| device, |
| framework, |
| } ); |
| |
| gaRecordEvent( 'Signup', 'calypso_new_user_site_creation' ); |
| } |
|
|
| |
| adTrackSignupComplete( { isNewUserSite: isNewUser && isNewSite } ); |
| } |
|
|
| export function recordSignupStep( flow, step, optionalProps ) { |
| const device = resolveDeviceTypeByViewPort(); |
| const props = { |
| flow, |
| step, |
| device, |
| ...optionalProps, |
| }; |
|
|
| signupDebug( 'recordSignupStep:', props ); |
|
|
| |
| recordTracksEvent( 'calypso_signup_step_start', props ); |
| } |
|
|
| export function recordSignupInvalidStep( flow, step ) { |
| recordTracksEvent( 'calypso_signup_goto_invalid_step', { flow, step } ); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function recordRegistration( { userData, flow, type } ) { |
| const device = resolveDeviceTypeByViewPort(); |
|
|
| signupDebug( 'recordRegistration:', { userData, flow, type } ); |
|
|
| |
| identifyUser( userData ); |
| |
| recordTracksEvent( 'calypso_user_registration_complete', { flow, type, device } ); |
| |
| gaRecordEvent( 'Signup', 'calypso_user_registration_complete' ); |
| |
| adTrackRegistration(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export function recordSignupProcessingScreen( flow, previousStep, optionalProps ) { |
| const device = resolveDeviceTypeByViewPort(); |
| recordTracksEvent( 'calypso_signup_processing_screen_show', { |
| flow, |
| previous_step: previousStep, |
| device, |
| ...optionalProps, |
| } ); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export const recordSignupPlanChange = ( |
| flow, |
| step, |
| previousPlanName, |
| previousPlanSlug, |
| currentPlanName, |
| currentPlanSlug |
| ) => { |
| const device = resolveDeviceTypeByViewPort(); |
|
|
| recordTracksEvent( 'calypso_signup_plan_change', { |
| flow, |
| step, |
| device, |
| previous_plan_name: previousPlanName, |
| previous_plan_slug: previousPlanSlug, |
| current_plan_name: currentPlanName, |
| current_plan_slug: currentPlanSlug, |
| } ); |
| }; |
|
|