Google Analytics 設定

Google Analyticsは、Googleより無料で提供されているアクセス解析サービスです。 このプラグインは、あなたのブログに基本的なGoogle Analyticsコードを簡単に挿入しますので、PHPコードやソースを編集する必要は一切ありません。 もしまだGoogle Analyticsアカウントを持っていない場合は、こちらから取得してください。 analytics.google.com.

Googleの管理画面上で、「プロファイルを追加」しようとすると、次のようなJavaScriptコードをページに挿入するように指示されます。
このコードの中には、そのWebサイトを定義するための文字列が含まれています。(「UA-*******-*」部分)

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

このテキストボックスにあなたのユーザーアカウント文字列(「UA-*******-*」部)を入力すると、トラッキングが開始されます。

おめでとうございます!Google Analyticsが有効化されました。ブログのソースから'urchin'を検索して、どのように実行されているか確認してください。

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

Google Analyticsが無効です。ユーザーアカウント(UA)文字列を入力してください。

"; } // 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"); // check if there's a post level profile // and if so, use it. if (function_exists("get_post_meta")) { $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, $includeUDN; echo("\n"); 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.61"; $uakey = "analytics"; if (function_exists("get_option")) { if ($wp_uastring_takes_precedence) { $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_footer', array('GA_Filter','spool_analytics')); // adds the footer so the javascript is loaded add_action('bb_foot', 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); ?>