exvo-metrics 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9ea8d1df1bf7a8409baaea2073ca5e6397624c2b
4
+ data.tar.gz: 5adae841e1f74b2b99f29625f99cdf66c3058e06
5
+ SHA512:
6
+ metadata.gz: 11876d600ac2f06d9ce2dc00094454e3739ba50ef7b3f8555fe525be283b6c5e724460ccbe9e24990d6b7fb84a138d1da18e8c6b59e79ba0745cd65f82988288
7
+ data.tar.gz: 17cdd0a918c532a9b17d83b1ae02d37a99b6ad48eeec8d401fcef15a74a4b73ca1307d3fab8a9b42efa9dfe7bbde5fb4b595fdea4c2ec0ab9b0bd30b02036546
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in exvo-metrics.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright © 2013 Exvo.com Development BV
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,85 @@
1
+ # Exvo::Metrics
2
+
3
+ Wrapper class/gem for the Mixpanel metrics system. It is configured to be used together with the `Mixpanel::Middleware` Rack middleware so that the tracking requests are sent asynchronously via client-side Javascript to the Mixpanel site.
4
+
5
+
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'exvo-metrics'
13
+ ```
14
+
15
+
16
+ Then execute:
17
+
18
+ ```bash
19
+ $ bundle
20
+ ```
21
+
22
+
23
+ In your `ApplicationController`:
24
+
25
+ ```ruby
26
+ def metrics
27
+ @metrics ||= Exvo::Metrics.new(current_user, request)
28
+ end
29
+ ```
30
+
31
+
32
+ In `config/environments/production.rb`:
33
+
34
+ ```ruby
35
+ config.middleware.use "Mixpanel::Middleware", ENV['MIXPANEL_API_TOKEN'], { persist: true }
36
+ ```
37
+
38
+ You can also add the above line to any environemnt you want (staging, development, etc.).
39
+
40
+ Remember to set the `ENV['MIXPANEL_API_TOKEN']` as well!
41
+
42
+
43
+
44
+ ## Usage
45
+
46
+ Add the following tracking code in one of your controllers:
47
+
48
+ ```ruby
49
+ metrics.track 'Profile update'
50
+ ```
51
+
52
+
53
+ You can also pass some custom params, which will be visible in the Mixpanel dashboard:
54
+
55
+ ```ruby
56
+ metrics.track 'Profile update', Type: 'Normal flow'
57
+ ```
58
+
59
+
60
+ If there is a situation, where `current_user` might be nil (as is the case during sign up process), you ca explicitly identify such user after you have a user record created in the database:
61
+
62
+ ```ruby
63
+ metrics.identify(user)
64
+ metrics.track 'Sign un'
65
+ ```
66
+
67
+
68
+
69
+ ## Caveats
70
+
71
+ Since the actual tracking is happening via client-side javascript calls, there might be a situation, when you track something in the controller, but after that there is a redirect to another website. In such situation the metric might not be recorded properly (it is usually the case with Exvo-Auth and signing in).
72
+
73
+
74
+
75
+ ## Contributing
76
+
77
+ 1. Fork it
78
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
79
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
80
+ 4. Push to the branch (`git push origin my-new-feature`)
81
+ 5. Create new Pull Request
82
+
83
+
84
+
85
+ Copyright © 2013 Exvo.com Development BV, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'exvo/metrics/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "exvo-metrics"
8
+ spec.version = Exvo::Metrics::VERSION
9
+ spec.authors = ["Paweł Gościcki"]
10
+ spec.email = ["pawel.goscicki@gmail.com"]
11
+ spec.description = "Metrics wrapper for Exvo apps."
12
+ spec.summary = "Wrapper gem for tracking usage metrics in Exvo apps."
13
+ spec.homepage = "https://github.com/Exvo/exvo-metrics"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'mixpanel'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'guard-rspec'
27
+ spec.add_development_dependency 'rb-fsevent'
28
+ spec.add_development_dependency 'rb-inotify'
29
+ end
@@ -0,0 +1,7 @@
1
+ module Exvo
2
+ class DummyMetrics
3
+ def method_missing(method, *args, &block)
4
+ true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Exvo
2
+ class Metrics
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,74 @@
1
+ require 'exvo/metrics/version'
2
+ require 'exvo/dummy_metrics'
3
+ require 'mixpanel'
4
+
5
+ module Exvo
6
+
7
+ class Metrics
8
+
9
+ def initialize(user, request)
10
+ @user, @request = user, request
11
+ end
12
+
13
+ def identify(user)
14
+ @user = user
15
+ append_identification
16
+ end
17
+
18
+ def track(event_name, properties = {})
19
+ append_identification unless identified?
20
+ metrics_platform.append_track(event_name, properties)
21
+ end
22
+
23
+ def method_missing(method, *args, &block)
24
+ metrics_platform.public_send(method, *args, &block)
25
+ end
26
+
27
+ private
28
+
29
+ def metrics_platform
30
+ @metrics_platform ||=
31
+ if defined?(Rails) && Rails.application.config.middleware.include?("Mixpanel::Middleware")
32
+ Mixpanel::Tracker.new(ENV['MIXPANEL_API_TOKEN'], { env: @request.env, persist: true })
33
+ else
34
+ Exvo::DummyMetrics.new
35
+ end
36
+ end
37
+
38
+ def identified?
39
+ @identified
40
+ end
41
+
42
+ def append_identification
43
+ # identify the user
44
+ metrics_platform.append_identify(@user.nickname)
45
+
46
+ # name this user in Stream view
47
+ metrics_platform.append("name_tag", @user.nickname)
48
+
49
+ # set properties of this user
50
+ metrics_platform.append_set(user_properties)
51
+
52
+ mark_as_identified
53
+ end
54
+
55
+ def user_properties
56
+ {
57
+ id: @user.id,
58
+ email: @user.email,
59
+ first_name: @user.first_name,
60
+ last_name: @user.last_name,
61
+ username: @user.nickname,
62
+ theme: @user.theme,
63
+ country_code: @user.country_code,
64
+ created: @user.created_at
65
+ }
66
+ end
67
+
68
+ def mark_as_identified
69
+ @identified = true
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Exvo::DummyMetrics do
4
+
5
+ let(:dummy) { Exvo::DummyMetrics.new }
6
+
7
+ it 'responds true to any method' do
8
+ dummy.track('Sign up').should be_true
9
+ end
10
+
11
+ it 'responds true to any method with any params' do
12
+ dummy.track('Sign up', Type: 'via Facebook').should be_true
13
+ end
14
+
15
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Exvo::Metrics do
4
+
5
+ let(:user) { OpenStruct.new({ nickname: 'Pawel' }) }
6
+ let(:request) { OpenStruct.new(env: { RAILS_ENV: 'test' }) }
7
+
8
+ let(:metrics) { Exvo::Metrics.new(user, request) }
9
+ let(:metrics_platform) { double }
10
+
11
+ before do
12
+ Exvo::Metrics.any_instance.stub(:metrics_platform) { metrics_platform }
13
+ end
14
+
15
+ describe '#identify' do
16
+
17
+ it 'identifies the user in the metrics platform' do
18
+ metrics_platform.should_receive(:append_identify).with(user.nickname)
19
+ metrics_platform.should_receive(:append).with('name_tag', user.nickname)
20
+ metrics_platform.should_receive(:append_set)
21
+ metrics.identify(user)
22
+
23
+ metrics.should be_identified
24
+ end
25
+
26
+ end
27
+
28
+ describe '#track' do
29
+
30
+ before do
31
+ metrics.stub(:identified?) { true }
32
+ end
33
+
34
+ it 'send tracking request' do
35
+ metrics_platform.should_receive(:append_track)
36
+ metrics.track('Sign in')
37
+ end
38
+
39
+ end
40
+
41
+ it 'forwards all other methods to the metrics platform' do
42
+ metrics_platform.should_receive(:set_once).with('id')
43
+ metrics.set_once('id')
44
+ end
45
+
46
+ end
@@ -0,0 +1,20 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'exvo/metrics'
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exvo-metrics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paweł Gościcki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mixpanel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rb-fsevent
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rb-inotify
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Metrics wrapper for Exvo apps.
112
+ email:
113
+ - pawel.goscicki@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - exvo-metrics.gemspec
124
+ - lib/exvo/dummy_metrics.rb
125
+ - lib/exvo/metrics.rb
126
+ - lib/exvo/metrics/version.rb
127
+ - spec/exvo/dummy_metrics_spec.rb
128
+ - spec/exvo/metrics_spec.rb
129
+ - spec/spec_helper.rb
130
+ homepage: https://github.com/Exvo/exvo-metrics
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.0.3
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Wrapper gem for tracking usage metrics in Exvo apps.
154
+ test_files:
155
+ - spec/exvo/dummy_metrics_spec.rb
156
+ - spec/exvo/metrics_spec.rb
157
+ - spec/spec_helper.rb