views:

299

answers:

3

I need to track anonymous users with enabled cookies.

Basically, they will go through the site, interact with it, and I would like to give them the best possible experience without requiring actual registration. Later on, if they want, they can register and their site activity will be tied to their new account.

Something like Stackoverflow but with the difference that I expect that majority of my users won't actually register but occasionally just comeback.

So, I don't want to create a bunch of dummy records in the Users table. And since I need it just for one table, I was thinking about something like this:

VoteHistory table

Id    TrackingToken    VotingData
1     100             ...
2     100             ...
3     101             ...
4     102             ...

Users table

Id    TrackingToken    OtherUsersColumns
1     100             ...

TrackingTokens table

LastTrackingToken
102

I would increment a LastTrackingToken integer field and simply add that value to the users cookie and track his voting activity with it. Then, if he decides to register, I would simply add his cookie TrackingToken value to his Users record.

Initially I was thinking about a Guid/uniqueidentifier but since the voting table will be very large and I will need to query it, I'm worried about indexing the uniqueidentifier field.

So, the questions are (sorry for 3 sub-questions, but they are so related and I think the context is important, so I don't want to duplicate the question and context description):

  1. Is integer field better when it comes to performance and indexing? Have in mind that TrackingToken is not a primary key field!

  2. Do you have some other idea how I could accomplish the scenario I outlined?

  3. If I decide to go with the manual generation of integer TrackingTokens, what would be the best way to reliably generate/increment a new TrackingToken? Assume a lot of concurrent users will hit the database.

+1  A: 

A Guid is not bad for an index. One thing to think about, a Guid won't be nearly as easy to fudge in the cookie if someone wants to try to game your system.

Moose
I would encrypt the value in the cookie, so that's not really an issue I think.
muerte
Ah. Yeah. Been a long day.
Moose
+2  A: 

To answer the 2nd of your questions in this multi-question (Do you have some other idea how I could accomplish the scenario I outlined), please see these:

http://stackoverflow.com/questions/234044/efficient-ways-to-anonymous-personalization-using-asp-net-cookie

http://stackoverflow.com/questions/526745/how-can-i-create-a-local-user-profile-for-the-anonymous-user-of-an-asp-net-mvc-ap

http://stackoverflow.com/questions/647038/how-can-i-support-anonymous-users-with-my-application

All pertain to anonymous profiles in ASP.NET.

bzlm
The links you provided are almost completely unrelated to the question.
muerte
A: 

(for question 3) If you decide to use manual generation for TrackingTokens just make sure you reserve your integers in a transaction and you're pretty much guarenteed that you'll have unique ones. You can also consider letting SQL server automatically assign them for you and they'll be unique too.

ajma