Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Most popular articles


5 Posts   1377 Views


31 July 2010 at 11:48pm Community Member, 30 Posts

Are somewhere in database stored data about page visits? I want to create list of most popular pages (articles). If not, what is the best place to put some code, that increments database field (with number of visits).


1 August 2010 at 11:08am Forum Moderator, 5511 Posts

No information in the database on page views. SS used to have it but that was a nightmare. To store the number of visits its easy to do but this means that for every page visit you're writing to the database which is slow and if you have a large site I wouldn't recommend it. You would be best to integrate with google analytics or something to get page view information.

If you really want to implement it then the easiest way is to add a field to your page type and increment the count in the init()

// Page.php
static $db = array(
'Views' => 'Int'

// Page_Controller
function init() {


// then the query for most popular would be like
function MostPopular() {
return DataObject::get('Page', '', 'Views DESC', '', '10');


2 August 2010 at 7:13pm Community Member, 30 Posts

Thx for reply. I didn't know that is possible to get data from google analytics. Google helped and I've found some usefull code. This solution will be better.


12 April 2011 at 1:58am (Last edited: 12 April 2011 1:58am), Community Member, 12 Posts

Hi Jarek,

Have you actually integrated Google analytic's most popular pages into SilverStripe. If so, are you able to share the code - it's exactly what I'm looking for!

Many thanks...


10 May 2012 at 9:13pm Community Member, 20 Posts

The problem with using Views page field mentioned above is that the page will be versioned every time it is accessed.

There are two ways to avoid this behavior:

- either to use SQL query directly for updating the View value
- or to use separate dataobject (e.g. PageCounter) that will keep information about page views

You can read tutorials I wrote regarding page view counter: [url=]how to implement page view counter[/url] and [url=]how to display popular articles[/url]

Google Analytics is a great web tool but I don't like to use it for my sites' logic, it's only what it's name says - an analytics tool.