/**
  * @covers Yoast_GA_Frontend->make_full_url()
  */
 public function test_make_full_url()
 {
     // Case 1
     $link = array('type' => 'download', 'protocol' => 'https', 'original_url' => 'yoast.com');
     $this->assertEquals($this->class_instance->make_full_url($link), 'https://yoast.com');
     // Case 2
     $link = array('type' => 'internal', 'protocol' => 'http', 'original_url' => 'yoast.com');
     $this->assertEquals($this->class_instance->make_full_url($link), 'http://yoast.com');
     // Case 3
     $link = array('type' => 'email', 'protocol' => 'mailto', 'original_url' => '*****@*****.**');
     $this->assertEquals($this->class_instance->make_full_url($link), 'mailto:peter@yoast.com');
 }
Beispiel #2
0
 public function __construct()
 {
     self::$options = get_option('yst_ga');
     if (isset(self::$options['ga_general']['tag_links_in_rss']) && self::$options['ga_general']['tag_links_in_rss'] == 1) {
         add_filter('the_permalink_rss', array($this, 'rsslinktagger'), 99);
     }
     // Check if the customer is running Universal or not (Enable in GA Settings -> Universal)
     if (isset(self::$options['ga_general']['enable_universal']) && self::$options['ga_general']['enable_universal'] == 1) {
         require_once GAWP_PATH . 'frontend/class-universal.php';
     } else {
         require_once GAWP_PATH . 'frontend/class-ga-js.php';
     }
 }
 public function __construct()
 {
     parent::__construct();
     $this->link_regex = '`<a (.*?)href=[\'\\"](.*?):/*([^\'\\"]+)[\'\\"](.*?)>(.*?)</a>`i';
     add_action('wp_head', array($this, 'tracking'), 8);
     if ($this->options['track_outbound'] == 1) {
         // Check for outbound option
         add_filter('the_content', array($this, 'the_content'), 99);
         add_filter('widget_text', array($this, 'widget_content'), 99);
         add_filter('the_excerpt', array($this, 'the_content'), 99);
         add_filter('comment_text', array($this, 'comment_text'), 99);
     }
 }
 /**
  * Function to output the GA Tracking code in the wp_head()
  *
  * @todo, add the tracking code and remove this test output
  */
 public function tracking()
 {
     global $wp_query;
     if (parent::do_tracking() && !is_preview()) {
         $gaq_push = array();
         if (isset($this->options['subdomain_tracking']) && $this->options['subdomain_tracking'] != '') {
             $domain = $this->options['subdomain_tracking'];
         } else {
             $domain = null;
             // Default domain value
         }
         if (!isset($this->options['allowanchor'])) {
             $this->options['allowanchor'] = false;
         }
         $ua_code = $this->get_tracking_code();
         if (is_null($ua_code)) {
             return;
         }
         $gaq_push[] = "'_setAccount', '" . $ua_code . "'";
         if (!is_null($domain)) {
             $gaq_push[] = "'_setDomainName', '" . $domain . "'";
         }
         if ($this->options['allowanchor']) {
             $gaq_push[] = "'_setAllowAnchor', true";
         }
         if ($this->options['add_allow_linker']) {
             $gaq_push[] = "'_setAllowLinker', true";
         }
         // @todo, check for AllowLinker in GA.js? Universal only?
         // SSL data
         $gaq_push[] = "'_gat._forceSSL'";
         // Anonymous data
         if ($this->options['anonymize_ips'] == 1) {
             $gaq_push[] = "'_gat._anonymizeIp'";
         }
         if (isset($this->options['allowhash']) && $this->options['allowhash']) {
             $gaq_push[] = "'_gat._anonymizeIp',true";
         }
         if (is_404()) {
             $gaq_push[] = "'_trackPageview,'/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer";
         } else {
             if ($wp_query->is_search) {
                 $pushstr = "'_trackPageview','/?s=";
                 if ($wp_query->found_posts == 0) {
                     $gaq_push[] = $pushstr . 'no-results:' . rawurlencode($wp_query->query_vars['s']) . "&cat=no-results'";
                 } else {
                     if ($wp_query->found_posts == 1) {
                         $gaq_push[] = $pushstr . rawurlencode($wp_query->query_vars['s']) . "&cat=1-result'";
                     } else {
                         if ($wp_query->found_posts > 1 && $wp_query->found_posts < 6) {
                             $gaq_push[] = $pushstr . rawurlencode($wp_query->query_vars['s']) . "&cat=2-5-results'";
                         } else {
                             $gaq_push[] = $pushstr . rawurlencode($wp_query->query_vars['s']) . "&cat=plus-5-results'";
                         }
                     }
                 }
             } else {
                 $gaq_push[] = "'_trackPageview'";
             }
         }
         $ga_settings = $this->options;
         // Assign the settings to the javascript include view
         // Include the tracking view
         if ($this->options['debug_mode'] == 1) {
             require 'views/tracking-debug.php';
         } else {
             require 'views/tracking-ga-js.php';
         }
     } else {
         require 'views/tracking-usergroup.php';
     }
 }
