複数人で記事を書くニュースサイトを運営する際、記者毎の成績を算出したい事があります。そういう時は Google Analytics のカスタム変数を使うと便利です。
Google Analytics のカスタム変数を使う
Google Analytics にはカスタム変数というのがあって、自由な項目名に自由な値を格納することができます。カスタム変数については以下のページが最も分かりやすいです。
カスタム変数 – Google Analytics – Google Code
私も Google Analytics については勉強中でありますが、以下のコードで実現できそうです。とても簡易的ではありますが、どの投稿者がよりアクセスを集めているかを計算することができます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-1234567890-09']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); <?php if(is_single()): ?> _gaq.push(['_setCustomVar', 1, 'author', '<?php the_author(); ?>', 1]); _gaq.push(['_trackEvent', 'Posts', 'author']); <?php endif; ?> </script> |
このコードはページ末尾に書くのが良いです。WordPress の the_author() が反応するのはフッタだけでした。おそらくどこかで間違えてるのでしょうか。
コメント