views:

826

answers:

2

In the SharePoint publishing site I will have some banners that are Web Parts and can have any HTML content inside them. I have requirement to count clicks on that banners. Banners will have some links to external sites.

I am not sure where to store counters for individual banners. Custom List is the first thing that came to my mind but I am not sure how will it behave in concurrent access. Can I lock list (list item) and do the counter increment ? What will happen for other list access if it is in lock state ? Will it fail or just wait ?

Are there any alternatives to storing counters somewhere else ?

+2  A: 

There are lots of places, here are the two most popular:

  1. Property Bag (most likely on the Web) which is a number you increment
  2. Inside a list

Of these, I have successfully done it with a list on our blogging solution, you can see it here: http://community.zevenseas.com/blogs, where I'm tracking views for each post. I took this approach because I like to see more than a number, eg. referrer, ip, etc.

Things to keep in mind:

  1. You need to keep a close eye on the number of items you are storing. SharePoint doesn't like lots of items in a list. To manage them put them in folders, a folder for each banner, and then subfolders for each month.

  2. I would keep a list with each of the banners (just their name or more) in it, then create a second list to store the views. In the list where you store the views have a lookup back to the list storing the banners. On the original banner list you can then create a new column which "Counts" the number of Views related to each banner item.

Again, be very careful about the number of items you are expecting, but this works pretty nicely for us.

Daniel McPherson
I don't see that number of views on your site is updating. Should I worry about simultaneous list access ? I planed to have only one list item for every banner and than just increment counter.
Robert Vuković
It doesn't update instantly, because the information is cached, but check back in 15 minutes or so, the numbers are changing.
Daniel McPherson
+1  A: 

Don't forget a small database will allow you to store page hits against whatever you want. You can then call a stored proc and that database "just takes care of it". You don't have to worry about access and concurrency (because you used a transaction riiiight!).

A SharePoint list is easy because they are there out of the box, but consider that they have a lot of overhead for adding values and even reading from. They are also editable by a site administrator, which may be find, depending on the number of administrators you have. A list is easier to provision than a new database, so in the end you do need to consider the two options carefully.

Just because SharePoint has a hammer does not mean everything is a nail :)

Nat