How can I count the number of views for a video? I am using the Profile2 module to display user's information.

Users add videos which any user can see. I would like to count the number of video's views, and use that number to sort the result shown by the Views module. Is it possible?

  • i don't get it ... it is not possible to gain statistics in drupal ? – Vlasin Dec 21 '12 at 9:04
  • 1
    It's very easy but have you actually researched this at all yourself? The first page of a Google search for "Drupal node statistics" would suggest not. Remember, this site is not your first-line tech support, you're expected to put the effort in yourself :) – Clive Dec 21 '12 at 9:25
  • @Clive thanks for the comment , but i am using fields from profile2 not nodes... i have already installed most popular but there is no api to extract the data ... – Vlasin Dec 21 '12 at 9:30
  • My apologies I read the question wrong :) This is actually very interesting, I can't find any statistics module for entities so I think you might have to resort to custom code for this – Clive Dec 21 '12 at 9:33

You should use the Radioactivity module

This module provides a field type which can be used as a hotness metric or a regular view counter for entities and for much much more. In essense, entities receiving attention (views or actions defined by Rules) are heated while inactive ones slowly cool down.

You can add an 'emitting' field to any entity (including a profile2 entity), and the module can be configured to do basic page counts without the decay profiles if you don't need them.

As it's a field, you can use it in Views as normal for sorting.

It has several storage options (some of which do not relay on the database), integrates with memcache etc, so it doesn't have the same performance problems as the core Statistics module that Letharion has mentioned.

Make sure you read the instructions though, it took me a while to realise that the statistics won't be counted unless the field is actually displayed on the entity type in question (not just attached to it, it needs to be visible in 'Manage Display' - nothing will be printed to the screen but it needs to be there for the stats to be counted).

  • 1
    No probs, totally spaced on this one when I was commenting earlier :) I've been using this for a while and I'm very happy with it. You can defer writing of stats to storage so it's even appropriate for high-traffic sites. Everyone wins :) – Clive Dec 21 '12 at 9:54
  • I've never had a need for Radioactivity and it really bugs me because it looks pretty awesome :( – Chapabu Dec 21 '12 at 9:57

I believe the reason there is not common "Out of the box" solution for this, is that the statistics module has a long-standing reputation of ruining performance, as it performs a lot of database writes.

While it could certainly be "upgraded" to being entity agnostic, I guess there's little interest in doing so.

The most common solution then, I think is to use a tool like Google analytics for counting impressions, and exposing your video (or other entity) in ways/with urls that make their views easily countable in your tool of choice.

For Views integration, the easiest options seems to be Google analytics statistics, (Thanks Chapabu), but other interesting modules could also be GA counter, GA reports and GA importer

  • great answer , exactly what i have expected, but now i got another question , can it be integrated with views ? Is there any documentation on this ? – Vlasin Dec 21 '12 at 9:49
  • You could try Google Analytics Statistics :) – Chapabu Dec 21 '12 at 9:53
  • Updated the answer with Views integration. – Letharion Dec 21 '12 at 9:56
  • Both answers are great , i do not know which one to accept , anyways i up voted both... thank you! – Vlasin Dec 21 '12 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.