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.

Blog Module /

Discuss the Blog Module.

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

Hit/views counter


Reply


3 Posts   2487 Views

Avatar
baba-papa

Community Member, 279 Posts

25 July 2009 at 8:04am

I programmed a hit counter for my blog. I always wondered if anyone reads my blog posts ;-) Now I know for sure.
May be this is useful to anyone else.
This is the method (BlogEntry_Controller.php):

function incViews() {
if(Session::get('BlogViewed-' . $this->ID) == false){
Session::set('BlogViewed-' . $this->ID, 'true');
$this->Views++;
$SQL_numViews = Convert::raw2sql($this->Views);
DB::query("UPDATE BlogEntry_Live SET Views = '$SQL_numViews' WHERE ID = $this->ID");
}
   }


I gets called in the init():

   function init() {
      parent::init();
      $this->incViews();
      Requirements::themedCSS('blog');
   }


I stole this idea from the FORUM-Module. Please tell me what you think about this feature.

Avatar
Willr

Forum Moderator, 5513 Posts

25 July 2009 at 11:30pm

I always wondered if anyone reads my blog posts ;-)

Well if you want some better statistics http://www.google.com/analytics/ or any other web statistics package would provide much more useful data.

Avatar
baba-papa

Community Member, 279 Posts

25 July 2009 at 11:42pm

Thanks for your hint. I´m not familiar with google analystics yet. It will be my next challenge to work with it.

Obviously my work is useless to others, but I learned some more things about SS.