18
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GoogleAnalyticsを使ったユーザの外部遷移の追跡

Last updated at Posted at 2013-02-08

自分のサイト内の外部遷移のURL(アフィリエイト等)をクリックされた際に、
どのページからどの外部URLに遷移したのかをGoogleAnalyticsで簡単に調査できるように
するための方法。

GoogleAnalyticsの_trackEventを使う。

sample.js
<script type="text/javascript">
//<![CDATA[
$(function(){
  $("a").on("click", function(){
    url = $(this).attr('href');
    if(url.indexOf($(location).attr('hostname')) == -1 && url.indexOf('http') >= 0)
    {
      _gaq.push(['_trackEvent','Link', $(location).attr('href'), url]);
    }
  });
});
//]]>
</script>
_gaq.push(['_trackEvent', category, action, opt_label, opt_value, opt_noninteraction])

という書式なので、action, opt_label等は分析したいように適当に

このコードを設置後、
GoogleAnalyticsのコンテンツ=>イベント=>上位のイベント
で確認すると以下のように外部遷移イベントを確認できるようになる。

trackEvent

上記のJSを設置した場合、

  • イベントアクションに遷移元ページ(自分のサイト)
  • イベントラベルに外部遷移したページ

が入る。

イベントアクションを外部遷移したページにしたほうがいいかもしれない。

18
18
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?