Example #1
0
 /**
  * Record a conversion
  *
  * @since 0.4.0
  *
  * @param \WP_REST_Request $request Full data about the request.
  * @return \WP_Error|\WP_REST_Request
  */
 public function conversion($request)
 {
     if (!ingot_is_no_testing_mode()) {
         $id = $request->get_param('id');
         ingot_register_conversion($id, $request->get_param('ingot_session_ID'));
     }
     return ingot_rest_response(['message' => ':)'], 200);
 }
Example #2
0
 /**
  * Decide, based on group type and average sessions if variant selection be at random
  *
  * @since 1.1.0
  *
  * @return bool
  */
 protected function set_random()
 {
     if (!ingot_is_no_testing_mode()) {
         if (!is_object($this->obj)) {
             $this->set_group_obj();
         }
         $initial_calc = new initial($this->obj);
         $this->random_mode = !$initial_calc->is_passed_initial();
     } else {
         $this->random_mode = true;
     }
 }
Example #3
0
 /**
  * Check if session has been used
  *
  * @since 0.3.0
  *
  * @param \WP_REST_Request $request Full data about the request.
  *
  * @return \WP_Error|\WP_REST_Response
  */
 public function session($request)
 {
     $session = $this->get_session_by_url_params($request);
     if (ingot_is_no_testing_mode()) {
         $data['ingot_ID'] = $session['ingot_ID'];
         $data['tests'] = [];
         $data['session_ID'] = $session['ID'];
         return $data;
     }
     $tests = [];
     if (!is_array($session)) {
         return $session;
     } else {
         if (\ingot\testing\crud\session::is_used($session['ID'])) {
             $new_session_args = [];
             if (0 != $request->get_param('ingot_id')) {
                 $new_session_args['ingot_ID'] = $request->get_param('ingot_id');
             } elseif (0 < absint($session['ingot_ID'])) {
                 $new_session_args['ingot_ID'] = $session['ingot_ID'];
             }
             if (0 != get_current_user_id()) {
                 $new_session_args['uID'] = get_current_user_id();
             }
             $data['session_ID'] = \ingot\testing\crud\session::create($new_session_args, true);
             if (is_numeric($data['session_ID'])) {
                 $session = \ingot\testing\crud\session::read((int) $data['session_ID']);
                 if (!empty($request->get_param('test_ids'))) {
                     foreach ($request->get_param('test_ids') as $variant_id) {
                         $html = '';
                         if (is_array($group = group::get_by_variant_id($variant_id))) {
                             $html = ingot_click_test($group);
                         }
                         $tests[] = ['html' => $html, 'ID' => $variant_id];
                     }
                 }
             }
         } else {
             \ingot\testing\crud\session::mark_used($session['ID']);
             $data['session_ID'] = $session['ID'];
         }
         $data['ingot_ID'] = $session['ingot_ID'];
         $data['tests'] = $tests;
         return rest_ensure_response($data);
     }
 }
Example #4
0
 /**
  *
  *
  * @param $levers
  *
  * @return mixed
  */
 protected function random_lever($levers)
 {
     if (isset($levers[$this->get_ID()]) && is_array($levers[$this->get_ID()])) {
         $levers = $levers[$this->get_ID()];
     }
     if (ingot_is_no_testing_mode()) {
         reset($levers);
         $key = key($levers);
     } else {
         $key = array_rand($levers);
     }
     return $levers[$key];
 }
Example #5
0
 /**
  * Inititialize Ingot session
  *
  * @uses "parse_request"
  *
  * @since 0.3.0
  */
 public function init_session()
 {
     if (ingot_is_front_end() && !ingot_is_no_testing_mode() && !ingot_is_admin_ajax() && !is_admin() && !ingot_is_rest_api()) {
         $id = null;
         if (isset($_GET['ingot_session_ID']) && ingot_verify_session_nonce(helpers::v('ingot_session_nonce', $_GET, ''))) {
             $id = helpers::v('ingot_session_ID', $_GET, null);
         }
         $session = new \ingot\testing\object\session($id);
         $session_data = $session->get_session_info();
         /**
          * Fired when Ingot session is setup at parse_request
          *
          * @since 0.3.0
          *
          * @param array $session_data has ID (session ID) and ingot_ID
          */
         do_action('ingot_session_initialized', $session_data);
         $this->current_session_data = $session_data;
     }
 }