Hello, I want to show a message on my website asking users for feedback, but I only want it to be shown to returning users. It would be even better if I could show it only to people who have come to my site at least say 5 times. I have Google Analytics installed, and I can see it tracks user loyalty, so maybe is there a way to use Analytics variables to check whether a user is frequent or not?
You should use cookies, first write the cookies in the user's browser starting with a count of 1 and increment the count one by one(each and everytime you are going to right the cookie) Check the cookie for the loyal visitor then At the sixth visit you can redirect to the feedback page, you can do with asp, php, asp.net... not with html.(you can use javascript too)
It's a nice idea to use cookies, but the downside is that if cookie is disable on the user's browser, then it won't work. Another solution might be the use of IP address. You could save their IP, query and increment on every visit. A bit more complex but hey, it solves the problem. Good luck
Using PHP, you can track each IP using mysql. Set it to only count 1 hit every 24+ hours. Here is a rough idea of how you could do it... create table... CREATE TABLE IF NOT EXISTS `table` ( `ip` text NOT NULL, `online` text NOT NULL `hits` text NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 PHP: <? // MySQL Connection $connect = mysql_connect( 'localhost', 'username', 'password' ) or die(mysql_error()); mysql_select_db( 'database' ); $ip=$_SERVER['REMOTE_ADDR']; $timestamp = time(); // checks if IP is in database $getStats2 = mysql_query("SELECT * FROM `table` WHERE `ip`='$ip'") or die(mysql_error()); if( mysql_num_rows( $getStats2 ) == 0 ) { $select2 = mysql_query("INSERT INTO `table` (`ip`, `online`, `hits`) VALUES ('$ip','$timestamp','1')") or die(mysql_error()); } else { // checks to see if last hit was before or after 24 hour mark. $diff = time() - 86400; $counthits = mysql_query("SELECT * FROM `table` WHERE `online` > '$diff' && ip='$ip'") or die(mysql_error()); if (mysql_num_rows($counthits)==0){ // unique hit while ($t=mysql_fetch_array($counthits)){ $hits=$t['hits']; } //checks if there is 5 hits yet... if ($hits=="5"){ // do message! } else { $select2 = mysql_query("UPDATE `table` SET `online` = '$timestamp', `hits`=`hits`+1 WHERE `ip` = '$ip'"); } } else { //not unique, does nothing... } } ?> PHP:
Cookies is the only way to do this with any sort of accuracy, while using the IP address is the least accurate unless you are sure that every visitor has their own unique IP address (extremely unlikely.....near to impossible). Cookies - advantages -Easy & Simple -Can store a surprising amount of information or allow you to store and retrieve database information based on cookie content -Most people allow them from the 1st party site -More accurate in identifying people in that it identifies a computer Cookies - Disadvantages -Visitor may not support them -Only identifies a computer not a user -If the user uses different computers the cookie may not exist unless they have used that PC before - easy for the visitor to delete. IP- advantages -visiting IP address can't be easily hidden. It can be spoofed but the average user isn't going to do that. -Potentially identifies the country of origin of the visitor - probably doesn't change much for the same visitor (or changes within a range) but the same IP could be used by thousands of web users at the same time. IP - disadvantages - not accurate for identifying a person. ISPs share the same IP for hundreds or thousands of their users. Even if the connection is using a dedicated IP it could be anyone in a company, or any PC behind a connection such as a group of PC's and users sharing the dedicated IP from a large office. - not much more, but if you're attempting to track individual users, using the IP address is almost pointless. There's no real fool-proof method of identifying the average single user except by getting them to log into the site (assuming they don't share their username & password). It's so difficult tracking/identifying individuals that even companies like Ebay or Paypal usually have, when potentially identifying an individual, words along the lines of "not you. Click here", so the visitor has to log in again to be properly identified.
There are 0.1% cases when cookies or javascript are switched off. But there are 50% when different clients access from the same IP. so you can mess the word completely!