Skip to content

Commit

Permalink
Add tracks events to Jetpack logged-out checkout. (#53678)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottprogrammer authored Jun 24, 2021
1 parent 125cffc commit e449bef
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 8 deletions.
2 changes: 2 additions & 0 deletions client/my-sites/checkout/checkout-system-decider.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default function CheckoutSystemDecider( {
isJetpackCheckout,
jetpackSiteSlug,
jetpackPurchaseToken,
isUserComingFromLoginForm,
} ) {
const reduxDispatch = useDispatch();
const translate = useTranslate();
Expand Down Expand Up @@ -133,6 +134,7 @@ export default function CheckoutSystemDecider( {
isJetpackCheckout={ isJetpackCheckout }
jetpackSiteSlug={ jetpackSiteSlug }
jetpackPurchaseToken={ jetpackPurchaseToken }
isUserComingFromLoginForm={ isUserComingFromLoginForm }
/>
</StripeHookProvider>
</CalypsoShoppingCartProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import React, { useEffect, useState, useCallback } from 'react';
import { useDispatch as useReduxDispatch } from 'react-redux';
import { useTranslate } from 'i18n-calypso';
import {
Checkout,
Expand Down Expand Up @@ -57,6 +58,7 @@ import {
hasTransferProduct,
} from 'calypso/lib/cart-values/cart-items';
import { addQueryArgs } from 'calypso/lib/route';
import { recordTracksEvent } from 'calypso/state/analytics/actions';
import PaymentMethodStep from './payment-method-step';
import CheckoutHelpLink from './checkout-help-link';
import type { CountryListItem } from '../types/country-list-item';
Expand Down Expand Up @@ -161,6 +163,7 @@ export default function WPCheckout( {
const total = useTotal();
const activePaymentMethod = usePaymentMethod();
const onEvent = useEvents();
const reduxDispatch = useReduxDispatch();

const areThereDomainProductsInCart =
hasDomainRegistration( responseCart ) || hasTransferProduct( responseCart );
Expand Down Expand Up @@ -193,11 +196,32 @@ export default function WPCheckout( {

const loginUrl = login( { redirectTo, emailAddress } );

reduxDispatch(
recordTracksEvent( 'calypso_checkout_wpcom_email_exists', {
email: emailAddress,
checkout_flow: isJetpackCheckout ? 'site_only_checkout' : 'wpcom_registrationless',
} )
);

return translate(
'That email address is already in use. If you have an existing account, {{a}}please log in{{/a}}.',
{
components: {
a: <a href={ loginUrl } />,
a: (
<a
onClick={ () =>
reduxDispatch(
recordTracksEvent( 'calypso_checkout_composite_login_click', {
email: emailAddress,
checkout_flow: isJetpackCheckout
? 'site_only_checkout'
: 'wpcom_registrationless',
} )
)
}
href={ loginUrl }
/>
),
},
}
);
Expand Down
43 changes: 37 additions & 6 deletions client/my-sites/checkout/composite-checkout/composite-checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export default function CompositeCheckout( {
isJetpackCheckout,
jetpackSiteSlug,
jetpackPurchaseToken,
isUserComingFromLoginForm,
}: {
siteSlug: string | undefined;
siteId: number | undefined;
Expand All @@ -137,9 +138,10 @@ export default function CompositeCheckout( {
infoMessage?: JSX.Element;
onAfterPaymentComplete?: () => void;
isFocusedLaunch?: boolean;
isJetpackCheckout?: boolean;
isJetpackCheckout: boolean;
jetpackSiteSlug?: string;
jetpackPurchaseToken?: string;
isUserComingFromLoginForm?: boolean;
} ): JSX.Element {
const translate = useTranslate();
const isJetpackNotAtomic =
Expand Down Expand Up @@ -200,6 +202,18 @@ export default function CompositeCheckout( {
[ reduxDispatch ]
);

const checkoutFlow: string = useMemo( () => {
if ( isLoggedOutCart ) {
if ( isJetpackCheckout ) {
return isUserComingFromLoginForm
? 'jetpack_site_only_coming_from_login'
: 'jetpack_site_only';
}
return 'wpcom_registrationless';
}
return isJetpackNotAtomic ? 'jetpack_checkout' : 'wpcom_checkout';
}, [ isLoggedOutCart, isJetpackCheckout, isUserComingFromLoginForm, isJetpackNotAtomic ] );

const countriesList = useCountryList( overrideCountryList || [] );

const {
Expand Down Expand Up @@ -408,7 +422,9 @@ export default function CompositeCheckout( {
productAliasFromUrl,
updatedSiteSlug,
feature,
plan
plan,
isJetpackCheckout,
checkoutFlow
);

const products = useSelector( ( state ) => getProductsList( state ) );
Expand Down Expand Up @@ -560,6 +576,7 @@ export default function CompositeCheckout( {
responseCart,
storedCards,
productAliasFromUrl,
checkoutFlow,
} );

const onPaymentComplete = useCreatePaymentCompleteCallback( {
Expand All @@ -573,6 +590,7 @@ export default function CompositeCheckout( {
isFocusedLaunch,
siteSlug: updatedSiteSlug,
isJetpackCheckout,
checkoutFlow,
} );

const handlePaymentComplete = useCallback(
Expand Down Expand Up @@ -678,11 +696,22 @@ function getAnalyticsPath(
product: string | undefined,
selectedSiteSlug: string | undefined,
selectedFeature: string | undefined,
plan: string | undefined
plan: string | undefined,
isJetpackCheckout: boolean,
checkoutFlow: string
): { analyticsPath: string; analyticsProps: Record< string, string > } {
debug( 'getAnalyticsPath', { purchaseId, product, selectedSiteSlug, selectedFeature, plan } );
debug( 'getAnalyticsPath', {
purchaseId,
product,
selectedSiteSlug,
selectedFeature,
plan,
isJetpackCheckout,
checkoutFlow,
} );
let analyticsPath = '';
let analyticsProps = {};

if ( purchaseId && product ) {
analyticsPath = '/checkout/:product/renew/:purchase_id/:site';
analyticsProps = { product, purchase_id: purchaseId, site: selectedSiteSlug };
Expand All @@ -693,8 +722,10 @@ function getAnalyticsPath(
analyticsPath = '/checkout/features/:feature/:site';
analyticsProps = { feature: selectedFeature, site: selectedSiteSlug };
} else if ( product && ! purchaseId ) {
analyticsPath = '/checkout/:site/:product';
analyticsProps = { product, site: selectedSiteSlug };
analyticsPath = isJetpackCheckout
? '/checkout/jetpack/:site/:product'
: '/checkout/:site/:product';
analyticsProps = { product, site: selectedSiteSlug, checkoutFlow };
} else if ( selectedSiteSlug ) {
analyticsPath = '/checkout/:site';
analyticsProps = { site: selectedSiteSlug };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default function useCreatePaymentCompleteCallback( {
isFocusedLaunch,
siteSlug,
isJetpackCheckout = false,
checkoutFlow,
}: {
createUserAndSiteBeforeTransaction?: boolean;
productAliasFromUrl?: string | undefined;
Expand All @@ -71,7 +72,8 @@ export default function useCreatePaymentCompleteCallback( {
isComingFromUpsell?: boolean;
isFocusedLaunch?: boolean;
siteSlug: string | undefined;
isJetpackCheckout?: boolean;
isJetpackCheckout: boolean;
checkoutFlow: string;
} ): PaymentCompleteCallback {
const { responseCart } = useShoppingCart();
const reduxDispatch = useDispatch();
Expand Down Expand Up @@ -119,6 +121,7 @@ export default function useCreatePaymentCompleteCallback( {
transactionResult,
redirectUrl: url,
responseCart,
checkoutFlow,
reduxDispatch,
} );
} catch ( err ) {
Expand Down Expand Up @@ -232,6 +235,7 @@ export default function useCreatePaymentCompleteCallback( {
createUserAndSiteBeforeTransaction,
isFocusedLaunch,
isJetpackCheckout,
checkoutFlow,
]
);
}
Expand Down Expand Up @@ -314,12 +318,14 @@ function recordPaymentCompleteAnalytics( {
transactionResult,
redirectUrl,
responseCart,
checkoutFlow,
reduxDispatch,
}: {
paymentMethodId: string | null;
transactionResult: WPCOMTransactionEndpointResponse | undefined;
redirectUrl: string;
responseCart: ResponseCart;
checkoutFlow: string;
reduxDispatch: ReturnType< typeof useDispatch >;
} ) {
const wpcomPaymentMethod = paymentMethodId
Expand Down Expand Up @@ -356,6 +362,7 @@ function recordPaymentCompleteAnalytics( {
currency: responseCart.currency,
payment_method: wpcomPaymentMethod || '',
device,
checkout_flow: checkoutFlow,
} )
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ export default function useRecordCheckoutLoaded( {
responseCart,
storedCards,
productAliasFromUrl,
checkoutFlow,
}: {
recordEvent: ( action: ReactStandardAction ) => void;
isLoading: boolean;
isApplePayAvailable: boolean;
responseCart: ResponseCart;
storedCards: StoredCard[];
productAliasFromUrl: string | undefined | null;
checkoutFlow: string;
} ): void {
const hasRecordedCheckoutLoad = useRef( false );
if ( ! isLoading && ! hasRecordedCheckoutLoad.current ) {
Expand All @@ -39,6 +41,7 @@ export default function useRecordCheckoutLoaded( {
apple_pay_available: isApplePayAvailable,
product_slug: productAliasFromUrl,
is_renewal: hasRenewalItem( responseCart ),
checkout_flow: checkoutFlow,
},
} );
hasRecordedCheckoutLoad.current = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function createAnalyticsEventHandler( reduxDispatch ) {
apple_pay_available: action.payload?.apple_pay_available,
product_slug: action.payload?.product_slug,
is_composite: true,
checkout_flow: action.payload?.checkout_flow,
} )
);
return reduxDispatch( recordTracksEvent( 'calypso_checkout_composite_loaded', {} ) );
Expand Down
1 change: 1 addition & 0 deletions client/my-sites/checkout/controller.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export function checkout( context, next ) {
isJetpackCheckout={ isJetpackCheckout }
jetpackSiteSlug={ jetpackSiteSlug }
jetpackPurchaseToken={ jetpackPurchaseToken || jetpackPurchaseNonce }
isUserComingFromLoginForm={ isUserComingFromLoginForm }
/>
);

Expand Down

0 comments on commit e449bef

Please sign in to comment.