2

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.

markom
  • 2,040
  • 1
  • 21
  • 29
  • So, your question boils down to: "is indexing on uniqueidentity fields bad for performance in sqlserver (version unknown)... and btw, how do you keep profile data for anonymous users". Looks like material for two different questions. – bzlm Mar 24 '09 at 21:14
  • Not really, performance is just one part of the question. I'd like to hear maybe some other ideas for the scenario I outlined: tracking anonymous user activity. – markom Mar 24 '09 at 21:16
  • Re #3; looks like your TrackingToken could just be an auto-incremented identity column in a table in SQL Server. Isn't that enough? – bzlm Mar 25 '09 at 07:59
  • Sure, but in what table? It can't be in VoteHistory because, as you can see in the example, the value of the token in that column is not unique. Or did I misunderstood you? – markom Mar 25 '09 at 12:25

4 Answers4

2

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:

efficient ways to anonymous personalization using ASP.NET + Cookie

How can I create a local user profile for the anonymous user of an ASP.Net MVC application under IIS 7?

How can I support anonymous users with my application?

All pertain to anonymous profiles in ASP.NET.

Community
  • 1
  • 1
bzlm
  • 9,626
  • 6
  • 65
  • 92
1

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
  • 5,354
  • 3
  • 33
  • 46
0

What is the problem with creating guest user accounts each time new user is performing some action (e.g. votes)? When that happens, you save a cookie with UUID or some other unique id (not an integer as you are suggesting, for added security) and once this user registers, all you have to do is change user group from 'guest' to 'member'. Simple.

mvbl fst
  • 5,213
  • 8
  • 42
  • 59
0

(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
  • 12,106
  • 12
  • 71
  • 90