Using session variables for tracking?

lschmidt

New member
Jun 11, 2007
1,251
48
0
I have some sites where I want to keep track of where the user came from (ie email, ppc, search engine, social media, etc) and sometimes it can get messy passing things through the URL all the time especially if there are lots of intermediary pages between them landing on the site and where I get a payout/sale.

So...any downsides to just using a session variable to track their origin source until they leave my site?
 


I guess you use a homegrown tracker?

Not really a downside. It's easier to develop. Just set your cookie duration to a long time.
 
I have some sites where I want to keep track of where the user came from (ie email, ppc, search engine, social media, etc) and sometimes it can get messy passing things through the URL all the time especially if there are lots of intermediary pages between them landing on the site and where I get a payout/sale.

So...any downsides to just using a session variable to track their origin source until they leave my site?

The main downside to sessions is as you said, only survives within your server. Aside from that just taking up a tiny bit of extra memory storing the data server-side. No real downside and probably more discreet that way as well as working even when he user may have cookies (or javascript) disabled. If you have a shit-ton of data you want to keep track of you can even keep organized storing a associative array as a session value so that something like $user_data = $_SESSION['user_data'] could later be used as $user_data['email']
 
Karl, is there any reason you can't store a serialized array in a cookie and achieve the same thing?

Other than that, Karl is right on the money. They're basically the same thing. Sessions can be more stable if the user isn't accepting cookies (because PHP will attach a SESSID to the URL if you tell it to), but that's almost no one; sessions are less manipulate-able (only the SESSID can be changed by the user - everything else is stored server side) than cookies as well though, so maybe that's a perk.