9
9

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.

【不要】Yahoo!検索結果のSSL化対策まとめ(Google / Adobe Analytics)

Last updated at Posted at 2015-09-07

Adobe / Googleの機能改修により、以下の手続きは一切不要になっています(2015/10/5追記)。

ついにYahoo!の検索結果ページのHTTPS化が始まった。今後すべての検索結果ページがHTTPSになっていく。

これに伴い、自然検索流入のキーワードを取得できなくなったのはともかく、それに加えてYahoo!のHTTPSの検索結果ページからの流入がアクセス解析ツールで**「自然検索流入」ではなく「Yahoo!からのリンク流入」**扱いでカウントされるようになった。

これはまずいのでYahoo!のHTTPSの検索結果ページからの流入を自然検索扱いにしたい。そのためのカスタマイズまとめ。

Adobe Analyticsの場合

Adobe AnalyticsをYahoo!検索SSL化に対応させる方法の通り。

s_code.jsのdoPlugins(s){...}の中に以下を追記する。

if (document.referrer == 'http://search.yahoo.co.jp' || document.referrer == 'http://search.yahoo.co.jp/') {
  s.referrer = document.referrer + 'search?p=::empty::';
}

具体的には以下のようになる。

s_code.js
s.usePlugins=true;
function s_doPlugins(s) {

    :
  // すでに記述されている内容
    :

  if (document.referrer == 'http://search.yahoo.co.jp' || document.referrer == 'http://search.yahoo.co.jp/') {
    s.referrer = document.referrer + 'search?p=::empty::';
  }

}
s.doPlugins=s_doPlugins;

(参考)
http://google.cms-ia.info/sitecatalyst/jp/modify-ssl-yahoo-referrer

Google Analyticsの場合

「参照元 / メディア」の「search.yahoo.co.jp / referral」を「yahoo / organic」に書き換えることによって実現する。これにはビューのフィルタ(管理画面上だけ)で書き換える方法と、タグだけで書き換える方法がある。

ビューのフィルタで書き換える場合

Googleアナリティクスで [search.yahoo.co.jp / referral] を [yahoo / organic] として計測する方法の通り。

ただし実際に設定するのは1.と2.までにとどめておいたほうがいい。
3.を実装してしまうと、まだキーワードを取得できるケース(徐々に減少していくが)のキーワードも消してしまうことになる。

トラッキングコードで書き換える場合

実はタグの書き換えだけで実装することも可能。

トラッキングコードのga('create', 'UA-XXXXXXX-Y', 'auto');ga('send', 'pageview');の間に以下を挿入する。

if (document.referrer == 'http://search.yahoo.co.jp' || document.referrer == 'http://search.yahoo.co.jp/'){
  var s = window.location.search;
  s.indexOf('utm_source=') == -1 && ga('set', 'campaignSource', 'yahoo');
  s.indexOf('utm_medium=') == -1 && ga('set', 'campaignMedium', 'organic');
  s.indexOf('utm_term=') == -1 && ga('set', 'campaignKeyword', '(not provided)');
}

document.referrerが該当する条件のときに、utm_***のパラメータがなければ書き換える。
あればそちらの内容を優先して適用する。

具体的には以下のようになる。

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXXXX-Y', 'auto');
    :
  // 既存の設定があればここに記述
    :
  if (document.referrer == 'http://search.yahoo.co.jp' || document.referrer == 'http://search.yahoo.co.jp/'){
    var s = window.location.search;
    s.indexOf('utm_source=') == -1 && ga('set', 'campaignSource', 'yahoo');
    s.indexOf('utm_medium=') == -1 && ga('set', 'campaignMedium', 'organic');
    s.indexOf('utm_term=') == -1 && ga('set', 'campaignKeyword', '(not provided)');
  }
  ga('send', 'pageview');
</script>
9
9
0

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
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?