function spool_analytics() { global $wp_query; $options = get_option('GoogleAnalyticsPP'); if ($options["uastring"] != "" && (!current_user_can('edit_users') || $options["admintracking"]) && !is_preview()) { echo "\n" . '<!-- Google Analytics for WordPress | http://yoast.com/wordpress/google-analytics/ -->' . "\n"; echo '<script type="text/javascript">' . "\n"; echo "\t" . 'var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");' . "\n"; echo "\t" . 'document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));' . "\n"; echo '</script>' . "\n"; echo '<script type="text/javascript">' . "\n"; echo "\t" . 'try {' . "\n"; echo "\t\t" . 'var pageTracker = _gat._getTracker("' . $options["uastring"] . '");' . "\n"; /** * If this is a 404 page, track the 404 and prevent all other stuff as it's not needed. */ if (is_404()) { echo "\t\t" . 'pageTracker._trackPageview("/404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer);' . "\n"; echo "\t" . '} catch(err) {}' . "\n"; echo '</script>' . "\n"; } else { if ($wp_query->is_search && $wp_query->found_posts == 0) { echo "\t\t" . 'pageTracker._trackPageview("' . get_bloginfo('url') . '/?s=no-results: ' . rawurlencode($wp_query->query_vars['s']) . '&cat=no-results");' . "\n"; echo "\t" . '} catch(err) {}' . "\n"; echo '</script>' . "\n"; } else { if ($options["extrase"]) { /** * We need to load another script, so we need to close the try / catch, load the script, and open it again. */ echo "\t" . '} catch(err) {}' . "\n"; echo '</script>' . "\n"; echo '<script src="' . gapp_plugin_path() . 'custom_se.js" type="text/javascript"></script>' . "\n"; echo '<script type="text/javascript">' . "\n"; echo "\t" . 'try {' . "\n"; } if ($options['userv2']) { echo "\t\t" . 'pageTracker._setLocalRemoteServerMode();' . "\n"; } if ($options['allowanchor']) { echo "\t\t" . 'pageTracker._setAllowAnchor(true);' . "\n"; } if ($options['trackloggedin'] && !isset($_COOKIE['__utmv']) && is_user_logged_in()) { echo "\t\tpageTracker._setVar('logged-in');\n"; } else { echo "\t\t// Cookied already: " . $_COOKIE['__utmv'] . "\n"; } if (isset($options['domain']) && $options['domain'] != "") { if (substr($options['domain'], 0, 1) != ".") { $options['domain'] = "." . $options['domain']; } echo "\t\t" . 'pageTracker._setDomainName("' . $options['domain'] . '");' . "\n"; } if (strpos($_SERVER['HTTP_REFERER'], "images.google") && strpos($_SERVER['HTTP_REFERER'], "&prev") && $options["imagese"]) { echo "\t\t" . 'pageTracker._addOrganic("images.google","prev");' . "\n"; // echo "\t\t".'regex = new RegExp("images.google.([^\/]+).*&prev=([^&]+)");'."\n"; // echo "\t\t".'var match = regex.exec(pageTracker.qa);'."\n"; // echo "\t\t".'pageTracker.qa = "http://images.google." + match[1] + unescape(match[2]);'."\n"; } echo "\t\t" . 'pageTracker._trackPageview();' . "\n"; echo "\t" . '} catch(err) {}' . "\n"; echo '</script>' . "\n"; } } echo '<!-- End of Google Analytics code -->' . "\n"; } else { if ($options["uastring"] != "" && current_user_can('edit_users') && !$options["admintracking"]) { echo "<!-- Google Analytics tracking code not shown because admin tracking is disabled -->"; } else { if ($options["uastring"] == "" && current_user_can('edit_users')) { echo "<!-- Google Analytics tracking code not shown because yo haven't entered your UA string yet. -->"; } } } }
function spool_analytics() { global $wp_query; // echo '<!--'.print_r($wp_query,1).'-->'; $options = get_option('Yoast_Google_Analytics'); if (!isset($options['uastring']) || $options['uastring'] == '') { if (current_user_can('manage_options')) { echo "<!-- Google Analytics tracking code not shown because yo haven't chosen a Google Analytics account yet. -->\n"; } return; } /** * The order of custom variables is very, very important: custom vars should always take up the same slot to make analysis easy. */ $customvarslot = 1; if (yoast_ga_do_tracking() && !is_preview()) { $push = array(); if ($options['allowanchor']) { $push[] = "'_setAllowAnchor',true"; } if ($options['allowlinker']) { $push[] = "'_setAllowLinker',true"; } if ($options['anonymizeip']) { $push[] = "'_gat._anonymizeIp'"; } if (isset($options['domain']) && $options['domain'] != "") { // should allow for a 'none' domain too! if (substr($options['domain'], 0, 1) != "." && $options['domain'] != 'none') { $options['domain'] = "." . $options['domain']; } $push[] = "'_setDomainName','" . $options['domain'] . "'"; } if ($options['allowhash']) { $push[] = "'_setAllowHash',false"; } if ($options['cv_loggedin']) { $current_user = wp_get_current_user(); if ($current_user && $current_user->ID != 0) { $push[] = "'_setCustomVar',{$customvarslot},'logged-in','" . $current_user->roles[0] . "',1"; } // Customvar slot needs to be upped even when the user is not logged in, to make sure the variables below are always in the same slot. $customvarslot++; } if (function_exists('is_post_type_archive') && is_post_type_archive()) { if ($options['cv_post_type']) { $post_type = get_post_type(); if ($post_type) { $push[] = "'_setCustomVar'," . $customvarslot . ",'post_type','" . $post_type . "',3"; $customvarslot++; } } } else { if (is_singular() && !is_home()) { if ($options['cv_post_type']) { $post_type = get_post_type(); if ($post_type) { $push[] = "'_setCustomVar'," . $customvarslot . ",'post_type','" . $post_type . "',3"; $customvarslot++; } } if ($options['cv_authorname']) { $push[] = "'_setCustomVar',{$customvarslot},'author','" . GA_Filter::ga_str_clean(get_the_author_meta('display_name', $wp_query->post->post_author)) . "',3"; $customvarslot++; } if ($options['cv_tags']) { $i = 0; if (get_the_tags()) { $tagsstr = ''; foreach (get_the_tags() as $tag) { if ($i > 0) { $tagsstr .= ' '; } $tagsstr .= $tag->slug; $i++; } // Max 64 chars for value and label combined, hence 64 - 4 $tagsstr = substr($tagsstr, 0, 60); $push[] = "'_setCustomVar',{$customvarslot},'tags','" . $tagsstr . "',3"; } $customvarslot++; } if (is_singular()) { if ($options['cv_year']) { $push[] = "'_setCustomVar',{$customvarslot},'year','" . get_the_time('Y') . "',3"; $customvarslot++; } if ($options['cv_category'] && is_single()) { $cats = get_the_category(); if (is_array($cats) && isset($cats[0])) { $push[] = "'_setCustomVar',{$customvarslot},'category','" . $cats[0]->slug . "',3"; } $customvarslot++; } if ($options['cv_all_categories'] && is_single()) { $i = 0; $catsstr = ''; foreach ((array) get_the_category() as $cat) { if ($i > 0) { $catsstr .= ' '; } $catsstr .= $cat->slug; $i++; } // Max 64 chars for value and label combined, hence 64 - 10 $catsstr = substr($catsstr, 0, 54); $push[] = "'_setCustomVar',{$customvarslot},'categories','" . $catsstr . "',3"; $customvarslot++; } } } } $push = apply_filters('yoast-ga-custom-vars', $push, $customvarslot); $push = apply_filters('yoast-ga-push-before-pageview', $push); if (is_404()) { $push[] = "'_trackPageview','/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer"; } else { if ($wp_query->is_search) { $pushstr = "'_trackPageview','" . get_bloginfo('url') . "/?s="; if ($wp_query->found_posts == 0) { $push[] = $pushstr . "no-results:" . rawurlencode($wp_query->query_vars['s']) . "&cat=no-results'"; } else { if ($wp_query->found_posts == 1) { $push[] = $pushstr . rawurlencode($wp_query->query_vars['s']) . "&cat=1-result'"; } else { if ($wp_query->found_posts > 1 && $wp_query->found_posts < 6) { $push[] = $pushstr . rawurlencode($wp_query->query_vars['s']) . "&cat=2-5-results'"; } else { $push[] = $pushstr . rawurlencode($wp_query->query_vars['s']) . "&cat=plus-5-results'"; } } } } else { $push[] = "'_trackPageview'"; } } if (!isset($options['disable_pagespeed_tracking']) || !$options['disable_pagespeed_tracking']) { $push[] = "'_trackPageLoadTime'"; } $push = apply_filters('yoast-ga-push-after-pageview', $push); if (defined('WPSC_VERSION') && $options['wpec_tracking']) { $push = GA_Filter::wpec_transaction_tracking($push); } if ($options['shopp_tracking']) { global $Shopp; if (isset($Shopp)) { $push = GA_Filter::shopp_transaction_tracking($push); } } $pushstr = ""; foreach ($push as $key) { if (!empty($pushstr)) { $pushstr .= ","; } $pushstr .= "[" . $key . "]"; } if (current_user_can('manage_options') && $options['firebuglite'] && $options['debug']) { echo '<script src="https://getfirebug.com/firebug-lite.js" type="text/javascript"></script>'; } ?> <script type="text/javascript">//<![CDATA[ // Google Analytics for WordPress by Yoast v<?php echo GAWP_VERSION; ?> | http://yoast.com/wordpress/google-analytics/ var _gaq = _gaq || []; _gaq.push(['_setAccount','<?php echo trim($options["uastring"]); ?> ']); <?php if ($options["extrase"]) { if (!empty($options["extraseurl"])) { $url = $options["extraseurl"]; } else { $url = gapp_plugin_path() . 'custom_se_async.js'; } echo '</script><script src="' . $url . '" type="text/javascript"></script>' . "\n" . '<script type="text/javascript">'; } if ($options['customcode'] && trim($options['customcode']) != '') { echo "\t" . stripslashes($options['customcode']) . "\n"; } ?> _gaq.push(<?php echo $pushstr; ?> ); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = <?php if ($options['gajslocalhosting'] && !empty($options['gajsurl'])) { echo "'" . $options['gajsurl'] . "';"; } else { $script = 'ga.js'; if (current_user_can('manage_options') && $options['debug']) { $script = 'u/ga_debug.js'; } echo "('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/" . $script . "';"; } ?> var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); //]]></script> <?php } else { if ($options["uastring"] != "") { echo "<!-- Google Analytics tracking code not shown because users over level " . $options["ignore_userlevel"] . " are ignored -->\n"; } } }