Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BBE: Experiment for BBE goal copy #68782

Merged
merged 9 commits into from
Oct 19, 2022
Merged
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
@@ -1,16 +1,39 @@
import { Onboard } from '@automattic/data-stores';
import { useIsEnglishLocale } from '@automattic/i18n-utils';
import { useTranslate } from 'i18n-calypso';
import { useExperiment } from 'calypso/lib/explat';
import type { Goal } from './types';

export const CALYPSO_BUILTBYEXPRESS_GOAL_TEXT_EXPERIMENT_NAME =
'calypso_builtbyexpress_goal_copy_change_202210';
export const VARIATION_CONTROL = 'control';
export const VARIATION_BUY = 'variation_buy';
export const VARIATION_GET = 'variation_get';

const SiteGoal = Onboard.SiteGoal;
const HIDE_GOALS = [ SiteGoal.DIFM, SiteGoal.Import ];

const shouldDisplayGoal = ( { key }: Goal ) => ! HIDE_GOALS.includes( key );

export const useGoals = ( displayAllGoals = false ): Goal[] => {
const translate = useTranslate();
const isEnglishLocale = useIsEnglishLocale();
const [ , experimentAssignment ] = useExperiment(
CALYPSO_BUILTBYEXPRESS_GOAL_TEXT_EXPERIMENT_NAME
);
const variationName = experimentAssignment?.variationName;

let builtByExpressGoalDisplayText;
switch ( variationName ) {
case VARIATION_BUY:
builtByExpressGoalDisplayText = translate( 'Buy a website' );
break;
case VARIATION_GET:
builtByExpressGoalDisplayText = translate( 'Get a website quickly' );
break;
case VARIATION_CONTROL:
default:
builtByExpressGoalDisplayText = translate( 'Hire a professional to design my website' );
}

const goals = [
{
Expand All @@ -27,7 +50,7 @@ export const useGoals = ( displayAllGoals = false ): Goal[] => {
},
{
key: SiteGoal.DIFM,
title: translate( 'Hire a professional to design my website' ),
title: builtByExpressGoalDisplayText,
isPremium: true,
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Button } from '@automattic/components';
import { Onboard } from '@automattic/data-stores';
import styled from '@emotion/styled';
import { useTranslate } from 'i18n-calypso';
import { useExperiment } from 'calypso/lib/explat';
import DIFMLink from './difm-link';
import { useGoals } from './goals';
import { CALYPSO_BUILTBYEXPRESS_GOAL_TEXT_EXPERIMENT_NAME, useGoals } from './goals';
import ImportLink from './import-link';
import SelectCard from './select-card';

Expand All @@ -13,6 +15,26 @@ type SelectGoalsProps = {
selectedGoals: Onboard.SiteGoal[];
};

const Placeholder = styled.div`
padding: 0 60px;
animation: loading-fade 800ms ease-in-out infinite;
background-color: var( --color-neutral-10 );
color: transparent;
min-height: 20px;
width: 100%;
@keyframes loading-fade {
0% {
opacity: 0.5;
}
50% {
opacity: 1;
}
100% {
opacity: 0.5;
}
}
`;

const SiteGoal = Onboard.SiteGoal;

export const SelectGoals = ( {
Expand All @@ -23,6 +45,9 @@ export const SelectGoals = ( {
}: SelectGoalsProps ) => {
const translate = useTranslate();
const goalOptions = useGoals( displayAllGoals );
const [ isBuiltByExpressExperimentLoading ] = useExperiment(
CALYPSO_BUILTBYEXPRESS_GOAL_TEXT_EXPERIMENT_NAME
);

const addGoal = ( goal: Onboard.SiteGoal ) => {
const goalSet = new Set( selectedGoals );
Expand Down Expand Up @@ -54,27 +79,39 @@ export const SelectGoals = ( {
const selectedGoalsWithDIFM = addGoal( SiteGoal.DIFM );
onSubmit( selectedGoalsWithDIFM );
};

const hasBuiltByExpressGoal = goalOptions.some( ( g ) => g.key === SiteGoal.DIFM );
return (
<>
{ displayAllGoals && (
<div className="select-goals__cards-hint">{ translate( 'Select all that apply' ) }</div>
) }

<div className="select-goals__cards-container">
{ goalOptions.map( ( { key, title, isPremium } ) => (
<SelectCard
key={ key }
onChange={ handleChange }
selected={ selectedGoals.includes( key ) }
value={ key }
>
<span className="select-goals__goal-title">{ title }</span>
{ isPremium && (
<span className="select-goals__premium-badge">{ translate( 'Premium' ) }</span>
) }
</SelectCard>
) ) }
{ /* We only need to show the goal loader only if the BBE goal will be displayed */ }
{ hasBuiltByExpressGoal && isBuiltByExpressExperimentLoading
? goalOptions.map( ( { key } ) => (
<div
className="select-card__container"
role="progressbar"
key={ `goal-${ key }-placeholder` }
style={ { cursor: 'default' } }
>
<Placeholder />
</div>
) )
: goalOptions.map( ( { key, title, isPremium } ) => (
<SelectCard
key={ key }
onChange={ handleChange }
selected={ selectedGoals.includes( key ) }
value={ key }
>
<span className="select-goals__goal-title">{ title }</span>
{ isPremium && (
<span className="select-goals__premium-badge">{ translate( 'Premium' ) }</span>
) }
</SelectCard>
) ) }
</div>

<div className="select-goals__actions-container">
Expand Down
7 changes: 7 additions & 0 deletions client/lib/signup/step-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { mapRecordKeysRecursively, camelToSnakeCase } from '@automattic/js-utils
import { setupSiteAfterCreation, isTailoredSignupFlow } from '@automattic/onboarding';
import debugFactory from 'debug';
import { defer, difference, get, includes, isEmpty, pick, startsWith } from 'lodash';
import { CALYPSO_BUILTBYEXPRESS_GOAL_TEXT_EXPERIMENT_NAME } from 'calypso/landing/stepper/declarative-flow/internals/steps-repository/goals/goals';
import { recordRegistration } from 'calypso/lib/analytics/signup';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import {
updatePrivacyForDomain,
supportsPrivacyProtectionPurchase,
planItem as getCartItemForPlan,
} from 'calypso/lib/cart-values/cart-items';
import { loadExperimentAssignment } from 'calypso/lib/explat';
import { getLocaleSlug } from 'calypso/lib/i18n-utils';
import { getSiteTypePropertyValue } from 'calypso/lib/signup/site-type';
import { fetchSitesAndUser } from 'calypso/lib/signup/step-actions/fetch-sites-and-user';
Expand Down Expand Up @@ -266,6 +268,8 @@ export function createSiteWithCart( callback, dependencies, stepData, reduxStore
}

const locale = getLocaleSlug();
// Pre Load Experiment relevant to the post site creation goal screen
loadExperimentAssignment( CALYPSO_BUILTBYEXPRESS_GOAL_TEXT_EXPERIMENT_NAME );

wpcom.req.post(
'/sites/new',
Expand Down Expand Up @@ -871,6 +875,9 @@ export function createSite( callback, dependencies, stepData, reduxStore ) {
client_secret: config( 'wpcom_signup_key' ),
};

// Pre Load Experiment relevant to the post site creation goal screen
loadExperimentAssignment( CALYPSO_BUILTBYEXPRESS_GOAL_TEXT_EXPERIMENT_NAME );

wpcom.req.post( '/sites/new', data, function ( errors, response ) {
let providedDependencies;
let siteSlug;
Expand Down