track_me 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/lib/generators/track_me/install/install_generator.rb +22 -0
- data/lib/generators/track_me/install/templates/_js.html.haml +3 -0
- data/lib/generators/track_me/install/templates/_kissmetrics.html.haml +21 -0
- data/lib/generators/track_me/install/templates/_mixpanel.html.haml +11 -0
- data/lib/generators/track_me/install/templates/track_me.rb +10 -0
- data/lib/track_me/version.rb +3 -0
- data/lib/track_me.rb +32 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/track_me_spec.rb +18 -0
- data/track_me.gemspec +22 -0
- metadata +96 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jim Ruther Nill
|
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,47 @@
|
|
1
|
+
# TrackMe
|
2
|
+
|
3
|
+
This is a gem that allows you to easily add javascript based metric systems like kissmetrics and mixpanel to your application.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'track_me'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install track_me
|
18
|
+
|
19
|
+
After installing the gem, you need to run the generator that will install a few files.
|
20
|
+
|
21
|
+
$ rails g track_me:install
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
In your controllers, call trackme and pass in the name of the action and the string that will be used to describe the action. You can also pass in a hash with a key called 'object' which will be used for sending the details of the object.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class CommentsController < ActionController::Base
|
29
|
+
trackme index: ['Visited the comments index page'],
|
30
|
+
create: ['Created a comment', object: 'comment']
|
31
|
+
|
32
|
+
def index
|
33
|
+
end
|
34
|
+
|
35
|
+
def create
|
36
|
+
@comment = ...
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module TrackMe
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path("../templates", __FILE__)
|
4
|
+
|
5
|
+
def copy_files
|
6
|
+
copy_file '_js.html.haml', 'app/views/track_me/_js.html.haml'
|
7
|
+
copy_file '_mixpanel.html.haml', 'app/views/track_me/_mixpanel.html.haml'
|
8
|
+
copy_file '_kissmetrics.html.haml', 'app/views/track_me/_kissmetrics.html.haml'
|
9
|
+
copy_file 'track_me.rb', 'config/initializers/track_me.rb'
|
10
|
+
|
11
|
+
say "\n"
|
12
|
+
say 'Please dont forget to add the js file to the head section of your html templates', :green
|
13
|
+
say "\n"
|
14
|
+
say " = render 'track_me/js' if Rails.env.production?", :green
|
15
|
+
say "\n"
|
16
|
+
say 'and the call to include on application controller', :green
|
17
|
+
say "\n"
|
18
|
+
say " include TrackMe", :green
|
19
|
+
say "\n"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
:javascript
|
2
|
+
// Initialize Kissmetrics
|
3
|
+
var _kmq = _kmq || [];
|
4
|
+
var _kmk = _kmk || '#{KISSMETRICS_ID}';
|
5
|
+
|
6
|
+
function _kms(u){
|
7
|
+
setTimeout(function(){
|
8
|
+
var d = document, f = d.getElementsByTagName('script')[0],
|
9
|
+
s = d.createElement('script');
|
10
|
+
s.type = 'text/javascript'; s.async = true; s.src = u;
|
11
|
+
f.parentNode.insertBefore(s, f);
|
12
|
+
}, 1);
|
13
|
+
}
|
14
|
+
_kms('//i.kissmetrics.com/i.js');
|
15
|
+
_kms('//doug1izaerwt3.cloudfront.net/' + _kmk + '.1.js');
|
16
|
+
|
17
|
+
// Identify current user
|
18
|
+
_kmq.push(['identify', '#{current_user.email}']);
|
19
|
+
|
20
|
+
// Track event
|
21
|
+
_kmq.push(['record', '#{escape_javascript @track_string}']);
|
@@ -0,0 +1,11 @@
|
|
1
|
+
:javascript
|
2
|
+
// Initialize Mixpanel
|
3
|
+
(function(c,a){window.mixpanel=a;var b,d,h,e;b=c.createElement("script");b.type="text/javascript";b.async=!0;b.src=("https:"===c.location.protocol?"https:":"http:")+'//cdn.mxpnl.com/libs/mixpanel-2.0.min.js';d=c.getElementsByTagName("script")[0];d.parentNode.insertBefore(b,d);a._i=[];a.init=function(b,c,f){function d(a,b){var c=b.split(".");2==c.length&&(a=a[c[0]],b=c[1]);a[b]=function(){a.push([b].concat(Array.prototype.slice.call(arguments,0)))}}var g=a;"undefined"!==typeof f? g=a[f]=[]:f="mixpanel";g.people=g.people||[];h="disable track track_pageview track_links track_forms register register_once unregister identify name_tag set_config people.set people.increment".split(" ");for(e=0;e<h.length;e++)d(g,h[e]);a._i.push([b,c,f])};a.__SV=1.1})(document,window.mixpanel||[]);
|
4
|
+
mixpanel.init("#{MIXPANEL_ID}");
|
5
|
+
|
6
|
+
- if @trackme_object
|
7
|
+
:javascript
|
8
|
+
mixpanel.track('#{escape_javascript @trackme_string}', #{@trackme_object.to_json});
|
9
|
+
- else
|
10
|
+
:javascript
|
11
|
+
mixpanel.track('#{escape_javascript @trackme_string}');
|
data/lib/track_me.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "track_me/version"
|
2
|
+
|
3
|
+
module TrackMe
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def trackme(actions)
|
10
|
+
@trackme_actions = actions
|
11
|
+
|
12
|
+
before_filter :set_trackme_actions
|
13
|
+
|
14
|
+
include TrackMe::InstanceMethods
|
15
|
+
end
|
16
|
+
|
17
|
+
def trackme_actions
|
18
|
+
@trackme_actions
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module InstanceMethods
|
23
|
+
def set_trackme_actions
|
24
|
+
@trackme_string, opts = self.class.trackme_actions[params[:action].to_sym]
|
25
|
+
|
26
|
+
if opts && opts[:object]
|
27
|
+
obj = instance_variable_get "@#{opts[:object]}"
|
28
|
+
@trackme_object = obj.attributes.except('created_at', 'updated_at', 'delta') if obj
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class FooController < ActionController::Base
|
4
|
+
include TrackMe
|
5
|
+
end
|
6
|
+
|
7
|
+
describe FooController do
|
8
|
+
before :each do
|
9
|
+
@foo = FooController.new
|
10
|
+
@foo.class.trackme index: ['My first tracked action']
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'trackme' do
|
14
|
+
it 'should set @trackme_actions which caches the options passed to #trackme' do
|
15
|
+
@foo.class.instance_variable_get('@trackme_actions')[:index].should == ['My first tracked action']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/track_me.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'track_me/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "track_me"
|
8
|
+
gem.version = TrackMe::VERSION
|
9
|
+
gem.authors = ["Jim Ruther Nill"]
|
10
|
+
gem.email = ["jim@netengine.com.au"]
|
11
|
+
gem.description = %q{Easy way to add a metric system using javascript and known metric saas}
|
12
|
+
gem.summary = %q{Easily add multiple metric systems}
|
13
|
+
gem.homepage = "https://github.com/jvnill/track_me"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
gem.add_development_dependency 'actionpack'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: track_me
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jim Ruther Nill
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: actionpack
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Easy way to add a metric system using javascript and known metric saas
|
47
|
+
email:
|
48
|
+
- jim@netengine.com.au
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- .rspec
|
55
|
+
- CHANGELOG.md
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- lib/generators/track_me/install/install_generator.rb
|
61
|
+
- lib/generators/track_me/install/templates/_js.html.haml
|
62
|
+
- lib/generators/track_me/install/templates/_kissmetrics.html.haml
|
63
|
+
- lib/generators/track_me/install/templates/_mixpanel.html.haml
|
64
|
+
- lib/generators/track_me/install/templates/track_me.rb
|
65
|
+
- lib/track_me.rb
|
66
|
+
- lib/track_me/version.rb
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
- spec/track_me_spec.rb
|
69
|
+
- track_me.gemspec
|
70
|
+
homepage: https://github.com/jvnill/track_me
|
71
|
+
licenses: []
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.8.23
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Easily add multiple metric systems
|
94
|
+
test_files:
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
- spec/track_me_spec.rb
|