基本上,我们想要 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 是否还在寻找其他东西?