[英]Google Analytics Content Experiments A/B testing server-side code without page refresh
基本上,我們希望A / B測試2個不同的頁面布局標題。 存在一些結構差異(它不僅僅是切換CSS)。 我們也不想等待谷歌翻轉硬幣來確定訪問者應該看到的變化; 相反,我們希望選擇變體服務器端並避免頁面重定向。
下面的代碼完成了我希望的那樣; 如果我沒有從head標簽中省略它,那么它生成的UTMX cookie看起來與Google提供的javascript會生成的cookie相同。
服務器端PHP代碼:
public function setUtmxCookie($cookieName, $experimentsString)
{
$domainHash = $this->getDomainHash($_SERVER['SERVER_NAME']);
$cookieVal = $domainHash . $experimentsString;
$expire = time() + 60 * 60 * 24 * 30;
$domain = '.' . $_SERVER['SERVER_NAME'];
setrawcookie($cookieName, $cookieVal, $expire, '/', $domain);
}
private function getExperimentsFromUtmxCookie($cookieName)
{
if (isset($_COOKIE[$cookieName])) {
$cookieVal = $_COOKIE[$cookieName];
$experimentsArray = array();
$experimentMatches = preg_split('/\./', $cookieVal);
$domainHash = array_shift($experimentMatches); //remove the first item. All that will remain in $experimentMatches is an array of experimentIds with their combos.
foreach ($experimentMatches as $m) {
$segments = preg_split('/:/', $m);
$experimentsArray[$segments[0]] = $segments[1];
}
return $experimentsArray;
}
return array();
}
private function getExperimentsString($cookieName, $experimentId, $variation)
{
$experiments = $this->getExperimentsFromUtmxCookie($cookieName);
$experiments[$experimentId] = $variation;
$experimentsString = '';
foreach ($experiments as $key => $val) {
$experimentsString .= '.' . $key . ':' . $val;
}
return $experimentsString;
}
為什么我的Google Analytics內容實驗信息中心沒有顯示我的實驗的所有訪問者呢? 我是否將utmx cookie設置得不完美? 除了設置UTMX cookie之外,GACE還在尋找其他什么嗎?
在過去的幾個月里,我們一直在使用完全不同的方法:亞馬遜負載均衡器(AWS ELB)和Google Analytics(不是內容實驗)。 (參見上面的評論。)正如我們所希望的那樣,它大大改善了我們合並回主干的經驗。
_gaq.push(['_setCustomVar', 2, varName, varValue, 2]);//https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables
_gaq.push(['_trackPageview']);//This must come AFTER the setCustomVar
//varName should be whatever you want to call the experiment
//varValue should be something like "original" for the original and "variation" for the variation. We just use "trunk" and [name of variation branch].
顯而易見的缺點是谷歌沒有為我們做數學計算(告訴我們變異在統計上是否明顯優於原始數據),並且我們不能輕易地同時進行多個實驗。 我們也不能有很多變化(我們需要添加比我們想要的更多負載平衡的實例)。
但是出於我們的目的(例如,考慮到我們不重新刷頁的重要性),它比其他方法更有效。
@ danmaz74在客戶端使用Google Analytics也采用了一種有趣的方法:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.