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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Blog Module /

Discuss the Blog Module.

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

Hit/views counter


Go to End


3 Posts   3695 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, 5523 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.