Google Analytics内容实验A / B测试不刷新页面的服务器端代码 [英] Google Analytics Content Experiments A/B testing server-side code without page refresh

查看:177
本文介绍了Google Analytics内容实验A / B测试不刷新页面的服务器端代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我们希望A / B测试2个不同的页面布局标题。有一些结构性差异(它不仅仅是切换CSS)。我们也不想等谷歌翻转硬币来确定访问者应该看到哪种变化;相反,我们想选择变体服务器端,并避免页面重定向。



下面的代码做我希望的;它生成的UTMX cookie看起来与Google提供的javascript生成的cookie相同,如果我没有从头标记中忽略它的话。



服务器端PHP代码:

$ $ p $ 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);

$ b private function getExperimentsFromUtmxCookie($ cookieName)
{
if(isset($ _ COOKIE [$ cookieName])){
$ cookieVal = $ _COOKIE [$ cookieName];
$ experimentsArray = array();
$ experimentMatches = preg_split('/ \。/',$ cookieVal);
$ domainHash = array_shift($ experimentMatches); //删除第一个项目。所有将保留在$ experimentMatches中的是一组带有combos的experimentIds数组。
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($实验为$ key => $ val){
$ experimentsString。='。'。 $键。 ':'。 $ VAL;
}
return $ experimentsString;
}

为什么我的Google Analytics内容实验仪表板不显示我的实验的访问者, 然后?我不完美地设置utmx cookie吗?除了设置UTMX cookie之外,GACE还在寻找其他任何东西吗? 解决方案

我们一直使用完全不同的方法过去几个月:亚马逊负载平衡器(AWS ELB)加上Google Analytics(而不是内容实验)。 (请参阅我上面的评论。)正如我们所希望的那样,它极大地改善了我们融入后备箱的经验。


$ b $

  _gaq.push(['_ setCustomVar',2,varName,varValue,2]); // https:// developers .google.com / analytics / devguides / collection / gajs / gaTrackingCustomVariables 
_gaq.push(['_trackPageview']); //必须在setCustomVar
// varName应该是你想要的调用实验
// varValue应该是原始的原始和变体的变体。我们只使用主干和变体分支名称。

明显的缺点是Google不会为我们做数学(告诉我们这种变化是否具有统计学意义明显优于原来的),并且我们不能一次轻松地运行多个实验。我们也不会有很多变体(我们需要添加比我们想要的更多的负载均衡实例)。



但为了我们的目的(例如,给予我们不重新刷新页面的重要性),它比其他方法更好。


Basically, we want to A/B test 2 different page layout headers. There are some structural differences (it's not just switching out the CSS). We also don't want to wait for Google to flip the coin to determine which variation the visitor should see; instead, we want to choose the variation server-side and avoid a page redirect.

The code below does what I hoped it would; the UTMX cookie it generates looks identical to the one that the Google-supplied javascript would generate if I didn't omit it from the head tag.

Server-side PHP code:

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;
}

Why isn't my Google Analytics Content Experiments dashboard showing any visitors to my experiment, then? Did I set the utmx cookie imperfectly? Other than setting the UTMX cookie, is GACE looking for anything else?

解决方案

We've been using a totally different approach for the past couple months: Amazon load-balancers (AWS ELB) plus Google Analytics (not Content Experiments). (See my comment above.) As we hoped, it has greatly improved our experience with merging back to trunk.

_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].

Obvious drawbacks are that Google doesn't do the math for us (telling us whether the variation has statistically significantly outperformed the original) and that we can't easily run multiple experiments at once. We also wouldn't be able to have many variations (we'd need to add more load-balanced instances than we'd want).

But for our purposes (e.g. given how important it is to us not to have a page refresh), it has worked better than other approaches.

这篇关于Google Analytics内容实验A / B测试不刷新页面的服务器端代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