Beispiel #5
0
 /**
  * Function to output the GA Tracking code in the wp_head()
  *
  * @param bool $return_array
  */
 public function tracking($return_array = false)
 {
     global $wp_query;
     if (parent::do_tracking() && !is_preview()) {
         $gaq_push = array();
         // Running action for adding possible code
         do_action('yst_tracking');
         if (isset($this->options['subdomain_tracking']) && $this->options['subdomain_tracking'] != '') {
             $domain = $this->options['subdomain_tracking'];
         } else {
             $domain = null;
             // Default domain value
         }
         if (!isset($this->options['allowanchor'])) {
             $this->options['allowanchor'] = false;
         }
         $ua_code = $this->get_tracking_code();
         if (is_null($ua_code) && $return_array == false) {
             return;
         }
         $gaq_push[] = "'_setAccount', '" . $ua_code . "'";
         if (!is_null($domain)) {
             $gaq_push[] = "'_setDomainName', '" . $domain . "'";
         }
         if (isset($this->options['allowanchor']) && $this->options['allowanchor']) {
             $gaq_push[] = "'_setAllowAnchor', true";
         }
         if ($this->options['add_allow_linker']) {
             $gaq_push[] = "'_setAllowLinker', true";
         }
         // @todo, check for AllowLinker in GA.js? Universal only?
         // SSL data
         $gaq_push[] = "'_gat._forceSSL'";
         if (!empty($this->options['custom_code'])) {
             // Add custom code to the view
             $gaq_push[] = array('type' => 'custom_code', 'value' => stripslashes($this->options['custom_code']));
         }
         // Anonymous data
         if ($this->options['anonymize_ips'] == 1) {
             $gaq_push[] = "'_gat._anonymizeIp'";
         }
         if (isset($this->options['allowhash']) && $this->options['allowhash']) {
             $gaq_push[] = "'_gat._anonymizeIp',true";
         }
         if (is_404()) {
             $gaq_push[] = "'_trackPageview','/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer";
         } else {
             if ($wp_query->is_search) {
                 $pushstr = "'_trackPageview','/?s=";
                 if ($wp_query->found_posts == 0) {
                     $gaq_push[] = $pushstr . 'no-results:' . rawurlencode($wp_query->query_vars['s']) . "&cat=no-results'";
                 } else {
                     if ($wp_query->found_posts == 1) {
                         $gaq_push[] = $pushstr . rawurlencode($wp_query->query_vars['s']) . "&cat=1-result'";
                     } else {
                         if ($wp_query->found_posts > 1 && $wp_query->found_posts < 6) {
                             $gaq_push[] = $pushstr . rawurlencode($wp_query->query_vars['s']) . "&cat=2-5-results'";
                         } else {
                             $gaq_push[] = $pushstr . rawurlencode($wp_query->query_vars['s']) . "&cat=plus-5-results'";
                         }
                     }
                 }
             } else {
                 $gaq_push[] = "'_trackPageview'";
             }
         }
         /**
          * Filter: 'yoast-ga-push-array-ga-js' - Allows filtering of the commands to push
          *
          * @api array $gaq_push
          */
         if (true == $return_array) {
             return $gaq_push;
         }
         $gaq_push = apply_filters('yoast-ga-push-array-ga-js', $gaq_push);
         $ga_settings = $this->options;
         // Assign the settings to the javascript include view
         // Include the tracking view
         if ($this->options['debug_mode'] == 1) {
             require 'views/tracking-debug.php';
         } else {
             require 'views/tracking-ga-js.php';
         }
     } else {
         require 'views/tracking-usergroup.php';
     }
 }