Skip to content

Instantly share code, notes, and snippets.

@zoomix
Created October 24, 2012 15:50
Show Gist options
  • Save zoomix/3946882 to your computer and use it in GitHub Desktop.
Save zoomix/3946882 to your computer and use it in GitHub Desktop.
Realtime kissmetrics
require 'sinatra'
require 'json'
set :logging, false
get '/log' do
$site_stats ||= Hash.new(0)
$report_stats ||= Hash.new(0)
$report_table_stats ||= Hash.new(0)
# params.each do |key,value|
# puts " #{key}: #{value}"
# end
case params[:event]
when 'View Report'
$site_stats[params[:site]] += 1
$report_stats[params[:report]] += 1
table_dimension = case params[:report]
when 'user-experience' then 'Category'
when 'visits' then 'Traffic Source'
else 'Placement'
end
$report_table_stats["#{params[:report]}/#{table_dimension}"] += 1
when 'View Report Table Column'
$site_stats[params[:site]] += 1
when 'View Report Table'
$report_stats[params[:report]] += 1
$report_table_stats["#{params[:report]}/#{params[:table]}"] += 1
end
# puts "All the stats: **************** #{[$site_stats, $report_stats, $report_table_stats]}"
204
end
get '/app' do
erb :index
end
get '/angie' do
erb :angie
end
get '/json/site' do
$site_stats.map { |k,v| { :site => k, :count => v } }.to_json
end
get '/json/report' do
$report_stats.map { |k,v| { :report => k, :count => v } }.to_json
end
get '/json/report_table' do
$report_table_stats.map { |k,v| { :report_table => k, :count => v } }.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment