phaedo5 Posted March 22, 2009 Share Posted March 22, 2009 I want to set up an action for a website user, but I want to be able to set a percentage of user participation. For instance, let's say I want to have something happen to 20% of the users that come to my site, like a survey or something. I know how to set cookies back and forth, but I am lost as to how I could have this happen to a set percentage of users. Any one able to help with that?? Quote Link to comment https://forums.phpfreaks.com/topic/150588-invitation-rate/ Share on other sites More sharing options...
cunoodle2 Posted March 22, 2009 Share Posted March 22, 2009 Just have php pick a random number at the time of the page loading. You could use this.. rand(1,5) and that would create a random number between 1 and 5. Depending on the the number selected you could show (or not show) the survey. Use this code... <?php $num = rand(1,5) if($num == 1) { //show survey } ?> There is no need to have an "else" to that if statement as you would simply show the survey or not. You would need to use the number 1 either. You could use any as the odds of getting any number 1-5 would be a 20% random guess. You could also do rand(1,100) and then make the if statement if($num < 21). Good luck and post your code when completed on here to hopefully help another member in the future. Quote Link to comment https://forums.phpfreaks.com/topic/150588-invitation-rate/#findComment-790998 Share on other sites More sharing options...
ram4nd Posted March 22, 2009 Share Posted March 22, 2009 I know how to set cookies back and forth, Why are you telling us that? You want to use cookies for that or ...? Quote Link to comment https://forums.phpfreaks.com/topic/150588-invitation-rate/#findComment-791003 Share on other sites More sharing options...
Maq Posted March 22, 2009 Share Posted March 22, 2009 Google has a pretty cool experiment web optimization feature you may be interested in. It lets you choose various "test" content for your site and what percentage of traffic/visitors get each test. It also gives you feedback of which one works the best, has the lowest bounce rate and many more statistics. Hope this is useful. Google - Website Optimizer. Quote Link to comment https://forums.phpfreaks.com/topic/150588-invitation-rate/#findComment-791007 Share on other sites More sharing options...
Lodius2000 Posted March 22, 2009 Share Posted March 22, 2009 Just have php pick a random number at the time of the page loading. i dunno if this is the best way (if you can use mysql) if you have only php at your disposal then using rand() is probably the best way, but if you set the survey to run on the result of 1, then for each user there is a 20% chance that they wont see the survey, it is theoretically possible to go hundreds of users without a survey being served. but if you have a database, you can make a counter, each time $page_count/5 = (int) (when the page count divided by 5 is a whole number) then you can serve the survey, this way guarantees that a survey will be served 20% of the time //sorry no code, im on lunch from work, no time // depending on how many visitors you site gets 20% of the time is probably way too many Quote Link to comment https://forums.phpfreaks.com/topic/150588-invitation-rate/#findComment-791056 Share on other sites More sharing options...
phaedo5 Posted March 23, 2009 Author Share Posted March 23, 2009 Thanks guy. Good suggestions. I think I will probably go the mySQL route. I'm still sort of new to PHP so I was just hoping to get some ideas what you might think would be best. Quote Link to comment https://forums.phpfreaks.com/topic/150588-invitation-rate/#findComment-791510 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.