Google Analytics Configuration

Google Analytics is a statistics service provided free of charge by Google. This plugin simplifies the process of including the basic Google Analytics code in your blog, so you don't have to edit any PHP. If you don't have a Google Analytics account yet, you can get one at analytics.google.com.

In the Google interface, when you "Add Website Profile" you are shown a piece of JavaScript that you are told to insert into the page, in that script is a unique string that identifies the website you just defined, that is your User Account string (it's shown in bold in the example below).

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "";
urchinTracker();
</script>

Once you have entered your User Account String in the box below your pages will be trackable by Google Analytics.

Congratulations! You have just activated Google Analytics - take a look at the source of your blog pages and search for the word 'urchin' to see how your pages have been affected.

"; } // end analytics_warning() function warning() { echo "

Google Analytics is not active. You must enter your UA String for it to work.

"; } // end analytics_warning() } // end class GA_Admin } //endif /** * Code that actually inserts stuff into pages. */ if ( ! class_exists( 'GA_Filter' ) ) { class GA_Filter { function analytics_cats() { global $dir, $post; foreach (get_the_category($post->ID) as $cat) { $profile = get_option('analytics_'.$cat->category_nicename); if ($profile != "") { return $profile; } } return ''; } //end analytics_cats() function spool_analytics() { global $uastring, $post, $version; echo("\n\n\n"); echo "\n"; // check if there's a post level profile // and if so, use it. $ua = get_post_meta($post->ID, $uakey); if ($ua[0] != "") { GA_Filter::spool_this($ua); return; } // check if any of the categories this post // belongs to have a profile, and if so // use the first one that's found // // TO DO switch on when maintenence UI is done // // $ua = analytics_cats(); // if ($ua != "") { // spool_this($ua); // return; // } // use the default channel if there is if ($uastring != "") { GA_Filter::spool_this($uastring); return; } // if we get here there is a problem echo("\n"); } // end spool_analytics() /* * Insert the tracking code into the page */ function spool_this($ua) { global $version; echo("\n"); } /* Create an array which contians: * "domain" e.g. boakes.org * "host" e.g. store.boakes.org */ function ga_get_domain($uri){ $hostPattern = "/^(http:\/\/)?([^\/]+)/i"; $domainPattern = "/[^\.\/]+\.[^\.\/]+$/"; preg_match($hostPattern, $uri, $matches); $host = $matches[2]; preg_match($domainPattern, $host, $matches); return array("domain"=>$matches[0],"host"=>$host); } /* Take the result of parsing an HTML anchor ($matches) * and from that, extract the target domain. If the * target is not local, then when the anchor is re-written * then an urchinTracker call is added. * * the format of the outbound link is definedin the $leaf * variable which must begin with a / and which may * contain multiple path levels: * e.g. /outbound/x/y/z * or which may be just "/" * */ function ga_parse_link($leaf, $matches){ global $origin ; $target = GA_Filter::ga_get_domain($matches[3]); $coolbit = ""; if ( $target["domain"] != $origin["domain"] ){ $coolBit .= "onclick=\"javascript:urchinTracker ('".$leaf."/".$target["host"]."');\""; } return '' . $matches[5] . ''; } function ga_parse_article_link($matches){ return GA_Filter::ga_parse_link("/outbound/article",$matches); } function ga_parse_comment_link($matches){ return GA_Filter::ga_parse_link("/outbound/comment",$matches); } function the_content($text) { static $anchorPattern = '/(.*?)<\/a>/i'; $text = preg_replace_callback($anchorPattern,array('GA_Filter','ga_parse_article_link'),$text); return $text; } function comment_text($text) { static $anchorPattern = '/(.*?)<\/a>/i'; $text = preg_replace_callback($anchorPattern,array('GA_Filter','ga_parse_comment_link'),$text); return $text; } function comment_author_link($text) { static $anchorPattern = '(.*href\s*=\s*)[\"\']*(.*)[\"\'] (.*)'; ereg($anchorPattern, $text, $matches); if ($matches[2] == "") return $text; $target = GA_Filter::ga_get_domain($matches[2]); $coolbit = ""; $origin = GA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]); if ( $target["domain"] != $origin["domain"] ){ $coolBit .= " onclick=\"javascript:urchinTracker('/outbound/commentauthor/".$target["host"]."');\" "; } return $matches[1] . "\"" . $matches[2] . "\"" . $coolBit . $matches[3]; } } // class GA_Filter } // endif $version = "0.51"; $uakey = "analytics"; $uastring = get_option('analytics_uastring'); $mulch = ($uastring=""?"##-#####-#":$uastring); $gaf = new GA_Filter(); $origin = $gaf->ga_get_domain($_SERVER["HTTP_HOST"]); if (!function_exists("add_GA_config_page")) { } //endif // adds the menu item to the admin interface add_action('admin_menu', array('GA_Admin','add_config_page')); // adds the footer so the javascript is loaded add_action('wp_head', array('GA_Filter','spool_analytics')); // filters alter the existing content add_filter('the_content', array('GA_Filter','the_content'), 99); add_filter('the_excerpt', array('GA_Filter','the_content'), 99); add_filter('comment_text', array('GA_Filter','comment_text'), 99); add_filter('get_comment_author_link', array('GA_Filter','comment_author_link'), 99); ?>