/** * WordPress dependencies */ import { _x, sprintf } from '@safe-wordpress/i18n'; /** * External dependencies */ import { getLocalUrlError } from '@nab/utils'; import { store as NAB_DATA } from '@nab/data'; import type { ExperimentType } from '@nab/types'; /** * Internal dependencies */ import icon from './icon.svg'; import { getQueryArgError } from './utils'; import { Original } from './components/original'; import { Alternative } from './components/alternative'; import type { ControlAttributes, AlternativeAttributes } from './types'; export const settings: ExperimentType< ControlAttributes, AlternativeAttributes > = { name: 'nab/url' as const, category: 'page', title: _x( 'URL', 'text (experiment name)', 'nelio-ab-testing' ), description: _x( 'Test alternative URLs', 'user', 'nelio-ab-testing' ), labels: { create: _x( 'Add new A/B test of URLs', 'command', 'nelio-ab-testing' ), }, icon, supports: { scope: 'tested-url-with-query-args', }, checks: { getControlError: ( control, select ) => { const homeUrl = select( NAB_DATA ).getPluginSetting( 'homeUrl' ); return getError( 'A', getLocalUrlError( control.url, homeUrl ) || getQueryArgError( control.url ) ); }, getAlternativeError: ( alternative, letter, _, select ) => { const homeUrl = select( NAB_DATA ).getPluginSetting( 'homeUrl' ); return getError( letter, getLocalUrlError( alternative.url, homeUrl ) || getQueryArgError( alternative.url ) ); }, isAlternativePreviewDisabled: ( alternative, control, select ) => { return !! settings.checks.getAlternativeError( alternative, '', control, select ); }, }, help: { original: _x( 'URL split tests help you to improve the conversion rate of your WordPress site by defining one or more variants. The control version (commonly known as the “A” version) is the selected URL from your site (such as, for instance, the home page or a contact us page) you want to run the test on.', 'user', 'nelio-ab-testing' ), alternative: _x( 'You can create one or more variants of your tested URL. When the visitor visits the original URL, she may be redirected to one of the variants in the list.', 'user', 'nelio-ab-testing' ), }, defaults: { original: { url: '', }, alternative: { url: '', }, }, views: { original: Original, alternative: Alternative, }, expected: { pageViews: { average: 5000, median: 1000, p25: 500, p75: 3500, }, }, }; // ======= // HELPERS // ======= function getError( letter: string, error: string | false ) { return ( !! error && sprintf( /* translators: %1$s: Letter of the variant. %2$s: Error description. */ _x( 'There’s an error in variant %1$s. %2$s', 'text', 'nelio-ab-testing' ), letter, error ) ); }