rakwik 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ *.sublime-*
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ .rvmrc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rakwik.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Christian Aust
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # Rakwik
2
+
3
+ *Server-side* integration of web tracking methods does not require Javascript snippets
4
+ or tracking images to be includd in the actual frontend. Rakwik implements asynchronous
5
+ tracking, so it tries to keep the time low, needed to count a particular request.
6
+
7
+ ![Server-side tracking](https://github.com/datenimperator/rakwik/wiki/server-side_tracking.png)
8
+
9
+ Unlike client-side tracking, server-side tracking can be used independently of frontend
10
+ encryption. Your application requires SSL encryption, but your installation of Piwik
11
+ does not support it? That's what Rakwik ist built for: It can track a request using http
12
+ while the original request came in over https, without the browser having to warn the
13
+ user about mixed content.
14
+
15
+ ## Pros and cons
16
+
17
+ Using server-side tracking, you can track all kinds of information that are visible to
18
+ your server. Most certainly the URL, IP address and referrer are used, also session
19
+ information to identify subsequent requests from the same client.
20
+
21
+ However, it's hard to track client-specific information like screen resolution and plugin
22
+ support since the server has no way to detect details like such.
23
+
24
+ ## Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ gem 'rakwik'
29
+
30
+ And then execute:
31
+
32
+ $ bundle
33
+
34
+ Or install it yourself as:
35
+
36
+ $ gem install rakwik
37
+
38
+ ## Usage
39
+
40
+ Rakwik comes as a Rack-compatible middleware which needs to be added to your application's
41
+ middleware stack on startup.
42
+
43
+ config.middleware.use Rakwik::Tracker,
44
+ :piwik_url => 'http://your.piwik.host/piwik.php',
45
+ :site_id => 'your_site_id', # eg. 1
46
+ :token_auth => 'yoursecrettoken'
47
+
48
+ The `:token_auth` is needed since Rakwik will tell Piwik to record hits from another IP
49
+ than its own. The token_auth must be either the Super User token_auth, or a user with
50
+ "admin" permission for this website ID.
51
+
52
+ ## Reference
53
+
54
+ * http://piwik.org/docs/tracking-api/reference/
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
60
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
61
+ 4. Push to the branch (`git push origin my-new-feature`)
62
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler'
3
+ require 'rspec/core/rake_task'
4
+
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ task :default => :spec
@@ -0,0 +1,58 @@
1
+ require 'em-http'
2
+ require 'pp'
3
+
4
+ module Rakwik
5
+ class Tracker
6
+ DEFAULT = {}
7
+
8
+ def initialize(app, options = {})
9
+ @app, @options = app, DEFAULT.merge(options)
10
+ missing = [:piwik_url, :site_id, :token_auth].detect{ |e| @options[e].nil? }
11
+ raise "Missing config value: :#{missing}" if missing
12
+ end
13
+
14
+ def call(env)
15
+ status, headers, response = @app.call(env)
16
+ track Rack::Request.new(env)
17
+ [status, headers, response]
18
+ end
19
+
20
+ private
21
+
22
+ def piwik_url
23
+ @options[:piwik_url]
24
+ end
25
+
26
+ def piwik_id
27
+ @options[:site_id]
28
+ end
29
+
30
+ def token_auth
31
+ @options[:token_auth]
32
+ end
33
+
34
+ def track(request)
35
+ header = {
36
+ 'User-Agent' => request.user_agent,
37
+ 'Accept-Language' => request.env["HTTP_ACCEPT_LANGUAGE"]
38
+ }
39
+ data = {
40
+ 'idsite' => piwik_id,
41
+ 'token_auth' => token_auth,
42
+ 'rec' => 1,
43
+ 'url' => request.url,
44
+ 'cip' => request.ip,
45
+ 'apiv' => 1
46
+ }
47
+ data['urlref'] = request.referer unless request.referer.nil?
48
+ EventMachine.schedule do
49
+ http = connection(piwik_url).get :head => header, :query => data
50
+ end
51
+ end
52
+
53
+ def connection(url)
54
+ EventMachine::HttpRequest.new(url)
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module Rakwik
2
+ VERSION = "0.0.1"
3
+ end
data/lib/rakwik.rb ADDED
@@ -0,0 +1,39 @@
1
+ require "rakwik/tracker"
2
+
3
+ module Rakwik
4
+ # Taken from http://www.hiringthing.com/2011/11/04/eventmachine-with-rails.html
5
+ # Thanks Joshua!
6
+ def self.start
7
+ if defined?(PhusionPassenger)
8
+ PhusionPassenger.on_event(:starting_worker_process) do |forked|
9
+ # for passenger, we need to avoid orphaned threads
10
+ if forked && EM.reactor_running?
11
+ EM.stop
12
+ end
13
+ Thread.new {
14
+ EM.run do
15
+ puts "=> EventMachine started"
16
+ end
17
+ }
18
+ die_gracefully_on_signal
19
+ end
20
+ else
21
+ # faciliates debugging
22
+ Thread.abort_on_exception = true
23
+ # just spawn a thread and start it up
24
+ Thread.new {
25
+ EM.run do
26
+ puts "=> EventMachine started"
27
+ end
28
+ } unless defined?(Thin)
29
+ # Thin is built on EventMachine, doesn't need this thread
30
+ end
31
+ end
32
+
33
+ def self.die_gracefully_on_signal
34
+ Signal.trap("INT") { EM.stop }
35
+ Signal.trap("TERM") { EM.stop }
36
+ end
37
+ end
38
+
39
+ Rakwik.start
data/rakwik.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rakwik/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Christian Aust"]
6
+ gem.email = ["github@kontakt.software-consultant.net"]
7
+ gem.description = %q{Rakwik is a server-side tracker integration for the Piwik opensource
8
+ web statistics software. It's easy to integrate into rack-based applications and does not require
9
+ frontend Javascript inclusion.}
10
+ gem.summary = %q{Rack-based server-side asynchronous Piwik tracker integration.}
11
+ gem.homepage = "https://github.com/datenimperator/rakwik"
12
+ gem.licenses = ["MIT"]
13
+
14
+ gem.add_dependency "rack"
15
+ gem.add_dependency "em-http-request"
16
+
17
+ gem.add_development_dependency "rspec"
18
+
19
+ gem.files = `git ls-files`.split($\)
20
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
+ gem.name = "rakwik"
23
+ gem.require_paths = ["lib"]
24
+ gem.version = Rakwik::VERSION
25
+ gem.platform = Gem::Platform::RUBY
26
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rakwik::Tracker do
4
+ end
@@ -0,0 +1,7 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ require 'rack'
4
+ require 'rakwik'
5
+
6
+ RSpec.configure do |config|
7
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rakwik
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Christian Aust
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-06-18 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rack
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: em-http-request
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :development
61
+ version_requirements: *id003
62
+ description: |-
63
+ Rakwik is a server-side tracker integration for the Piwik opensource
64
+ web statistics software. It's easy to integrate into rack-based applications and does not require
65
+ frontend Javascript inclusion.
66
+ email:
67
+ - github@kontakt.software-consultant.net
68
+ executables: []
69
+
70
+ extensions: []
71
+
72
+ extra_rdoc_files: []
73
+
74
+ files:
75
+ - .gitignore
76
+ - Gemfile
77
+ - LICENSE
78
+ - README.md
79
+ - Rakefile
80
+ - lib/rakwik.rb
81
+ - lib/rakwik/tracker.rb
82
+ - lib/rakwik/version.rb
83
+ - rakwik.gemspec
84
+ - spec/lib/rakwik/tracker_spec.rb
85
+ - spec/spec_helper.rb
86
+ homepage: https://github.com/datenimperator/rakwik
87
+ licenses:
88
+ - MIT
89
+ post_install_message:
90
+ rdoc_options: []
91
+
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ requirements: []
113
+
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.24
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Rack-based server-side asynchronous Piwik tracker integration.
119
+ test_files:
120
+ - spec/lib/rakwik/tracker_spec.rb
121
+ - spec/spec_helper.rb