3

Is there any possible way to find the number of views of a node.

For example:

I have created a node called "Sample".

If i viewed it once then the count should be increased as 1 view and when i view the same node again it should not get increased.

Is there any module to do that..

Else what's the best way to do it ?

5 Answers 5

4

It depends how much traffic you site has and how big your server is. If you need to create a view count like this, it will require that you disable page cache making your site slower and demanding more resources from your server, or run expensive queries on every node view.

You could do this with Drupal, but there isn't a module that provides this functionality for you. The statistics module will count all views of the node. To implement this you would need to use either hook_node_view or hook_boot and write to a database the nid of the node being used and a token for the user. If you don't want to count anonymous users, you can use the uid, else you would have to use a combination of uid and session id to try not to count the same anonymous users twice.

A better way if you have a lot of traffic is to use an external tool like Google Analytics and then draw data from there.

Both solutions will require custom code though.

4
  • 1
    Doesn't the core statistics module contain the ability to count page views out of the box? I agree Google Analytics is a better option though, Statistics can fill a database pretty damn quickly on larger sites. The Google Analytics API would also allow pulling page views into Drupal based on the path, which is nice :-)
    – Chapabu
    Commented Jan 31, 2012 at 9:32
  • 1
    @Chapabu The core statistics module doesn't allow to count unique views, which is what OP asked for.
    – googletorp
    Commented Jan 31, 2012 at 10:31
  • Aaah, apologies! I misunderstood/misread.
    – Chapabu
    Commented Jan 31, 2012 at 10:38
  • There are a few contrib modules that extend the core statistics counter to be more considerate of 'unique' visitors. (like statistics_advanced)
    – user18099
    Commented Jul 4, 2017 at 10:45
2

Enable statistics module in your site and then go to configuration of statistics module which is at

--> admin/config/system/statistics.

--> CONTENT VIEWING COUNTER SETTINGS check "Count content views".

Then go to any node like node/1 or node/2, at bottom see the number of reads like "1 read" / "50 reads" you can also find the number of node views in any View go to -> add fields and search --> " Content statistics: Total views" This will bring node views to your content.

1
  • This module is great but it counts every view, not just unique views... Commented Sep 8, 2020 at 20:38
1

There indeed indeed appears to be contrib module that provides unique page visits for an entity. I haven't used it yet but just came across it when search for this https://www.drupal.org/project/piwik_stats.

0

For Drupal 6 you can use "Statistics Advanced" module that allows to track only unique visitors.

For Drupal 7 this module has unstable version http://drupal.org/node/816040

0

Statistics module has a short API for doing this job

$nodevisit=statistics_get($node->nid);
print $nodevisit['totalcount'];
print $nodevisit['daycount'];

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