This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » Developer » count accesses to a page ezpublish 4.5

count accesses to a page ezpublish 4.5

count accesses to a page ezpublish 4.5

Tuesday 24 May 2011 5:00:03 pm - 4 replies

I need to count the accesses to a page.
When a user (also anonymous) displays a page I have to increase a value.
Can anyone help me?

Modified on Tuesday 24 May 2011 5:01:23 pm by alessio asistar

Wednesday 25 May 2011 12:31:47 am

If you just need to get most viewed nodes you can try using view_top_list fetch function.

Keep in mind that it relies on a cronjob script (updateviewcount.php) that parses Apache log files and updates ezview_counter table (which is than used to determine the most accessed nodes).


Wednesday 25 May 2011 9:05:35 am

If you do not want to parse files, you could do something like this. Create a template operator called "viewcounter" and add the following code to your pagelayout

{cache-block expiry=1}{if and($current_node_id,gt($current_node_id,2))}{""|viewcounter($current_node_id)}{/if}{/cache-block}

The template operator modify function should look something like this:

function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, $operatorValue, $namedParameters )
$nodeID = $namedParameters['node_id'];
switch ( $operatorName )
case 'viewcounter':
if ( is_numeric( $nodeID ) AND $nodeID > 0 )
$nodeObject = eZContentObjectTreeNode::fetch( $nodeID );
if ( $nodeObject != null )
$counter = eZViewCounter::fetch( $nodeID );
if ( $counter == null )
$counter = eZViewCounter::create( $nodeID );
} break;

The code is for older versions of eZ, so it probably has to be updated.

Modified on Wednesday 25 May 2011 9:09:51 am by S V

Wednesday 25 May 2011 11:02:44 am

Also, you should take into consideration the effects of different caching approaches.

For example, if you make use of static cache, it might happen that your template code does not get executed.

Also, if you use some kind of reverse proxy / HTTP accelerator like Varnish, it could happen that visit does not get into Apache log either.

You can try some kind of client side/Java Script approach (for example by utilising Google Analytics custom variables). By this you can also filter out visits made by web bots/crawlers.

Modified on Wednesday 25 May 2011 11:37:56 am by Igor Vrdoljak

Wednesday 25 May 2011 1:39:47 pm

Hi Alessio.

I have made an extension that counts visits using a template operator and gives live stats in realtime. In practice it counts only the content that is not in static cache, so it's usually used to get realtime visits for content like articles and news. A very usefull tools for news portals.

Since this counter is a part of broader extension, it's not yet available to public but if you want you can contact me personally and I can help you setting it up.

Modified on Wednesday 25 May 2011 1:44:29 pm by Mavko Žmak - Žmale


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from