21278 Posts in 5728 Topics by 2599 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1068 Views |
-
Most popular articles

31 July 2010 at 11:48pm
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).
-
Re: Most popular articles

1 August 2010 at 11:08am
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() {
parent::init();$this->Views++;
$this->write();
}// then the query for most popular would be like
function MostPopular() {
return DataObject::get('Page', '', 'Views DESC', '', '10');
} -
Re: Most popular articles

2 August 2010 at 7:13pm
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.
-
Re: Most popular articles

12 April 2011 at 1:58am Last edited: 12 April 2011 1:58am
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...
-
Re: Most popular articles

10 May 2012 at 9:13pm
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 viewsYou can read tutorials I wrote regarding page view counter: how to implement page view counter and how to display popular articles
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.
| 1068 Views | ||
|
Page:
1
|
Go to Top |



