Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
Like Tree1Likes
  • 1 Post By Philip M

Thread: Redirecting a percentage of traffic...

  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Redirecting a percentage of traffic...

    Hello all,

    New poster here. I used the search function and I didn't see any threads that address this so I apologize if I missed it.

    Basically, right now I'm redirecting all traffic on a page using the simple code below:

    Code:
    <script type="text/javascript">
    location.replace("http://www.site.com/page.php")
    </script>
    I'm wondering if there is a way I can redirect only a percentage of the traffic hitting this page?

    For example, send 20% or 50% etc. of all visitors to the redirect but not the others.

    The reason for this is I'm using a split-testing script to test changes to the page. for drastic changes I'd like to "test the waters" by sending only a portion of the traffic first.

    Anyone know the most simple way to accomplish this?

  • #2
    Regular Coder
    Join Date
    Nov 2007
    Posts
    144
    Thanks
    64
    Thanked 0 Times in 0 Posts
    You would have to use PHP or something to have it dynamically add the redirect statement in based on a counter.

    It has to be done server side.

    You may be able to do this via Apache and mod_rewrite, however I don't know if that supports changing it based on a percentage.. although, with linux, everything is possible.

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    you must store somewhere a number, server side, retrive when the page is loaded, increment or reset when rich a maxim value and save it back.
    For example if you want to redirect 20&#37; of users you must redirect 1 from 5 that means when you get 5 you make it 1 and redirect this user,
    Same thing but up to 2 for 50%.
    I'm not sure but I guess you can't use only javascript for that.

    best regards

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,912
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Another and simpler approach is to redirect based on time.

    Code:
    <script type = "text/javascript">
    var now = new Date().getTime();  // time in milliseconds
    if (now&#37;5 == 0) {  // 20% of occasions
    window.location = "http://www.yoursite.com/newpage.html";
    }
    </script>
    This will redirect 20% of visitors which is not exactly the same as every fifth visitor, but OK for the purpose.



    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    JackC likes this.

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Philip M View Post
    Another and simpler approach is to redirect based on time.

    Code:
    <script type = "text/javascript">
    var now = new Date().getTime();  // time in milliseconds
    if (now&#37;5 == 0) {  // 20% of occasions
    window.location = "http://www.yoursite.com/newpage.html";
    }
    </script>
    This will redirect 20% of visitors which is not exactly the same as every fifth visitor, but OK for the purpose.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    this assume that you have constantly a given number of visitors in a time unit which could be wrong, day/night, holiday or not,
    But this solution get rid of server side and in my opinion could be improved, if is not enought accurate, with the risk of some complication.
    It's just a idea, but I think that a combined correction based on time of the day, day of the week, day of the month, month of the year and some coefficients could increase accuracy.
    Of course increase accuracy implies complication but not useless complication, .

    Edit: seems that was a good idea to not jump on conclusion that could not be done without server side code,

    best regards
    Last edited by oesxyl; 09-05-2008 at 02:32 PM.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,912
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by oesxyl View Post
    this assume that you have constantly a given number of visitors in a time unit which could be wrong, day/night, holiday or not,
    Sorry, it makes no such assumption.

    But this solution get rid of server side and in my opinion could be improved, if is not enought accurate, with the risk of some complication.
    It's just a idea, but I think that a combined correction based on time of the day, day of the week, day of the month, month of the year and some coefficients could increase accuracy.
    , .

    Edit: seems that was a good idea to not jump on conclusion that could not be done without server side code,

    best regards
    What is the point? The OP wishes to redirect a certain percentage of his visitors. What does it matter whether they are day or night, Mondays or Fridays, January or June or whatever?

    Assuming a reasonable number of visitors then my script will redirect +-20&#37; of them, and that will be +-20% regardless of the day of the week etc.

    Monday 100 visitors +-20 redirected (perhaps 19 this week, 21 next week)
    Tuesday 200 visitors +-40 redirected
    Friday 10 visitors - too low a count to be sure that exactly 2 are redirected.

    Over time the percentage redirected will be (virtually) exactly 20%.
    What more does the guy want?


    "The generation of random numbers is too important to be left to chance."

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Philip M View Post
    Sorry, it makes no such assumption.



    What is the point? The OP wishes to redirect a certain percentage of his visitors. What does it matter whether they are day or night, Mondays or Fridays, January or June or whatever?

    Assuming a reasonable number of visitors then my script will redirect +-20% of them, and that will be +-20% regardless of the day of the week etc.

    Monday 100 visitors +-20 redirected (perhaps 19 this week, 21 next week)
    Tuesday 200 visitors +-40 redirected
    Friday 10 visitors - too low a count to be sure that exactly 2 are redirected.

    Over time the percentage redirected will be (virtually) exactly 20%.
    ok, what is wrong in this code, except that is probably ugly,
    Code:
    <?xml version="1.0"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Statistic Medness, :)</title>
        <script type="text/javascript" src="test80.js"></script>
      </head>
      <body onload="go_and_test();">
        <div>
          <p>Total 1: <b id="tot1"></b></p>
          <p>Redirected 1: <b id="red1"></b></p>
          <p>Total 2: <b id="tot2"></b></p>
          <p>Redirected 2: <b id="red2"></b></p>
        </div>
      </body>
    </html>
    Code:
    /* -*- c++ -*-
     */
    function is_redirected(){
      var now = new Date().getTime();
      return ((now % 5) == 0);
    }
    
    var total1 = 0;
    var howmany1 = 0;
    var toto1 = null;
    var redo1 = null;
    
    var total2 = 0;
    var howmany2 = 0;
    var toto2 = null;
    var redo2 = null;
    
    function show_visitors(){
      if(!toto1){
        toto1 = document.getElementById('tot1');
      }
      if(!redo1){
        redo1 = document.getElementById('red1');
      }
      if(!toto2){
        toto2 = document.getElementById('tot2');
      }
      if(!redo2){
        redo2 = document.getElementById('red2');
      }
      if(toto1){
        toto1.innerHTML = total1;
      }
      if(redo1){
        redo1.innerHTML = howmany1 + ' ' + Math.round(10000*howmany1/total1,2)/100;
      }
      if(toto2){
        toto2.innerHTML = total2;
      }
      if(redo2){
        redo2.innerHTML = howmany2 + ' ' + Math.round(10000*howmany2/total2,2)/100;
      }
    }
    
    function increment_visitors1(){
      total1++;
      if(is_redirected()){
        howmany1++;
      }
      show_visitors();
    }
    
    function increment_visitors2(){
      total2++;
      if(is_redirected()){
        howmany2++;
      }
      show_visitors();
    }
    
    function go_and_test(){
      show_visitors();
      setInterval(increment_visitors1,5000);
      setInterval(increment_visitors2,3000);
    }
    In my opinion the difference between case 1 and 2 have a statistic explanation, pretty long one, .

    What more does the guy want?
    something simple, I don't know how important is for op to have a accurate percent of redirections but I guess he/she want something predictable,

    "The generation of random numbers is too important to be left to chance."
    agree,

    best regards

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,912
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by oesxyl View Post
    ok, what is wrong in this code, except that is probably ugly,
    Code:
    <?xml version="1.0"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Statistic Medness, :)</title>
        <script type="text/javascript" src="test80.js"></script>
      </head>
      <body onload="go_and_test();">
        <div>
          <p>Total 1: <b id="tot1"></b></p>
          <p>Redirected 1: <b id="red1"></b></p>
          <p>Total 2: <b id="tot2"></b></p>
          <p>Redirected 2: <b id="red2"></b></p>
        </div>
      </body>
    </html>
    Code:
    /* -*- c++ -*-
     */
    function is_redirected(){
      var now = new Date().getTime();
      return ((now &#37; 5) == 0);
    }
    
    var total1 = 0;
    var howmany1 = 0;
    var toto1 = null;
    var redo1 = null;
    
    var total2 = 0;
    var howmany2 = 0;
    var toto2 = null;
    var redo2 = null;
    
    function show_visitors(){
      if(!toto1){
        toto1 = document.getElementById('tot1');
      }
      if(!redo1){
        redo1 = document.getElementById('red1');
      }
      if(!toto2){
        toto2 = document.getElementById('tot2');
      }
      if(!redo2){
        redo2 = document.getElementById('red2');
      }
      if(toto1){
        toto1.innerHTML = total1;
      }
      if(redo1){
        redo1.innerHTML = howmany1 + ' ' + Math.round(10000*howmany1/total1,2)/100;
      }
      if(toto2){
        toto2.innerHTML = total2;
      }
      if(redo2){
        redo2.innerHTML = howmany2 + ' ' + Math.round(10000*howmany2/total2,2)/100;
      }
    }
    
    function increment_visitors1(){
      total1++;
      if(is_redirected()){
        howmany1++;
      }
      show_visitors();
    }
    
    function increment_visitors2(){
      total2++;
      if(is_redirected()){
        howmany2++;
      }
      show_visitors();
    }
    
    function go_and_test(){
      show_visitors();
      setInterval(increment_visitors1,5000);
      setInterval(increment_visitors2,3000);
    }
    In my opinion the difference between case 1 and 2 have a statistic explanation, pretty long one, .


    something simple, I don't know how important is for op to have a accurate percent of redirections but I guess he/she want something predictable,


    agree,

    best regards


    I am afraid that I do not see how your code captures the total number of visitors, or the number redirected. It requires a server-side language to capture this information. With the greatest respect, it is not only ugly but pointless.

    My code redirects 20% of visitors. Period. That is entirely predictable. And entirely accurate (for practical purposes). Out of 1000 visitors, 200 (or conceivably 199 or 201) will be redirected. It does not matter in the slightest whether those visits (or what proportion of them) were day or night, Monday or Friday, January or June. That is not the information that is wanted.

    The OP is not requesting some sort of complicated statistical analysis. He wants to redirect 20% of his visitors so that he can test the effectiveness of alternative pages in terms of sales.

    1000 vistors to his site.
    200 were redirected. 60 (30%) of these purchased a widget
    800 were not redirected. 200 (25%) of these purchased a widget.

    Conclusion: the alternative page results in improved sales.

    Of course, the OP can tell if the order came from the redirected page or not simply by including a code as a hidden field in his order form.

    I ask again - what more does he want?


    "If it ain't broke, keep on at it until it is".

  • #9
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Philip M View Post
    I am afraid that I do not see how your code captures the total number of visitors, or the number redirected. It requires a server-side language to capture this information. With the greatest respect, it is not only ugly but pointless.
    I'm affraid you don't understand. The code I post was not for op, was for you.
    Anyway I don't want to continue this, is useless and a waste of time for both of as and for op.

    best regards

  • #10
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,912
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Sorry, we seem not to have been on the same wavelength.

  • #11
    New to the CF scene
    Join Date
    May 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Another and simpler approach is to redirect based on time.

    Code:
    <script type = "text/javascript">
    var now = new Date().getTime();  // time in milliseconds
    if (now%5 == 0) {  // 20% of occasions
    window.location = "http://www.yoursite.com/newpage.html";
    }
    </script>
    This will redirect 20% of visitors which is not exactly the same as every fifth visitor, but OK for the purpose.



    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    Thank you for this. How can i make this 50% instead of 20%?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •