' . ($experimentId ? ($readOnly ? esc_html__('View Experiment', 'better-analytics') : esc_html__('Edit Experiment', 'better-analytics')) : esc_html__('Create Experiment', 'better-analytics')) . '

'; if ($readOnly) { if ($experiment['status'] == 'ENDED') { echo '

' . esc_html__('This experiment has ended. You can view it for informational purposes, but you cannot make changes to it.', 'better-analytics') . '

'; } elseif ($experiment['status'] == 'RUNNING') { echo '

' . esc_html__('This experiment is currently running. You can view it for informational purposes, but you cannot make changes to it.', 'better-analytics') . '

'; } else { echo '

' . esc_html__('This experiment was not created by Better Analytics. You can view it for informational purposes, but you cannot make changes to it.', 'better-analytics') . '

'; } } echo '
'; if ($experimentId) { echo ''; } wp_nonce_field('create_edit-experiment' . $nOnceSalt); ?> '; } } elseif($experiment['status'] == 'ENDED') { if(isset($experiment['variationWinner'])) { echo ''; } } ?>
'; ?>
' . esc_html__('Variation Status', 'better-analytics') . ' '; if ($experiment['variationWinning'] > 0) { printf(esc_html__('Variation %u is winning', 'better-analytics'), $experiment['variationWinning']); } else { esc_html_e('Original is winning', 'better-analytics'); } echo '
' . esc_html__('Variation Winner', 'better-analytics') . ' '; if ($experiment['variationWinner'] > 0) { printf(esc_html__('Variation %u won', 'better-analytics'), $experiment['variationWinner']); } else { esc_html_e('Original won', 'better-analytics'); } echo '
/>
'; echo ''; echo ''; echo ''; echo ''; ?>
/>
/>
', '' ) ); ?>">

