/** * WordPress dependencies */ import { _x, sprintf } from '@safe-wordpress/i18n'; /** * External dependencies */ import { store as NAB_DATA } from '@nab/data'; import type { ExperimentType } from '@nab/types'; /** * Internal dependencies */ import icon from './icon.svg'; import { Original } from './components/original'; import { Alternative } from './components/alternative'; import { getPostTypeExceptions } from './get-post-type-exceptions'; import type { ControlAttributes, AlternativeAttributes } from './types'; export const settings: ExperimentType< ControlAttributes, AlternativeAttributes > = { name: 'nab/custom-post-type' as const, category: 'page', title: _x( 'Custom Post Type', 'text (experiment name)', 'nelio-ab-testing' ), description: _x( 'Test alternative versions of a custom post type', 'user', 'nelio-ab-testing' ), labels: { create: _x( 'Add new A/B test of custom post types', 'command', 'nelio-ab-testing' ), }, icon, supports: { alternativeApplication: ( control ) => ! control?.testAgainstExistingContent, alternativeEdition: { type: 'external', enabled: ( control ) => ! control.testAgainstExistingContent, }, postTypeExceptions: ( select ) => getPostTypeExceptions( { isWooCommerceEnabled: select( NAB_DATA ) .getActivePlugins() .includes( 'woocommerce/woocommerce.php' ), } ), scope: 'tested-post-with-consistency', }, checks: { getControlError: ( control ) => { if ( ! control.postId ) { return _x( 'Please select the element you want to test', 'user', 'nelio-ab-testing' ); } return false; }, getAlternativeError: ( alternative, letter, control ) => { if ( control.testAgainstExistingContent && ! alternative.postId ) { return sprintf( /* translators: %s: Letter of the variant. */ _x( 'Please select an element in variant %s', 'user', 'nelio-ab-testing' ), letter ); } return false; }, isAlternativePreviewDisabled: ( alternative, control ) => !! control.testAgainstExistingContent && ! alternative.postId, }, help: { original: _x( 'Split tests of custom post types help you to improve the conversion rate of your WordPress site by creating one or more variants of your content. The control version (commonly known as the “A” version) is the already-existing content from your site you want to run the test on.', 'user', 'nelio-ab-testing' ), alternative: _x( 'You can create one or more variants of your tested element. By default, each variant you create will be an exact copy of the tested element. Click on the “Edit” link of each variant to tweak it as you please. When editing a variant, you can also overwrite it with the content of any existing element in the selected type.', 'user', 'nelio-ab-testing' ), }, defaults: { original: { postType: '', postId: 0, }, alternative: { name: '', postId: 0, }, }, views: { original: Original, alternative: Alternative, }, };