/** * Register a conversion for a destination test * * @since 1.1.0 * * @param int $group_id */ public static function conversion($group_id) { $variant_id = cookie::get_cookie($group_id); if (is_numeric($variant_id)) { ingot_register_conversion($variant_id); } }
/** * 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_bot()) { $id = $request->get_param('id'); ingot_register_conversion($id, $request->get_param('ingot_session_ID')); } return ingot_rest_response(['message' => ':)'], 200); }
/** * Test multiple conversions * * @todo move this test to a better place * * @since 0.4.0 * * @group bandit * @group group * @group front_ui * * @covers ingot_register_conversion() */ public function testMultipleConversions() { $groups = ingot_tests_data::click_link_group(true, 1, 3); $group_id = $groups['ids'][0]; $variants = $groups['variants'][$groups['ids'][0]]; $expected = []; foreach ($variants as $variant) { $expected[$variant] = ['n' => 0, 'd' => 0]; } for ($i = 0; $i <= 25; $i++) { $chosen = $this->check_render($groups); if (in_array($i, [2, 3, 5, 8, 13, 21])) { ingot_register_conversion($chosen); $expected[$chosen]['n'] = $expected[$chosen]['n'] + 1; } $expected[$chosen]['d'] = $expected[$chosen]['d'] + 1; $levers = \ingot\testing\crud\group::get_levers($group_id); /** @var \MaBandit\Lever $lever */ foreach ($levers[$group_id] as $id => $lever) { if ($chosen != $id) { $this->assertSame($expected[$id]['n'], $lever->getNumerator(), $id . '-' . $lever->getNumerator()); $this->assertSame($expected[$id]['d'], $lever->getDenominator(), $id); } } } }
$content = 'http://hellogiggles.com/wp-content/uploads/2014/07/22/you-popular-cute-cat-the-very-creative_113506.jpg'; } return sprintf('<img src="%s" />', esc_url($content)); } /** * This function should return ID of the group. * * The first time this runs it will create the group and save its ID in an option. After that, it will just return the ID from the option. * * It may also return a WP_Error with information on why it couldn't create the group * * @return int|WP_Error */ function my_ingot_custom_test_group() { include_once dirname(__FILE__) . '/my_ingot_custom_test.php'; $group = new my_ingot_custom_test(); $id = $group->get_id(); return $id; } /** * Register a conversion whenever anyone reaches page 42 and we have a variant ID in the cookie to track. * * @TODO -- You should change your condition for registering a conversion. Could be a different page, a different hook. Or you could use the `/variants/<id>/conversion` endpoint to register via AJAX -- see http://ingothq.com/documentation/ingot-rest-api/ */ add_action('template_redirect', function () { if (!ingot_is_bot() && is_page(42) && isset($_COOKIE['my_ingot_custom_test_variant']) && 0 < absint($_COOKIE['my_ingot_custom_test_variant'])) { $variant_id = absint($_COOKIE['my_ingot_custom_test_variant']); ingot_register_conversion($variant_id); } });
/** * Generic callback for hook test tracking * * @since 1.1.0 */ public function hook_test_cb() { if (!empty($this->hook_tests) && in_array(sanitize_key(current_action()), $this->hook_tests)) { ingot_register_conversion($this->hook_tests[sanitize_key(current_action())]); } }
/** * Check products in a sale for any we are testing and if so registers conversion * * @since 0.0.9 * * @access protected * * @param array $products Array of product IDs */ protected function check_for_winners($products) { foreach ($products as $product) { if (!is_null($test = $this->get_test($product))) { ingot_register_conversion($test->ID); } } }