mixpanel-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/lib/mixpanel-rails.rb +1 -0
- data/lib/mixpanel/engine.rb +38 -0
- data/lib/mixpanel/helper.rb +27 -0
- data/lib/mixpanel/rails.rb +3 -0
- data/lib/mixpanel/rails/version.rb +5 -0
- data/mixpanel-rails.gemspec +22 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2a402c13b28c27567c34a3a9bb97601a2faaa253
|
4
|
+
data.tar.gz: 2af1d7fde1b4d954f9bbde834062cc64e5c25003
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4ba26f1b40e7b8bd65157f312c9dd0ac4ec4a4bd6d2d886e59f5ac5677e4da178e44b6b46d72a8d501f34789520b25c090b9eb74bccc653854035b127873d377
|
7
|
+
data.tar.gz: 9850bbdd3de84544d6ff8d161afbcd0cabdeb4b7cd4ebd173cfb0b7662582da160aa0aafc17097c1ea62a14d836eec0bca7e016c6b8df54657965d9a60d47b17
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Charles Lowell
|
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,45 @@
|
|
1
|
+
# Mixpanel::Rails
|
2
|
+
|
3
|
+
Painlessly integrate your rails application with [Mixpanel][1]
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mixpanel-rails'
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
Set the `config.mixpanel.api_token` parameter in your applications configuration or
|
14
|
+
the `MIXPANEL_API_TOKEN` environment variable. e.g.
|
15
|
+
|
16
|
+
# config/environments/staging.rb
|
17
|
+
config.mixpanel.token = 'XYZ'
|
18
|
+
config.mixpanel.options = {:async => true}
|
19
|
+
|
20
|
+
Want to use the [middleware for tracking with JavaScript][2]?
|
21
|
+
|
22
|
+
# config/application.rb
|
23
|
+
config.mixpanel.middleware.use = true
|
24
|
+
config.mixpanel.middleware.persist = false
|
25
|
+
config.mixpanel.middlware.insert_js_last = true
|
26
|
+
config.mixpanel.middleware.config = {:cookie_name => 'mixpanel_cookie' }
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
You can now access a pre-configured instance of `Mixpanel::Tracker` from anywhere in
|
31
|
+
your application by including the `Mixpanel::Helper` module:
|
32
|
+
|
33
|
+
class User < ActiveRecord::Base
|
34
|
+
include Mixpanel::Helper
|
35
|
+
after_create :notify_mixpanel
|
36
|
+
|
37
|
+
def notify_mixpanel
|
38
|
+
mixpanel.track 'User Created', :distinct_id => self.id
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Alternatively, you can use `Rails.application.mixpanel` if you don't want to include the module
|
43
|
+
|
44
|
+
[1]: http://mixpanel.com
|
45
|
+
[2]: https://github.com/zevarito/mixpanel#rack-middleware
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'mixpanel/rails'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'mixpanel'
|
2
|
+
|
3
|
+
module Mixpanel
|
4
|
+
class Engine < ::Rails::Railtie
|
5
|
+
|
6
|
+
Config = Struct.new(:token, :options, :middleware)
|
7
|
+
MiddlewareConfig = Struct.new(:use, :insert_js_last, :persist, :config)
|
8
|
+
|
9
|
+
config.mixpanel = Config.new(nil, {}, MiddlewareConfig.new(false, false, false, {}))
|
10
|
+
|
11
|
+
|
12
|
+
initializer 'mixpanel.setup' do |app|
|
13
|
+
class << app
|
14
|
+
attr_accessor :mixpanel
|
15
|
+
end
|
16
|
+
config.mixpanel.token ||= ENV['MIXPANEL_TOKEN']
|
17
|
+
$stderr.puts <<-WARNING unless config.mixpanel.token
|
18
|
+
No Mixpanel token was configured for environment #{::Rails.env}! this application will be
|
19
|
+
unable to interact with mixpanel.com. You can set your token with either the environment
|
20
|
+
variable `MIXPANEL_TOKEN` (recommended) or by setting `config.mixpanel.token` in your
|
21
|
+
environment file directly.
|
22
|
+
WARNING
|
23
|
+
app.mixpanel = Mixpanel::Tracker.new config.mixpanel.token, config.mixpanel.options
|
24
|
+
end
|
25
|
+
|
26
|
+
initializer 'mixpanel.middleware' do |app|
|
27
|
+
mixpanel = config.mixpanel
|
28
|
+
middleware = mixpanel.middleware
|
29
|
+
if middleware.use
|
30
|
+
config.middleware.use 'Mixpanel::Middleware', mixpanel.token, {
|
31
|
+
:insert_js_last => middleware.insert_js_last,
|
32
|
+
:persist => middleware.persist,
|
33
|
+
:config => middleware.config
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Mixpanel
|
2
|
+
module Helper
|
3
|
+
def mixpanel
|
4
|
+
config = ::Rails.application.config
|
5
|
+
Mixpanel::Tracker.new(config.mixpanel.token, config.mixpanel.options.merge(mixpanel_options)).tap do |tracker|
|
6
|
+
tracker.extend TrackerProperties
|
7
|
+
tracker.mixpanel_properties = mixpanel_properties
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def mixpanel_properties
|
12
|
+
{}
|
13
|
+
end
|
14
|
+
|
15
|
+
def mixpanel_options
|
16
|
+
{}
|
17
|
+
end
|
18
|
+
|
19
|
+
module TrackerProperties
|
20
|
+
attr_accessor :mixpanel_properties
|
21
|
+
|
22
|
+
def track(event_name, properties = {}, options = {})
|
23
|
+
super event_name, mixpanel_properties.merge(properties), options
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -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 'mixpanel/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "mixpanel-rails"
|
8
|
+
gem.version = Mixpanel::Rails::VERSION
|
9
|
+
gem.authors = ["Charles Lowell"]
|
10
|
+
gem.email = ["cowboyd@thefrontside.net"]
|
11
|
+
gem.description = %q{A Rails Engine for Mixpanel}
|
12
|
+
gem.summary = %q{Autoconfigure your Rails environment for use with Mixpanel}
|
13
|
+
gem.homepage = ""
|
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_dependency 'rails', '~> 3.0'
|
21
|
+
gem.add_dependency 'mixpanel', '~> 3.0'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mixpanel-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Charles Lowell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDPjCCAiagAwIBAgIBADANBgkqhkiG9w0BAQUFADBFMRAwDgYDVQQDDAdjb3di
|
14
|
+
b3lkMRwwGgYKCZImiZPyLGQBGRYMdGhlZnJvbnRzaWRlMRMwEQYKCZImiZPyLGQB
|
15
|
+
GRYDbmV0MB4XDTEzMDEzMDIxMDYwNFoXDTE0MDEzMDIxMDYwNFowRTEQMA4GA1UE
|
16
|
+
AwwHY293Ym95ZDEcMBoGCgmSJomT8ixkARkWDHRoZWZyb250c2lkZTETMBEGCgmS
|
17
|
+
JomT8ixkARkWA25ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAO45
|
18
|
+
CUxpETDGYXjCCy2dMg/aIrdrTqBqQW5ZrzhHxF9EkcdmWFr0z/qMz0JSpZ3pF11Z
|
19
|
+
KYaj5PaQQpjZfLPwbuiGGkuSWi+UAac//V18xo6S4lzRBjO+gpzG9f2AOzt9b+SR
|
20
|
+
Uc8UhO7QBZ5edUDxMxw9QstD+U0YBAlzsPJbHuUOqdtxXmNQCds3ZnqTgZaIpdUy
|
21
|
+
CSejtrukSmlthxFzwgMezYQhcYxmkl+Q475JUodnI6Pjc6nja/Or8Y6cEWiLgeUa
|
22
|
+
a+efcPGLDEbwJC7TGRrvk8yassMByBEJ3XueTMzeqWFd+665ptciojYo6BvIAR0N
|
23
|
+
iLwks0x567FZyS8SqTcCAwEAAaM5MDcwCQYDVR0TBAIwADAdBgNVHQ4EFgQUxVgR
|
24
|
+
5TUqf7Hd24ICb3g4FNbM7oYwCwYDVR0PBAQDAgSwMA0GCSqGSIb3DQEBBQUAA4IB
|
25
|
+
AQDdJj+NzZhiYXA56z0wzRUA/Fcf6CYqKB+RFRlPssDEcHTor5SnwdWgQof/gNLi
|
26
|
+
Qel1Om4zO0Shcp89jxaUqtvEdYVhmyfc0vycHmemKttNBT734yMrEJtF8Hhy+Dnz
|
27
|
+
9CzixXLvgGaRH+mf3M0+l+zIDJJr2L+39L8cyTSSRnp/srfI8aSmJKhGshudBKoC
|
28
|
+
Ty6Gi071pwoJXvdMaE/6iPy7bUzlndYdHyYuWSKaO9N47HqQ62oEnBraglw6ghoi
|
29
|
+
UgImJlChAzCoDP9zi9tdm6jAr7ttF25R9PPYr11ILb7dYe3qUzlNlM6zJx/nb31b
|
30
|
+
IhdyRVup4qLcqYSTPsm6u7VA
|
31
|
+
-----END CERTIFICATE-----
|
32
|
+
date: 2013-05-29 00:00:00.000000000 Z
|
33
|
+
dependencies:
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rails
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
type: :runtime
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: mixpanel
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
description: A Rails Engine for Mixpanel
|
63
|
+
email:
|
64
|
+
- cowboyd@thefrontside.net
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/mixpanel-rails.rb
|
75
|
+
- lib/mixpanel/engine.rb
|
76
|
+
- lib/mixpanel/helper.rb
|
77
|
+
- lib/mixpanel/rails.rb
|
78
|
+
- lib/mixpanel/rails/version.rb
|
79
|
+
- mixpanel-rails.gemspec
|
80
|
+
homepage: ''
|
81
|
+
licenses: []
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.0.0
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Autoconfigure your Rails environment for use with Mixpanel
|
103
|
+
test_files: []
|