Created
March 30, 2011 15:59
-
-
Save moeffju/894670 to your computer and use it in GitHub Desktop.
If you want to use clickheat, but don't want to bother with mixing PHP and Ruby, or getting mixed-content warnings on SSL, etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get '/c' => proc { |env| | |
request = Rack::Request.new(env) | |
params = request.params | |
unless params['x'] && params['y'] && params['w'] && params['g'] && params['s'] && params['b'] && params['c'] | |
[200, {}, 'KO'] | |
else | |
final = [params['s'].gsub(/[^a-z_0-9\-]+/, '_'), params['g'].gsub(/[^a-z_0-9\-]+/, '_')].join(',') | |
log_path = Rails.root.join('log', 'clickheat', final) | |
FileUtils.mkdir_p(log_path) | |
File.open([log_path, "#{Time.now.strftime('%Y-%m-%d')}.log"].join('/'), 'a') do |f| | |
f.puts [params['x'].to_i, params['y'].to_i, params['w'].to_i, params['b'].downcase.gsub(/[^a-z]+/, ''), params['c'].to_i].join('|') | |
end | |
[200, {}, 'OK'] | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment