運営堂ブログ

Google analytics非同期コードで同一URLのページ遷移を取得する方法

今までのコードの場合の取得方法はGoogle analyticsで同じURLのページ遷移を取得する方法で紹介しましたが、非同期の場合はどうするのか?という説明です。

<script type="text/javascript">
var _gaq = _gaq ,, [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview', '仮想URL']);
(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);
})();
</script>

のように取得したいページで _gaq.push(['_trackPageview''のあとに仮想URLを入れるだけでOKです。
仮想URLは01.html等でもいいですがhoge/hoge.htmlのようにディレクトリを入れておくと後から探しやすくなります。