随机重定向,如A / B测试

时间:2018-01-26 13:46:22

标签: javascript jquery redirect ab-testing

我想用A / B测试来测试我网站的一部分。 为此,我想通过单击按钮将用户随机重定向到两个不同的URL之一。

用户在例如/ register现在我想通过点击/ ​​register

上的“立即注册”按钮将他随机发送到/ success-v1或/ success-v2

这是HTML

<div class="button" id="testbutton">
  Go for it
</div>

JS:

$(document).ready(function(){
    $('#testbutton').click(function(){
        if(Math.random() > 0.5) { 
            window.location.href = "http://host/versionA";
            } else {
            window.location.href = "http://host/versionB"; 
            }
    });
});

但不知何故,它不起作用:/

谢谢!

1 个答案:

答案 0 :(得分:1)

这可以在父页面中:

if(Math.random() > 0.5) { 
    window.location.href = "http://host/versionA"; 
} else {
    window.location.href = "http://host/versionB"; 
}
相关问题