redis_analytics

Web analytics for your rails apps using Redis

  • 所有者: d0z0/redis_analytics
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

redis_analytics Build Status Coverage Status Gem Version

A ruby gem that uses redis to track web analytics for your rails apps

Why should I use it?

It gives you detailed analytics about visitors, unique visitors, browsers, OS, visitor recency, traffic sources, etc

Does it have a cool dashboard?

Yes, It uses the excellent Morris.js for graphs/charts

Screenshot

Cool! So how do I install it?

In your Gemfile

gem 'redis_analytics'

Make sure your redis server is running! Redis configuration is outside the scope of this README, but
check out the Redis documentation.

How do I enable tracking in my rails apps?

require 'redis_analytics'

# configure your redis_connection (mandatory) and redis_namespace (optional)
RedisAnalytics.configure do, configuration, configuration.redis_connection = Redis.new(url: 'redis://localhost:6379')
  configuration.redis_namespace = 'ra'
end

Where can I see the dashboard?

The Dashboard is a Rails::Engine. Just mount it into your routes.rb file at your favorite endpoint

Rails.application.routes.draw do
  mount RedisAnalytics::Dashboard::Engine => "/dashboard"
end

and navigate to /dashboard in your app

What if I have multiple rails apps that I want to track as one single website?

Just make sure you use the same redis_connection and redis_namespace in the configuration for all your rails apps

RedisAnalytics.configure do, configuration, configuration.redis_connection = Redis.new(url: 'redis://localhost:6379')
  configuration.redis_namespace = 'mywebsite.org'
end

Why is the Geolocation tracking giving me wrong results?

IP based Geolocation works using MaxMind's GeoLite database. The free version is not as accurate as their commercial version.
Also it is recommended to regularly get an updated binary of 'GeoLite Country' database from here and extract the GeoIP.dat file into a local directory.
You will then need to point to the GeoIP.dat file in your configuration.

RedisAnalytics.configure do, configuration, configuration.redis_connection = Redis.new(url: 'redis://localhost:6379')
  configuration.redis_namespace = 'mywebsite.org'
  configuration.geo_ip_data_path = '/path/to/GeoIP.dat'
end

Customizing & Extending

Tracking custom metrics

You can define how to track custom metrics by creating an instance method inside the RedisAnalytics::Metrics module

module RedisAnalytics::Metrics

  # methods to track custom metrics  

end

RedisAnalytics only looks for method names which conform to the following format:

[abc]_[x]_per_[y]

where

  • abc is a metric name
  • x can be any one of ratio or count and defines the type of the metric
  • y can be any one of hit or visit and defines how the metric will be tracked (once per hit or once per visit)

The return value of the method is important and should be Fixnum for count and String for ratio failing which, your metric might not work!

If the return value is an error or nil the metric won't be tracked at all

You can access the Rack::Request object via @rack_request and the Rack::Response object via @rack_response in your methods

You are free to define other methods that do not have the above format in the Metrics module as helper methods

module RedisAnalytics::Metrics

  # TRACKING RATIOS

  # i want to track ratio of product views per product_id & user_id using query params
  def user_product_views_ratio_per_hit
    if @rack_request.path == '/product/info'
      return "#{@rack_request.params['product_id']}_#{@rack_request.params['user_id']}"
    end
  end

  # i want to track ratio of sold products by product_id using the URL `/products/:id/sale`
  def product_sales_ratio_per_hit
    if @rack_request.path =~ Regexp.new("\/product\/([0-9]+)\/sale")
      return $1
    end
  end

  # TRACKING COUNTS

  # i want to track how many times a visitor reached the payment step
  def payment_step_count_per_hit
    return 1 if @rack_request.path == '/payment'
  end

end

Customizing the dashboard

Coming soon

Using filters

RedisAnalytics.configure do, configuration, # simple string path filter
  configuration.add_path_filter('/robots.txt')

  # regexp path filter
  configuration.add_path_filter(/^\/favicon.ico$/)

  # generic filters
  configuration.add_filter do, request, response, request.params['layout'] == 'print'
  end

  # generic filters
  configuration.add_filter do, request, response, request.ip =~ /^172.16/ or request.ip =~ /^192.168/
  end

end

Contributors Wanted

I may not be able to devote much time to this gem, but you are welcome to send me pull requests. See CONTRIBUTING.md to get started

License

Since redis_analytics is licensed under MIT, you can use redis_analytics for free, provided you leave the attribution as is, in code as well as on the dashboard pages

Copyright (c) 2012-2014 Schubert Cardozo. See MIT-LICENSE! for further details.

主要指标

概览
名称与所有者d0z0/redis_analytics
主编程语言Ruby
编程语言Ruby (语言数: 4)
平台
许可证MIT License
所有者活动
创建于2013-02-16 09:59:57
推送于2020-02-25 23:15:39
最后一次提交2019-08-27 12:19:40
发布数6
最新版本名称v1.1.0 (发布于 )
第一版名称v0.1.0 (发布于 2013-09-10 13:09:23)
用户参与
星数175
关注者数13
派生数31
提交数396
已启用问题?
问题数13
打开的问题数5
拉请求数8
打开的拉请求数2
关闭的拉请求数2
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?