Extend experiemnt expiration TTL to an hour

This commit is contained in:
moon 2022-05-11 12:36:11 -07:00
parent dd6f161467
commit a64844de1a
2 changed files with 11 additions and 1 deletions

View File

@ -7,7 +7,11 @@ import { apiFetch } from '@wordpress/data-controls';
* Internal dependencies * Internal dependencies
*/ */
import TYPES from './action-types'; import TYPES from './action-types';
import { EXPERIMENT_NAME_PREFIX, TRANSIENT_NAME_PREFIX } from './constants'; import {
EXPERIMENT_NAME_PREFIX,
TRANSIENT_NAME_PREFIX,
TRANSIENT_TIMEOUT_NAME_PREFIX,
} from './constants';
function toggleFrontendExperiment( experimentName, newVariation ) { function toggleFrontendExperiment( experimentName, newVariation ) {
const storageItem = JSON.parse( const storageItem = JSON.parse(
@ -15,6 +19,7 @@ function toggleFrontendExperiment( experimentName, newVariation ) {
); );
storageItem.variationName = newVariation; storageItem.variationName = newVariation;
storageItem.ttl = 3600;
window.localStorage.setItem( window.localStorage.setItem(
EXPERIMENT_NAME_PREFIX + experimentName, EXPERIMENT_NAME_PREFIX + experimentName,
@ -26,6 +31,9 @@ function* toggleBackendExperiment( experimentName, newVariation ) {
try { try {
const payload = {}; const payload = {};
payload[ TRANSIENT_NAME_PREFIX + experimentName ] = newVariation; payload[ TRANSIENT_NAME_PREFIX + experimentName ] = newVariation;
payload[ TRANSIENT_TIMEOUT_NAME_PREFIX + experimentName ] =
Math.round( Date.now() / 1000 ) + 3600;
yield apiFetch( { yield apiFetch( {
method: 'POST', method: 'POST',
path: '/wc-admin/options', path: '/wc-admin/options',

View File

@ -1,4 +1,6 @@
export const STORE_KEY = 'wc-admin-helper/experiments'; export const STORE_KEY = 'wc-admin-helper/experiments';
export const EXPERIMENT_NAME_PREFIX = 'explat-experiment--'; export const EXPERIMENT_NAME_PREFIX = 'explat-experiment--';
export const TRANSIENT_NAME_PREFIX = '_transient_abtest_variation_'; export const TRANSIENT_NAME_PREFIX = '_transient_abtest_variation_';
export const TRANSIENT_TIMEOUT_NAME_PREFIX =
'_transient_timeout_abtest_variation';
export const API_NAMESPACE = '/wc-admin-test-helper'; export const API_NAMESPACE = '/wc-admin-test-helper';