WordPressにカウンタをつけたかったので、Counterize IIをいれてみた。簡単なアクセス解析ができるプラグインみたい。
http://wordpress.org/extend/plugins/counterizeii/ からダウンロードして、pluginsディレクトリに展開する。counterize-ja_UTF.mo を counterize-ja.mo にリネームして設定画面を日本語表示にする。
関数をいろいろ追加する
昨日のアクセス数も表示できるように http://oboegaki.net/wordpress/plugin/counterize-ii.html を参考にcounterize.phpに以下の関数を追加する。
# Returns amount of hits yesterday
function counterize_gethitsyesterday()
{
$today = date("Y-m-d");
$yesterday = date("Y-m-d",strtotime("-1 day"));
$sql = "SELECT COUNT(1) FROM ".counterize_logTable()." WHERE timestamp >= '$yesterday' AND timestamp < '$today'";
$wpdb =& $GLOBALS['wpdb'];
return $wpdb->get_var($sql);
}
ユニークなIPアドレスからのアクセス数も表示できるようにしておこう。
# Returns amount of unique hits yesterday
function counterize_getuniquehitsyesterday()
{
$today = date("Y-m-d");
$yesterday = date("Y-m-d",strtotime("-1 day"));
$sql = "SELECT count(DISTINCT ip) FROM ".counterize_logTable()." WHERE timestamp >= '$yesterday' AND timestamp < '$today'";
$wpdb =& $GLOBALS['wpdb'];
return $wpdb->get_var($sql);
}
トータルのユニークなヒット数(日にちが違えば同じIPアドレスでも別カウントとして数える)を表示する関数。
# Returns amount of unique hits total
function counterize_getuniquehitstotal()
{
$sql = 'SELECT count(DISTINCT ip,date(timestamp)) FROM ' . counterize_logTable();
$wpdb =& $GLOBALS['wpdb'];
return $wpdb->get_var($sql);
}
sideber.phpあたりに以下を追加して実際に表示させる。
<table> <tbody> <tr> <td><br /></td> <td>Unique</td> <td>Hits</td> </tr> <tr> <td>今日</td> <td><?php echo number_format(counterize_getuniquehitstoday()); ?></td> <td><?php echo number_format(counterize_gethitstoday()); ?></td> </tr> <tr> <td>昨日</td> <td><?php echo number_format(counterize_getuniquehitsyesterday()); ?></td> <td><?php echo number_format(counterize_gethitsyesterday()); ?></td> </tr> <tr> <td>累計</td> <td><?php echo number_format(counterize_getuniquehitstotal()); ?></td> <td><?php echo number_format(counterize_getamount()); ?></td> </tr> </tbody> </table>
[12/2 追記]
現在の訪問者(アクセスから5分以内)の数を表示するには以下の関数を使う。
counterize_get_online_users();
管理画面でIPアドレスを表示させる
Counterize II ではDBにIPアドレスを記録しているかと思ったら、md5のハッシュ値を記録しているだけだった。
IPアドレスをそのまま記録するように修正する。
$ diff -u counterize.php.orig counterize.php
@@ -781,7 +808,8 @@
$wpdb =& $GLOBALS['wpdb'];
$sql = "INSERT INTO ".counterize_logTable()." (IP, timestamp, pageID, refererID, agentID) VALUES (";
- $sql .= "'" . substr(md5($wpdb->escape($remoteaddr)),1,16) . "',";
+// $sql .= "'" . substr(md5($wpdb->escape($remoteaddr)),1,16) . "',";
+ $sql .= "'" . $wpdb->escape($remoteaddr) . "',";
$sql .= "'" . $timestamp . "', '";
$sql .= $pageID . "', '";
$sql .= $refererID . "', '";
管理画面にIPアドレスを表示するように修正する。
@@ -1098,6 +1126,7 @@
<td scope="col" width="2%"><strong><?php _e("del",'counterize'); ?></strong></td>
<td scope="col" width="6%"><strong><?php _e("ID",'counterize'); ?></strong></td>
<td scope="col" style="width: 14%"><strong><?php _e("Timestamp",'counterize'); ?></strong></td>
+ <td scope="col" style="width: 10%"><strong><?php _e("IP",'counterize'); ?></strong></td>
<td scope="col" style="width: 20%"><strong><?php _e("URl",'counterize'); ?></strong></td>
<td scope="col" style="width: 31%"><strong><?php _e("Referer",'counterize'); ?></strong></td>
<td scope="col" style="width: 10%"><strong><?php _e("UserAgent",'counterize'); ?></strong></td>
@@ -1115,6 +1144,7 @@
value="<?php echo $entry->id; ?>" /></td>
<td><?php echo $entry->id; ?></small></td>
<td scope="col" width="14%"><small><?php echo $entry->timestamp; ?> </small></td>
+ <td scope="col" width="10%"><small><?php echo $entry->ip; ?> </small></td>
<td scope="col" width="25%"><small><?php echo "<a href=\"" . $entry->url . "\">" . wordwrap($entry->url, 30, "\n", 1); ?>
</a> (<a
href="edit.php?page=counterizeii/counterize.php&urifilter=<?php echo $entry->url; ?>">F</a>)</small></td>
[12/2 追記]
プラグインを再び有効にしたときに、IPをmd5化しないように修正。
$ diff -u counterize_install.php.orig counterize_install.php
@@ -179,11 +179,13 @@
$wpdb->query($sql);
}
+/*
if($minorVersion < 13)
{
$sql = "UPDATE `".counterize_logTable()."` set IP=MD5(IP);" ;
$wpdb->query($sql);
}
+*/
// Set new Version
update_option('counterize_MajorVersion',2);
トラックバックURL
14件のトラックバック
[...] ・Counterize II でWordPressにカウンタを表示する – 片っ端からメモってみる ・Wordpressのアクセス解析(カウンター)プラグインCounterize IIを導入 – 無料で使える情報探す「おぼえがき」 [...]
[...] http://www.parlia.net/weblog/post/121.html/より, couterize.phpに昨日のHit数,昨日のユニークなHit数,ユニークなHit数の合計を表示する関数を追加。 # Returns amount of hits yesterday function counterize_gethitsyes [...]
[...] ≫ Counterize IIでカウンタを表示するCounterize II でWordPressにカウンタを表示する – 片っ端からメモってみるWordpressのアクセス解析(カウンター)プラグインCounterize IIを導入 | [...]
[...] 探してきた物は、プラグインのCounterize II。 こことここを参考に、インストールと画面への表示を作ってみた。 [...]
[...] 参考:Counterize II でWordPressにカウンタを表示する 感謝します。 [...]
[...] 下記サイトを参考にさせていただきました。 片っ端からメモってみる 無料で使える情報探す「おぼえがき」 [...]
[...] erize_getuniquehitstotal()); ?< <!– トータルのユニークなカウント –> <?php echo counterize_get_online_users(); ?< <!– 現在の訪問者数 –> 参考:Counterize II でWordPressにカウンタを表示する [...]
[...] Counterize II でWordPressにカウンタを表示する – 片っ端からメモってみるでは設置方法以外に管理画面でIPアドレスを表示する方法も載っています。これもなかなか便利かも。 [...]
[...] 参考:Counterize II でWordPressにカウンタを表示する [...]
[...] 参考:Counterize II でWordPressにカウンタを表示する [...]
[...] 参考:Counterize II でWordPressにカウンタを表示する [...]
[...] ・Counterize II でWordPressにカウンタを表示する – 片っ端からメモってみる [...]
[...] それから、 ついでにここを参考に、Counterize II の管理画面にIPアドレスを表示ようにしてみました。 デフォルトではIPアドレスをmd5でハッシュした値をデータベースに記録していとのこ [...]
[...] こっちも参考に昨日のuuも追加してみたけど動かない? http://www.parlia.net/weblog/post/121.html/ [...]
1件のコメント
難しいPHPとかをいじらなくても、カウンタライズを表示できるプラグインがあるそうです。
http://strong-seo.net/category/counterizeii-extension