使用 PHP 设置简单的 A/B 测试 [英] Setting up a simple A/B testing with PHP
问题描述
我的网站上有一个网页 - 或者实际上它是一个 Web 应用程序,而此页面类似于仪表板(必须登录).
I have a webpage on my site - or really it's a web application and this page is sort of the dashboard (have to be logged in).
我想为出现在页面右侧的面板尝试两种设计.
I'd like to try two designs for a panel that appears on the right of the page.
我有 2 个面板设计,我可以轻松跟踪每个面板的点击时间,但我如何提供这些替代版本?
I have the 2 panel designs and I can easily track when each is clicked but how do I deliver these alternative verisons?
我是否应该在页面加载时以某种方式交替加载它们(这意味着一个人会同时看到它们)
should i just somehow load them alternatively when the page is loaded (that would mean one person sees them both)
我是否应该将用户标记为 a 或 b 并且他们只能看到那个版本?
should I flag the users as being either a or b and they only ever see that version?
以及我如何均匀地交付它以便访问者 1 获得 A,访问者 2 获得 B 等
and how do I evenly deliver it so that visitor 1 gets A, visitor 2 gets B etc
推荐答案
我会对用户的 IP 地址进行散列,然后对 2 取模以得到 0 或 1 值.
I would take a hash of a user's IP address and then mod 2 to get a 0 or 1 value.
$ip=$_SERVER['REMOTE_ADDR'];
$hash=md5($ip);
$number = hexdec( substr($hash, 0, 4));
$version = $number % 2;
if( $version == 0) {
// show A
} else {
// show B
}
这很好,因为单个用户将始终看到相同的版本,并且会在两个版本之间平均分布用户.
This is good because a single user will always see the same version, and it will spread user's evenly across both versions.
这篇关于使用 PHP 设置简单的 A/B 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!