Rajdeep Singh
Rajdeep Singh

Reputation: 17834

Want to count number of visits on my blogs

I want to count the number of visits on my blog? Can someone please suggest the overall method to implement this feature?

Upvotes: 0

Views: 1460

Answers (3)

amit_saxena
amit_saxena

Reputation: 7614

You could also use an existing (free) analytics solutions if you want to get much more data than the number of times the action was called (please note that if the same user refreshes the browser 5 times, you get 5 hits):

http://www.google.com/analytics/

Using these you can get data like unique visitors, referral URL, locations data, browser, OS, and a lot of different stuff to make informed decisions. There are several other options (paid, free, real time) available as well:

https://mixpanel.com

https://www.kissmetrics.com/

Upvotes: 0

Bachan Smruty
Bachan Smruty

Reputation: 5734

It is just an idea. You can add a count_view column in the database into blogs table with default value 0.

And in the show action of BlogsController add the following code

def show
 @blog = Blog.where('id = ?', params[:id]).first
 @blog.update_column('count_view', @blog.count_view + 1) if @blog.present?
end

You can modify this logic as per your requirement.

Upvotes: 3

mrudult
mrudult

Reputation: 2570

You can check the hit counter gem or the impressionist gem.

Upvotes: 1

Related Questions