Skip to content

Commit

Permalink
Add currency to pricing page and checkout page view tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeyGuyDylan committed Dec 20, 2024
1 parent 1a5a369 commit a1fe6d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function useRecordCheckoutLoaded( {
} ): void {
const reduxDispatch = useDispatch();
const hasRecordedCheckoutLoad = useRef( false );
const { currency } = responseCart;
if ( ! isLoading && ! hasRecordedCheckoutLoad.current ) {
debug( 'composite checkout has loaded' );
reduxDispatch(
Expand All @@ -35,6 +36,7 @@ export default function useRecordCheckoutLoaded( {
product_slug: productAliasFromUrl,
is_composite: true,
checkout_flow: checkoutFlow,
currency,
} )
);
reduxDispatch( recordTracksEvent( 'calypso_checkout_composite_loaded', {} ) );
Expand Down
33 changes: 22 additions & 11 deletions client/my-sites/plans/jetpack-plans/selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import CalypsoShoppingCartProvider from 'calypso/my-sites/checkout/calypso-shopp
import { EXTERNAL_PRODUCTS_LIST } from 'calypso/my-sites/plans/jetpack-plans/constants';
import { useDispatch, useSelector } from 'calypso/state';
import { recordTracksEvent } from 'calypso/state/analytics/actions/record';
import { getCurrentUserCurrencyCode } from 'calypso/state/currency-code/selectors';
import { showMasterbar } from 'calypso/state/ui/actions';
import { getSelectedSiteId, getSelectedSiteSlug } from 'calypso/state/ui/selectors';
import { getPurchaseURLCallback } from './get-purchase-url-callback';
Expand Down Expand Up @@ -49,24 +50,34 @@ const SelectorPage: React.FC< SelectorPageProps > = ( {

const siteId = useSelector( getSelectedSiteId );
const siteSlugState = useSelector( getSelectedSiteSlug ) || '';
const { unlinked, purchasetoken, purchaseNonce, site, currency: currencyCodeQp } = urlQueryArgs;
const siteSlug = siteSlugProp || siteSlugState;
const [ currentDuration, setDuration ] = useState< Duration >( defaultDuration );
const [ hasRecordedPageView, setHasRecordedPageView ] = useState( false );
const viewTrackerPath = getViewTrackerPath( rootUrl, siteSlugProp );
const viewTrackerProps = siteId ? { site: siteSlug } : {};
const legacyPlan = planRecommendation ? planRecommendation[ 0 ] : null;

const [ , experimentAssignment ] = useExperiment( 'calypso_jetpack_upsell_page_2022_06' );
const showUpsellPage = experimentAssignment?.variationName === 'treatment';

let currencyCode = useSelector( getCurrentUserCurrencyCode );
if ( currencyCodeQp ) {
currencyCode = currencyCodeQp;
}

useEffect( () => {
dispatch(
recordTracksEvent( 'calypso_jetpack_pricing_page_visit', {
site: siteSlug,
path: viewTrackerPath,
root_path: rootUrl,
} )
);
}, [ dispatch, rootUrl, siteSlug, viewTrackerPath ] );
if ( currencyCode && ! hasRecordedPageView ) {
setHasRecordedPageView( true );
dispatch(
recordTracksEvent( 'calypso_jetpack_pricing_page_visit', {
site: siteSlug,
path: viewTrackerPath,
root_path: rootUrl,
currency: currencyCode,
} )
);
}
}, [ dispatch, rootUrl, siteSlug, viewTrackerPath, currencyCode, hasRecordedPageView ] );

useEffect( () => {
if ( legacyPlan ) {
Expand All @@ -81,7 +92,6 @@ const SelectorPage: React.FC< SelectorPageProps > = ( {
}
}, [ legacyPlan, dispatch, rootUrl, siteSlug, viewTrackerPath ] );

const { unlinked, purchasetoken, purchaseNonce, site, currency: currencyCode } = urlQueryArgs;
const canDoSiteOnlyCheckout = unlinked && !! site && !! ( purchasetoken || purchaseNonce );
useEffect( () => {
if ( canDoSiteOnlyCheckout ) {
Expand All @@ -90,10 +100,11 @@ const SelectorPage: React.FC< SelectorPageProps > = ( {
site: siteSlug,
path: viewTrackerPath,
root_path: rootUrl,
currency: currencyCode,
} )
);
}
}, [ canDoSiteOnlyCheckout, dispatch, rootUrl, siteSlug, viewTrackerPath ] );
}, [ canDoSiteOnlyCheckout, dispatch, rootUrl, siteSlug, viewTrackerPath, currencyCode ] );

useEffect( () => {
setDuration( defaultDuration );
Expand Down

0 comments on commit a1fe6d0

Please sign in to comment.