/>
100000 )); $allPages = get_pages(); echo ''; ?>
'; foreach ($allPosts as $post) { $postId = 0; if (!empty($experiment['extraData']['post_title']) && !empty($experiment['extraData']['post_title']['post_id'])) { $postId = empty($experiment['extraData']['page_title']['post_id']) ? 0 : $experiment['extraData']['page_title']['post_id']; } echo ''; } unset($allPosts); echo ''; ?>
    $variation) { echo '
  1. '; if (!$readOnly) { echo ''; } echo '
  2. '; } } else { echo '
  3. '; if (!$readOnly) { echo ''; } echo '
  4. '; } ?>
' . esc_html__('Add another title variation', 'better-analytics') . ''; } ?>
'; foreach ($allPages as $page) { $postId = 0; if (!empty($experiment['extraData']['page_title']) && !empty($experiment['extraData']['page_title']['post_id'])) { $postId = $experiment['extraData']['page_title']['post_id']; } echo ''; } unset($allPages); echo ''; ?>
    $variation) { echo '
  1. '; if (!$readOnly) { echo ''; } echo '
  2. '; } } else { echo '
  3. '; if (!$readOnly) { echo ''; } echo '
  4. '; } ?>
' . esc_html__('Add another title variation', 'better-analytics') . ''; } ?>
    $variation) { echo '
  1. ' . (!$readOnly ? '' : '') . '
  2. '; } } else { echo '
  3. ' . (!$readOnly ? '' : '') . '
  4. '; } ?>
' . esc_html__('Add another CSS variation', 'better-analytics') . ''; } ?>
    get('TextDomain'); if (!empty($experiment['extraData']['theme']) && !empty($experiment['extraData']['theme']['themes']) && is_array($experiment['extraData']['theme']['themes'])) { foreach ($experiment['extraData']['theme']['themes'] as $key => $variation) { echo '
  1. '; echo ''; echo ''; echo '
  2. '; } } else { echo '
  3. '; echo ''; echo ''; echo '
  4. '; } unset($allThemes); ?>
'; } else { check_admin_referer('create_edit-experiment' . $nOnceSalt); $errorMessage = array(); $experimentObject = array( 'status' => empty($_POST['status']) ? '' : sanitize_text_field($_POST['status']), 'servingFramework' => 'API', 'editableInGaUi' => false, ); if (@$experiment['status'] != 'ENDED') { $experimentObject['minimumExperimentLengthInDays'] = absint(empty($_POST['minimum_days_to_run']) ? 1 : $_POST['minimum_days_to_run']); $experimentObject['equalWeighting'] = (!empty($_POST['equal_weighting']) && $_POST['equal_weighting'] ? true : false); $experimentObject['name'] = sanitize_text_field(empty($_POST['name']) ? '' : $_POST['name']); $experimentObject['trafficCoverage'] = absint(empty($_POST['traffic_coverage']) ? 1 : $_POST['traffic_coverage']) / 100; $experimentObject['winnerConfidenceLevel'] = absint(empty($_POST['winner_confidence_level']) ? 25 : $_POST['winner_confidence_level']) / 100; //TODO: check default values } if (@$experiment['status'] != 'RUNNING' && @$experiment['status'] != 'ENDED') { $experimentObject['optimizationType'] = sanitize_text_field(@$_POST['optimization_type']); $experimentObject['objectiveMetric'] = sanitize_text_field(@$_POST['objective_metric']); } $extraData = array( 'description' => sanitize_text_field(@$_POST['description']), 'type' => sanitize_text_field(@$_POST['type']) ); $extraDataInput = @$_POST['extra_data']; $variations = array(array( 'name' => 'original', 'status' => 'ACTIVE' )); if (is_array($extraDataInput)) { switch (@$_POST['type']) { case 'POST_TITLE': $extraData['post_title']['post_id'] = absint(@$extraDataInput['post_title']['post_id']); if (is_array(@$extraDataInput['post_title']['titles'])) { foreach($extraDataInput['post_title']['titles'] as $title) { if ($title = sanitize_text_field($title)) { $extraData['post_title']['titles'][] = $title; $variations[] = array( 'name' => $title, 'status' => 'ACTIVE', // 'url' => 'none' ); } } } break; case 'PAGE_TITLE': $extraData['page_title']['post_id'] = absint(@$extraDataInput['page_title']['post_id']); if (is_array(@$extraDataInput['page_title']['titles'])) { foreach($extraDataInput['page_title']['titles'] as $title) { if ($title = sanitize_text_field($title)) { $extraData['page_title']['titles'][] = $title; $variations[] = array( 'name' => $title, 'status' => 'ACTIVE', // 'url' => 'none' ); } } } break; case 'CSS': if (is_array(@$extraDataInput['css']['code'])) { foreach($extraDataInput['css']['code'] as $code) { if ($code = wp_strip_all_tags($code)) { $extraData['css']['code'][] = $code; $variations[] = array( 'name' => 'CSS variation', 'status' => 'ACTIVE', // 'url' => 'none' ); } } } break; case 'THEME': if (is_array(@$extraDataInput['theme']['themes'])) { foreach($extraDataInput['theme']['themes'] as $theme) { if ($theme = sanitize_text_field($theme)) { $extraData['theme']['themes'][] = $theme; $variations[] = array( 'name' => $theme, 'status' => 'ACTIVE', // 'url' => 'none' ); } } } break; default: list($extraData, $variations) = apply_filters('better_analytics_experiment_save', $extraData, $variations, $extraDataInput); } } if (count($variations) > 0) { $experimentObject['variations'] = $variations; } $experimentObject['description'] = json_encode($extraData); if (!$experimentObject['name'] && !$experiment['name']) { $errorMessage[] = esc_html__('Experiment name is required.', 'better-analytics'); } if (!$errorMessage && $profile = $reportingClass->getProfileByProfileId(@$betterAnalyticsOptions['api']['profile'])) { if ($experimentId) { $experiment = $reportingClass->patchExperiment($profile['accountId'], $profile['webPropertyId'], $profile['id'], $experimentId, $experimentObject); } else { $experiment = $reportingClass->insertExperiment($profile['accountId'], $profile['webPropertyId'], $profile['id'], $experimentObject); } $reportingClass->deleteExperimentCache($profile['accountId'], $profile['webPropertyId'], $profile['id']); if (!empty($experiment['id'])) { $reportingClass->deleteExperimentCache($profile['accountId'], $profile['webPropertyId'], $profile['id'], $experiment['id']); } if ($experimentId) { /* translators: %1$s = , %2$s = */ $noticeAtTop = '

' . sprintf(esc_html__('Experiment %1$supdated%2$s.'), '', '') . '

'; } else { /* translators: %1$s = , %2$s = */ $noticeAtTop = '

' . sprintf(esc_html__('Experiment %1$screated%2$s.'), '', '') . '

'; } } } } elseif ($experiment && !empty($_REQUEST['action']) && ($_REQUEST['action'] == 'start' || $_REQUEST['action'] == 'end' || $_REQUEST['action'] == 'delete')) { $reportingClass->deleteExperimentCache($experiment['accountId'], $experiment['webPropertyId'], $experiment['profileId']); $reportingClass->deleteExperimentCache($experiment['accountId'], $experiment['webPropertyId'], $experiment['profileId'], $experimentId); if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'start') { $experiment = $reportingClass->patchExperiment($experiment['accountId'], $experiment['webPropertyId'], $experiment['profileId'], $experimentId, array('status' => 'RUNNING')); /* translators: %1$s = , %2$s = */ $noticeAtTop = '

' . sprintf(esc_html__('Experiment %1$sstarted%2$s.'), '', '') . '

'; } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'end') { $experiment = $reportingClass->patchExperiment($experiment['accountId'], $experiment['webPropertyId'], $experiment['profileId'], $experimentId, array('status' => 'ENDED')); /* translators: %1$s = , %2$s = */ $noticeAtTop = '

' . sprintf(esc_html__('Experiment %1$sended%2$s.'), '', '') . '

'; } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'delete') { $reportingClass->deleteExperiment($experiment['accountId'], $experiment['webPropertyId'], $experiment['profileId'], $experimentId); /* translators: %1$s = , %2$s = */ $noticeAtTop = '

' . sprintf(esc_html__('Experiment %1$sdeleted%2$s.'), '', '') . '

'; } } if (empty($_REQUEST['action']) || $_REQUEST['action'] != 'create_edit' || $_SERVER['REQUEST_METHOD'] == 'POST') { if (!empty($errorMessage)) { echo '
'; foreach($errorMessage as $error) { echo '

' . $error . '

'; } echo '
'; } else { echo '

' . esc_html__('Experiments', 'better-analytics') . ' ' . esc_html__('Add New', 'better-analytics') . '' . '

'; echo $noticeAtTop; if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'activate') { /* translators: %1$s = , %2$s = */ echo '

' . sprintf(esc_html__('Experiment %1$sactivated%2$s.'), '', '') . '

'; } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'activate-selected') { /* translators: %1$s = , %2$s = */ echo '

' . sprintf(esc_html__('Selected experiments %1$sactivated%2$s.'), '', '') . '

'; } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'deactivate') { /* translators: %1$s = , %2$s = */ echo '

' . sprintf(esc_html__('Experiment %1$sdeactivated%2$s.'), '', '') . '

'; } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'deactivate-selected') { /* translators: %1$s = , %2$s = */ echo '

' . sprintf(esc_html__('Selected experiments %1$sdeactivated%2$s.'), '', '') . '

'; } global $totals; $experiments = $totals = array(); if ($profile = $reportingClass->getProfileByProfileId($betterAnalyticsOptions['api']['profile'])) { $experiments = DigitalPointBetterAnalytics_Model_Experiments::getAllExperiments($profile['accountId'], $profile['webPropertyId'], $profile['id']); $totals = DigitalPointBetterAnalytics_Model_Reporting::getExperimentTotals($experiments); } $goalTable = new DigitalPointBetterAnalytics_Formatting_ExperimentTable(array('plural' => 'experiments', 'experiments' => $experiments)); $goalTable->prepare_items(); $goalTable->views(); $goalTable->display(); echo '
'; } }