Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import Snackbars from '../../snackbars';
import { InterimOmnibar } from '../interim-omnibar';
import type { Site, User } from '@automattic/api-core';

jest.mock( 'calypso/lib/explat', () => ( {
useExperiment: () => [ false, { variationName: 'ungated_site_launch' } ],
// Site launch gating: the ungated variant is unreachable in production while
// useSiteLaunchGatingVariant() hardcodes the semi-gated default, but its code
// path is kept as scaffolding for future experiments, so we mock the hook to
// keep it tested.
jest.mock( 'calypso/lib/explat/site-launch-gating', () => ( {
useSiteLaunchGatingVariant: () => [ false, 'ungated_site_launch' ],
} ) );

jest.mock( 'calypso/lib/analytics/tracks', () => ( {
Expand Down
10 changes: 5 additions & 5 deletions client/dashboard/sites/site-launch-button/use-site-launch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useQuery, useMutation } from '@tanstack/react-query';
import { __ } from '@wordpress/i18n';
import { addQueryArgs } from '@wordpress/url';
import { useMemo, useState, type ComponentType, type ReactElement } from 'react';
import { useExperiment } from 'calypso/lib/explat';
import { useSiteLaunchGatingVariant } from 'calypso/lib/explat/site-launch-gating';
import { getCurrentDashboard } from '../../app/routing';
import { dashboardLinkWithBackport, redirectToDashboardLink, wpcomLink } from '../../utils/link';
import {
Expand Down Expand Up @@ -44,8 +44,6 @@ export interface UseSiteLaunchResult {
modal: ReactElement | null;
}

const EXPERIMENT_NAME = 'calypso_standardized_site_launch_gating_202603_v1';

export function useSiteLaunch(
site: Site,
{
Expand Down Expand Up @@ -75,8 +73,7 @@ export function useSiteLaunch(
} );

const [ isModalOpen, setIsModalOpen ] = useState( false );
const [ isExperimentLoading, experiment ] = useExperiment( EXPERIMENT_NAME );
const variant = experiment?.variationName;
const [ isExperimentLoading, variant ] = useSiteLaunchGatingVariant();

const isSitePlanHostingTrial = site.plan?.product_slug === DotcomPlans.HOSTING_TRIAL_MONTHLY;
const isSitePlanPaidWithDomains = isSitePlanPaid( site ) && domains.length > 1;
Expand Down Expand Up @@ -179,6 +176,9 @@ export function useSiteLaunch(
return { ...baseResult, isHidden: true, onClick: () => {} };
}

// Site launch gating: 'semi_gated_site_launch' is the shipped default.
// The other branches are scaffolding for future experiments; see
// useSiteLaunchGatingVariant().
if ( variant === 'semi_gated_site_launch' ) {
return {
...baseResult,
Expand Down
10 changes: 5 additions & 5 deletions client/hosting/performance/site-performance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
useDeviceTab,
} from 'calypso/hosting/performance/contexts/device-tab-context';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { useExperiment } from 'calypso/lib/explat';
import { useSiteLaunchGatingVariant } from 'calypso/lib/explat/site-launch-gating';
import { TabType } from 'calypso/performance-profiler/components/header';
import { profilerVersion } from 'calypso/performance-profiler/utils/profiler-version';
import { trackReportCompletedEvent } from 'calypso/performance-profiler/utils/track-report-events';
Expand Down Expand Up @@ -157,10 +157,7 @@ const SitePerformanceContent = ( { path }: { path?: string } ) => {
select: ( data ) => data.filter( ( domain ) => domain.blog_id === site?.ID ),
} );

const [ isExperimentLoading, experimentData ] = useExperiment(
'calypso_standardized_site_launch_gating_202603_v1'
);
const experimentVariant = experimentData?.variationName;
const [ isExperimentLoading, experimentVariant ] = useSiteLaunchGatingVariant();
const retestPage = () => {
recordTracksEvent( 'calypso_performance_profiler_test_again_click' );
performance.mark( 'test-started' );
Expand Down Expand Up @@ -191,6 +188,9 @@ const SitePerformanceContent = ( { path }: { path?: string } ) => {
path,
} );

// Site launch gating: 'semi_gated_site_launch' is the shipped default.
// The other branches are scaffolding for future experiments; see
// useSiteLaunchGatingVariant().
if ( experimentVariant === 'semi_gated_site_launch' ) {
window.location.assign(
addQueryArgs( '/start/launch-site', {
Expand Down
11 changes: 7 additions & 4 deletions client/layout/masterbar/masterbar-launch-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button } from '@wordpress/components';
import { addQueryArgs } from '@wordpress/url';
import clsx from 'clsx';
import { useTranslate } from 'i18n-calypso';
import { useExperiment } from 'calypso/lib/explat';
import { useSiteLaunchGatingVariant } from 'calypso/lib/explat/site-launch-gating';
import { useCelebrateLaunchModalSideEffects } from 'calypso/my-sites/customer-home/celebrate-site-launch-modal/use-side-effects';
import { useDispatch, useSelector } from 'calypso/state';
import { recordTracksEvent } from 'calypso/state/analytics/actions';
Expand All @@ -22,12 +22,15 @@ export const MasterbarLaunchButton = ( { siteId }: { siteId: number } ) => {

const { onSiteLaunched } = useCelebrateLaunchModalSideEffects( siteId );

const [ isLoading, data ] = useExperiment( 'calypso_standardized_site_launch_gating_202603_v1' );
const [ isLoading, variant ] = useSiteLaunchGatingVariant();

const onLaunchSiteClick = () => {
dispatch( recordTracksEvent( 'calypso_masterbar_launch_site', { source: sectionName } ) );

if ( data?.variationName === 'semi_gated_site_launch' ) {
// Site launch gating: 'semi_gated_site_launch' is the shipped default.
// The other branches are scaffolding for future experiments; see
// useSiteLaunchGatingVariant().
if ( variant === 'semi_gated_site_launch' ) {
window.location.assign(
addQueryArgs( '/start/launch-site', {
siteSlug: site?.slug,
Expand All @@ -37,7 +40,7 @@ export const MasterbarLaunchButton = ( { siteId }: { siteId: number } ) => {
return;
}

if ( data?.variationName === 'ungated_site_launch' ) {
if ( variant === 'ungated_site_launch' ) {
launchSiteMutation.mutate( undefined, {
onSuccess: () => onSiteLaunched( !! site?.is_wpcom_atomic ),
} );
Expand Down
26 changes: 26 additions & 0 deletions client/lib/explat/site-launch-gating.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Site launch gating variant.
*
* The calypso_standardized_site_launch_gating_202603_v1 experiment concluded with
* "semi_gated_site_launch" shipping as the default behavior for everyone. The
* variant branches at the call sites of this hook are kept as scaffolding for the
* expected follow-up experiment; they are unreachable while this hook returns a
* hardcoded variant.
*
* To run the next experiment:
* 1. Add any new variant name(s) to the SiteLaunchGatingVariant union.
* 2. Replace the hardcoded return value below with a useExperiment() call for the
* new experiment name, e.g.:
*
* const [ isLoading, experiment ] = useExperiment( 'new_experiment_name' );
* return [ isLoading, ( experiment?.variationName ?? null ) as SiteLaunchGatingVariant ];
*
* 3. Adjust the variant branches at the call sites of this hook as needed; `null`
* (control) should keep the default semi-gated behavior.
*/
export type SiteLaunchGatingVariant = 'semi_gated_site_launch' | 'ungated_site_launch' | null;

export function useSiteLaunchGatingVariant(): [ boolean, SiteLaunchGatingVariant ] {
// [ isLoading, variant ]
return [ false, 'semi_gated_site_launch' ];
}
24 changes: 12 additions & 12 deletions client/my-sites/customer-home/cards/launchpad/pre-launch.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useExperiment } from 'calypso/lib/explat';
import { useSiteLaunchGatingVariant } from 'calypso/lib/explat/site-launch-gating';
import { useCelebrateLaunchModalSideEffects } from 'calypso/my-sites/customer-home/celebrate-site-launch-modal/use-side-effects';
import { useSelector } from 'calypso/state';
import { getSite } from 'calypso/state/sites/selectors';
Expand All @@ -18,26 +18,26 @@ const LaunchpadPreLaunch = ( props: LaunchpadPreLaunchProps ): JSX.Element => {

const { onSiteLaunched } = useCelebrateLaunchModalSideEffects( siteId );

const [ , experimentData ] = useExperiment( 'calypso_standardized_site_launch_gating_202603_v1' );
const experimentAssignment = experimentData?.variationName;
const [ , variant ] = useSiteLaunchGatingVariant();

const handleTaskClick = ( task: Task ) => {
// No experiment assignment (i.e., control) or not the site launch task
if ( task.id !== 'site_launched' || ! experimentAssignment ) {
// No variant (i.e., control) or not the site launch task
if ( task.id !== 'site_launched' || ! variant ) {
return;
}

// Ungated site launch. When the action is completed, handleSiteLaunched will be called.
if ( experimentAssignment === 'ungated_site_launch' ) {
return;
}

if ( experimentAssignment === 'semi_gated_site_launch' ) {
// Site launch gating: 'semi_gated_site_launch' is the shipped default.
// The other branches are scaffolding for future experiments; see
// useSiteLaunchGatingVariant().
if ( variant === 'semi_gated_site_launch' ) {
window.location.assign( `/start/launch-site?siteSlug=${ site?.slug }` );
return false;
}

throw new Error( 'Invalid experiment assignment' );
// Ungated site launch. When the action is completed, handleSiteLaunched will be called.
if ( variant === 'ungated_site_launch' ) {
return;
}
};

return (
Expand Down
Loading