/** * Returns the GA tracking code * * @since 0.3 */ function get_raw_embed_code() { $options = Yoast_GA_Options::instance()->options; if (isset($options['enable_universal']) && 1 === intval($options['enable_universal'])) { $tracker = new Yoast_GA_Universal(); } else { $tracker = new Yoast_GA_JS(); } ob_start(); $tracker->tracking(); $ga_code = ob_get_clean(); return $ga_code; }
/** * Test the custom code in the tracking * * @covers Yoast_GA_JS::tracking() */ public function test_custom_code() { $options_singleton = Yoast_GA_Options::instance(); $options = $options_singleton->get_options(); $options['custom_code'] = '__custom_code[\\"test\\"]'; $options_singleton->update_option($options); // create and go to post $post_id = $this->factory->post->create(); $this->go_to(get_permalink($post_id)); // Get tracking code $tracking_data = $this->class_instance->tracking(true); if (is_array($tracking_data)) { foreach ($tracking_data as $row) { if (is_array($row)) { if ($row['type'] == 'custom_code') { $this->assertEquals($row['value'], '__custom_code["test"]'); } } } } }