xその他‎ > ‎

ABテストの始め方

Google Web Site Optimiserがあるので、そちらを使えばいいのですが、
あえて、Google Analtyicsでやる事を考えようと思います。

用意するもの:


データ設定側:

  • その後、cookieを読んで、該当キーに値があるかどうかを調べる。
    • 下は、customVarのslot1にABTEST : A or Bという形があるかどうか?
    • document.cookie.search(/\|1\=ABTEST\=[AB]\=1/) 
  • cookieに該当値がなければ、作っておいた乱数を設定値とします。
    • _setCustomVar(1, "ABTEST", (Math.random() > 0.5 ? "A" :"B"),1)

  • cookieの値によって、Dom操作で表示ドキュメントを変える。
    • $("振り分けした文字").insertAfter(#id)
    • jQueryだとこんな感じ。
  • googleにデータを送ります。pageTracker._trackPageview();です。
  • これで、レポート側にデータが送られる。
ちなみに僕のサイトで使ってるもののだと、

if(document.cookie.search(/\|1\=ABTEST\=[AB]\=1/)!=-1){
 _gaq.push(["_setCustomVar",1, (Math.random()>0.5 ? "A" : "B"),1]);
}

_gaq.push(function(){
 var p = _gat._getTracker("UA-xxxxx-xx");
 if(p._getVisitorCustomVar(1) == "A"){
    window["prm_txt"] = "   PR: このblog本人からのお知らせ。勉強会の講師します。";
 }else{
    window["prm_txt"] = "   PR: 勉強会の講師します。";
}
$("<a style='color:red;' href='business'>"+ window["prm_txt"] +"</a>").
    insertAfter("span.post-cat").
    bind("click", function(){ p._trackEvent("ABTest",
                                          "click",
                                          document.location.pathname,
                                          Math.round((new Date()).getTime() -startTime)/1000))});

レポート側:

  • カスタムレポートで、カスタム変数1のをディメンジョンに選びます。
  • ユニークユーザと、セッション数などを指標にセット。
  • ゴール数もセット。


Comments