Question

When we detect these items for visitors:

  • Browser name
  • Browser version
  • OS name
  • OS version
  • Screen resolution
  • Screen depth
  • Flash enabled
  • ...

Should these all be stored in the database in separate columns or should I be storing it all as a user agent string and then breaking it down in the application?

And should I use varchar(255) for this just to be safe or are there well-defined datatypes for these items? I use MySQL and PHP

Was it helpful?

Solution

It really depends on what you want to do with the information. If you plan to use the data for very detailed statistics, use separate columns so you can run detailed queries like "show all screen resolutions for users with Internet Explorer 6" and such.

If you don't expect to need such detailed statistics, storing the user agent string in one field will usually work fine.

OTHER TIPS

You should store each item in its own column. That'll allow you to easily query and summarize your data.

Parsing once on insertion is cheap. Parsing on every query is very expensive.

There are no defined datatypes for these items, so you can use varchar(255) or even smaller. It is better to add this values to database in separate fields, because it has no noticeable impact on performance + inserts are done once, read - more times, so why do not split once, on write, and not on every read? :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top