Jump to content

Invitation Rate


phaedo5

Recommended Posts

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??

Link to comment
https://forums.phpfreaks.com/topic/150588-invitation-rate/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/150588-invitation-rate/#findComment-790998
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/150588-invitation-rate/#findComment-791007
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/150588-invitation-rate/#findComment-791056
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.