Sha256: c2ce21ccb69689a71267271fa6cb5d0e213a255f845790ab39dfbeaa8ef4e316
Contents?: true
Size: 1.3 KB
Versions: 1
Compression:
Stored size: 1.3 KB
Contents
require 'sinatra' require 'net/http' class Analytics < Sinatra::Base configure do set :static, true set :views, File.expand_path('./views', __FILE__) set :haml, { :format => :html5 } set :port, 8080 @@events ||= [] end get '/' do @events = @@events haml :index end get '/test' do puts "#{@@events}" end get '/__utm.gif' do unless params[:utmt].nil? options = params[:utme] || "" if params[:utmt] == "event" options = options.split("(") arr = [] options.each{|o| arr << o.split(")") } arr = arr.flatten arr.reject!{|o| o == '' } details = arr[1].split("*") options = { :action => details[0], :location => details[1], :label => details[2], :value => arr[2], created_at: Time.now } @@events << options end end content_type :gif puts "" end get '/ga.js' do uri = URI.parse("http://www.google-analytics.com/ga.js") response = Net::HTTP.get_response(uri) local = "http://" + self.request.host + ":" + self.request.port.to_s body = response.body.gsub(/http(.*?)google-analytics.com/, local).gsub('www.google-analytics.com', local) render js: body, :content_type => "text/javascript" end end Analytics.run!
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
analyticator-1.0.1 | lib/analytics/analytics.rb |