lita-mixpanel 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/README.md +47 -0
- data/Rakefile +1 -0
- data/lib/lita-mixpanel.rb +12 -0
- data/lib/lita/handlers/mixpanel.rb +49 -0
- data/lib/mixpanel_stats.rb +107 -0
- data/lita-mixpanel.gemspec +22 -0
- data/locales/en.yml +4 -0
- data/spec/lita/handlers/mixpanel_spec.rb +4 -0
- data/spec/spec_helper.rb +6 -0
- data/templates/.gitkeep +0 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4350d8ac4092933f474c9d3e7443299175cc3dfa
|
4
|
+
data.tar.gz: 2c523417c98b9c5b195531d1a11470c36bf43d20
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f94824cdcab78fb0c7238445dbc6afb6ae6d49f4e1ea3952c9b8e340a6e797f5d967665881921cdaa62707afc638cff432ed04615c37b00f1819a15023e41569
|
7
|
+
data.tar.gz: 6b1637ec37d0451f0c687c1e7b4ff9056ef066172dea566346714ea6bda9503b384606b2a5e7a161189c7920d50b0fe2ea6334e97a2327a1eb971737a584a2f5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# lita-mixpanel
|
2
|
+
|
3
|
+
**lita-mixpanel** is a handler for [Lita](https://github.com/jimmycuadra/lita) that provides current KPI information from mixpanel
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add lita-mixpanel to your Lita instance's Gemfile:
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem "lita-mixpanel"
|
11
|
+
```
|
12
|
+
|
13
|
+
|
14
|
+
## Configuration
|
15
|
+
|
16
|
+
This plugin requires a working mixpanel account & api_key & api_secret. FUNNEL_ID can be obtained from the mixpanel dashboard (see id url). FUNNEL_NAME is arbitrary and for display purpuses only.
|
17
|
+
|
18
|
+
``` ruby
|
19
|
+
config.handlers.mixpanel.api_key = 'MIXPANEL_API_KEY'
|
20
|
+
config.handlers.mixpanel.api_secret = 'MIXPANEL_API_SECRET'
|
21
|
+
config.handlers.mixpanel.funnels = {
|
22
|
+
"FUNNEL_ID" =>"FUNNEL_NAME",
|
23
|
+
}
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
```
|
29
|
+
Lita: mixpanel funnels
|
30
|
+
|
31
|
+
---
|
32
|
+
Funnel performance for: FUNNEL_NAME
|
33
|
+
2015-06-12 CR=2.26% 8/354
|
34
|
+
2015-06-13 CR=3.88% 19/490
|
35
|
+
2015-06-14 CR=2.61% 17/651
|
36
|
+
2015-06-15 CR=2.61% 21/804
|
37
|
+
2015-06-16 CR=4.58% 28/611
|
38
|
+
2015-06-17 CR=2.44% 11/450
|
39
|
+
2015-06-18 CR=4.49% 12/267
|
40
|
+
2015-06-19 CR=0.00% 0/13 <- today
|
41
|
+
--------------------
|
42
|
+
TOTAL CR=3.19% 116/3640
|
43
|
+
```
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
[MIT](http://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "lita"
|
2
|
+
|
3
|
+
Lita.load_locales Dir[File.expand_path(
|
4
|
+
File.join("..", "..", "locales", "*.yml"), __FILE__
|
5
|
+
)]
|
6
|
+
|
7
|
+
require "lita/handlers/mixpanel"
|
8
|
+
|
9
|
+
Lita::Handlers::Mixpanel.template_root File.expand_path(
|
10
|
+
File.join("..", "..", "templates"),
|
11
|
+
__FILE__
|
12
|
+
)
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'mixpanel_stats'
|
2
|
+
|
3
|
+
module Lita
|
4
|
+
module Handlers
|
5
|
+
class Mixpanel < Handler
|
6
|
+
|
7
|
+
def self.default_config(config)
|
8
|
+
config.api_key = nil
|
9
|
+
config.api_secret = nil
|
10
|
+
config.funnels = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
route %r{(mixpanel)}i,
|
14
|
+
:funnels_stats,
|
15
|
+
command: true,
|
16
|
+
help: {
|
17
|
+
"mixpanel funnels" => "gets recent funnels performance from mixpanel"}
|
18
|
+
|
19
|
+
def funnels_stats(response)
|
20
|
+
(funnels || []).each do |id, name|
|
21
|
+
funnel_stats = generate_funnel_stats(id)
|
22
|
+
msg = "Funnel performance for: #{name}\n"
|
23
|
+
msg << funnel_stats
|
24
|
+
response.reply "/code " + msg
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def generate_funnel_stats(funnel_id)
|
29
|
+
to = Date.today
|
30
|
+
from = Date.today - 7
|
31
|
+
mixpanel.funnel_chart(funnel_id, from, to)
|
32
|
+
end
|
33
|
+
|
34
|
+
def mixpanel
|
35
|
+
@mixpanel ||= MixpanelStats.new(
|
36
|
+
Lita.config.handlers.mixpanel.api_key,
|
37
|
+
Lita.config.handlers.mixpanel.api_secret,
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def funnels
|
42
|
+
Lita.config.handlers.mixpanel.funnels
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
Lita.register_handler(Mixpanel)
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'mixpanel_client'
|
2
|
+
|
3
|
+
class MixpanelStats
|
4
|
+
def initialize(key, secret)
|
5
|
+
@key, @secret = key, secret
|
6
|
+
end
|
7
|
+
|
8
|
+
def funnel_chart(funnel_id, from, to)
|
9
|
+
chart_data = funnel_data(funnel_id, from, to)
|
10
|
+
chart = FunnelChart.new(chart_data)
|
11
|
+
chart.to_s
|
12
|
+
end
|
13
|
+
protected
|
14
|
+
|
15
|
+
def funnel_data(funnel_id, from, to)
|
16
|
+
from = from.iso8601 if from.is_a?(Date)
|
17
|
+
to = to.iso8601 if to.is_a?(Date)
|
18
|
+
|
19
|
+
client.request("funnels/",
|
20
|
+
funnel_id: funnel_id,
|
21
|
+
from_date: from,
|
22
|
+
to_date: to,
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def client
|
27
|
+
@client ||= Mixpanel::Client.new(
|
28
|
+
api_key: @key,
|
29
|
+
api_secret: @secret
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class FunnelChart
|
35
|
+
|
36
|
+
# data example:
|
37
|
+
# {"meta"=>{"dates"=>["2015-05-17"]},
|
38
|
+
# "data"=>{
|
39
|
+
# "2015-05-17"=>
|
40
|
+
# {"steps"=>[
|
41
|
+
# {"count"=>579,
|
42
|
+
# "step_conv_ratio"=>1,
|
43
|
+
# "goal"=>"Landing page view",
|
44
|
+
# "overall_conv_ratio"=>1,
|
45
|
+
# "avg_time"=>nil,
|
46
|
+
# "event"=>"Landing page view"},
|
47
|
+
# {"count"=>9,
|
48
|
+
# "step_conv_ratio"=>0.015544041450777202,
|
49
|
+
# "goal"=>"Download page view",
|
50
|
+
# "overall_conv_ratio"=>0.015544041450777202,
|
51
|
+
# "avg_time"=>211, "event"=>"Download page view"
|
52
|
+
# }
|
53
|
+
# ],
|
54
|
+
# "analysis"=>{
|
55
|
+
# "completion"=>9,
|
56
|
+
# "starting_amount"=>579,
|
57
|
+
# "steps"=>2,
|
58
|
+
# "worst"=>1}
|
59
|
+
# }}}
|
60
|
+
def initialize(mixpanel_data)
|
61
|
+
@dates = mixpanel_data['meta']['dates']
|
62
|
+
@data = mixpanel_data['data']
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_s
|
66
|
+
stats = []
|
67
|
+
parts = @dates.map do |date|
|
68
|
+
stat = date_stats(date)
|
69
|
+
stats << stat
|
70
|
+
line = format_line(date, stat)
|
71
|
+
line << " <- today" if date == Date.today.iso8601
|
72
|
+
line
|
73
|
+
end
|
74
|
+
parts << "-"*20
|
75
|
+
parts << format_line("TOTAL ", calc_totals(stats))
|
76
|
+
parts.join("\n")
|
77
|
+
end
|
78
|
+
|
79
|
+
def calc_totals(stats)
|
80
|
+
total_completion, total_start = 0,0,0
|
81
|
+
stats.each do |_, completion, start|
|
82
|
+
total_completion += completion
|
83
|
+
total_start += start
|
84
|
+
end
|
85
|
+
total_cr = total_completion.to_f/total_start.to_f
|
86
|
+
return [total_cr, total_completion, total_start]
|
87
|
+
end
|
88
|
+
|
89
|
+
def date_stats(date)
|
90
|
+
stats = @data[date]
|
91
|
+
analysis = stats['analysis']
|
92
|
+
start = analysis['starting_amount']
|
93
|
+
completion = analysis['completion']
|
94
|
+
cr = completion.to_f / start.to_f
|
95
|
+
[cr, completion, start]
|
96
|
+
end
|
97
|
+
|
98
|
+
def format_line(title, stats)
|
99
|
+
cr, completion, start = stats
|
100
|
+
"#{title} CR=#{percent(cr)} #{completion}/#{start}"
|
101
|
+
end
|
102
|
+
|
103
|
+
def percent(float)
|
104
|
+
"%.2f%" % (float * 100)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-mixpanel"
|
3
|
+
spec.version = "0.2.0"
|
4
|
+
spec.authors = ["Eugen Martin"]
|
5
|
+
spec.email = ["eugeniusmartinus@gmail.com"]
|
6
|
+
spec.description = "a mixpanl plugin for lita chat-bot"
|
7
|
+
spec.summary = "Is a handler for [Lita](https://github.com/jimmycuadra/lita) that provides current KPI information from mixpanel"
|
8
|
+
spec.homepage = "https://github.com/olgen/lita-mixpanel"
|
9
|
+
spec.license = "http://opensource.org/licenses/MIT"
|
10
|
+
spec.metadata = { "lita_plugin_type" => "handler" }
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($/)
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
|
17
|
+
spec.add_runtime_dependency "lita", ">= 4.4"
|
18
|
+
spec.add_runtime_dependency "mixpanel_client", ">= 4.1"
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
data/locales/en.yml
ADDED
data/spec/spec_helper.rb
ADDED
data/templates/.gitkeep
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-mixpanel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eugen Martin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lita
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mixpanel_client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
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
|
+
description: a mixpanl plugin for lita chat-bot
|
70
|
+
email:
|
71
|
+
- eugeniusmartinus@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/lita-mixpanel.rb
|
81
|
+
- lib/lita/handlers/mixpanel.rb
|
82
|
+
- lib/mixpanel_stats.rb
|
83
|
+
- lita-mixpanel.gemspec
|
84
|
+
- locales/en.yml
|
85
|
+
- spec/lita/handlers/mixpanel_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
- templates/.gitkeep
|
88
|
+
homepage: https://github.com/olgen/lita-mixpanel
|
89
|
+
licenses:
|
90
|
+
- http://opensource.org/licenses/MIT
|
91
|
+
metadata:
|
92
|
+
lita_plugin_type: handler
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.4.5
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Is a handler for [Lita](https://github.com/jimmycuadra/lita) that provides
|
113
|
+
current KPI information from mixpanel
|
114
|
+
test_files:
|
115
|
+
- spec/lita/handlers/mixpanel_spec.rb
|
116
|
+
- spec/spec_helper.rb
|