lascivious 0.1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,62 @@
1
+ ### dev
2
+ [full changelog](http://github.com/Cloudability/lascivious/compare/v1.0.1...master)
3
+
4
+
5
+ ### v1.0.1
6
+ [full changelog](http://github.com/Cloudability/lascivious/compare/v1.0.0...v1.0.1)
7
+
8
+ Fixes
9
+
10
+ * Forgot to update changelog.
11
+
12
+
13
+ ### v1.0.0
14
+ [full changelog](http://github.com/Cloudability/lascivious/compare/v0.1.0...v1.0.0)
15
+
16
+ Fixes
17
+
18
+ * Overhaul documentation.
19
+ * Remove cruft.
20
+ * Change how we use Jeweler to update the gem
21
+
22
+
23
+ ### v0.1.0
24
+ [full changelog](http://github.com/Cloudability/lascivious/compare/v0.1.0.pre6...v0.1.0)
25
+
26
+ Fixes
27
+
28
+ * Fix references to `KissMetrics` class in documentation.
29
+ * Loosen `RubyGems` requirement.
30
+
31
+
32
+ ### v0.1.0.pre6
33
+ [full changelog](http://github.com/Cloudability/lascivious/compare/v0.1.0.pre5...v0.1.0.pre6)
34
+
35
+ Fixes
36
+
37
+ * Fix one last reference to `KissMetrics` class.
38
+
39
+
40
+ ### v0.1.0.pre5
41
+ [full changelog](http://github.com/Cloudability/lascivious/compare/v0.1.0.pre4...v0.1.0.pre5)
42
+
43
+ Fixes
44
+
45
+ * Turn this into a proper Rails Engine to fix missing partials issue.
46
+ * Fix a few more `KissMetrics` references.
47
+
48
+
49
+ ### v0.1.0.pre4
50
+ [full changelog](http://github.com/Cloudability/lascivious/compare/v0.1.0.pre3...v0.1.0.pre4)
51
+
52
+ Fixes
53
+
54
+ * Fix a few more `KissMetrics` references.
55
+
56
+
57
+ ### v0.1.0.pre3
58
+ [full changelog](http://github.com/Cloudability/lascivious/compare/v0.1.0.pre2...v0.1.0.pre3)
59
+
60
+ Fixes
61
+
62
+ * Fix loading order-of-operations issue.
@@ -1,3 +1,5 @@
1
+ (The MIT License)
2
+
1
3
  Copyright (c) 2011 Cloudability Inc.
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
@@ -0,0 +1,269 @@
1
+ # Lascivious
2
+
3
+ This plugin simplifies the use of KISSmetrics with Rails.
4
+
5
+ KISSmetrics really works best with Javascript. The problem is that in Rails
6
+ the best place to decide whether to fire off an event is inside a Controller.
7
+
8
+ Using a flash mechanism this plugin provides a series of helper functions to
9
+ allow your Controller to inject the correct Javascript into any page.
10
+
11
+
12
+ ## Instructions
13
+
14
+ 1. Install the gem by adding it to your Gemfile
15
+ 2. Add an initializer in `config/initializers/kiss_metrics.rb` like:
16
+
17
+ ```ruby
18
+ Lascivious.setup do |config|
19
+ config.api_key = "0000000000000000000000000000000000000000"
20
+ end
21
+ ```
22
+
23
+ 3. Replace the zeroes with your API key from <https://www.kissmetrics.com/settings>
24
+ 4. Add `kiss_metrics_tag` to whichever layouts you want to use KISSmetrics
25
+ with, usually all of them, e.g. here's what our header partial looks like:
26
+
27
+ ```erb
28
+ <title><%= title %></title>
29
+ <%= csrf_meta_tag %>
30
+ <link rel="image_src" href="/images/facebook-icon.png"/>
31
+ <%= kiss_metrics_tag %>
32
+ ```
33
+
34
+ 5. Now all you have to do is add KISSmetricss tags in controllers or views wherever you need something. For instance:
35
+
36
+ ```ruby
37
+ class SomeController < ApplicationController
38
+ def index
39
+ kiss_record "SomeController loaded"
40
+ end
41
+ end
42
+ ```
43
+
44
+ Currently the following commands are provided:
45
+
46
+ * `kiss_set <message>` - adds a 'set' event, e.g. 'country: uk'
47
+ * `kiss_identify <user_id>` - adds an 'identity' event, associating the given
48
+ user ID with the KISSmetrics identifier.
49
+ * `kiss_alias <value>` - adds an 'alias' event (weak identifier), e.g. user_id from a tracking cookie that may or may not be on a shared machine
50
+ * `kiss_record <message>` - adds a 'record' event with a message of 'message'
51
+ * `kiss_metric <event_type> <message>` - adds an event of type 'event_type' with a message of 'message'
52
+
53
+
54
+ ## How to Integrate with your app
55
+
56
+ Our service is built on Rails 3 with Devise and Inherited Resources. This is
57
+ how we integrated KISSmetricss into our app.
58
+
59
+ ### Everywhere
60
+
61
+ In all cases add this to the HEAD of your layouts:
62
+
63
+ ```erb
64
+ <%= kiss_metrics_tag %>
65
+ ```
66
+
67
+ And define your keys via an initializer in `app/config/initializers/kiss_metrics.rb`
68
+ like this:
69
+
70
+ ```ruby
71
+ Lascivious.setup do |config|
72
+ if Rails.env == 'production'
73
+ config.api_key = ENV['KISS_METRICS_API_KEY']
74
+ else
75
+ # Development/testing/staging account key...
76
+ config.api_key = "1111111111111111111111111111111111111111"
77
+ end
78
+ end
79
+ ```
80
+
81
+ ### Sign In
82
+
83
+ We use a Controller override in Devise as we want to handle a failed login very
84
+ specifically. So we have in `app/controllers/users/sessions_controller.rb`:
85
+
86
+ ```ruby
87
+ class Users::SessionsController < Devise::SessionsController
88
+ def create
89
+ warden_opts = { :scope => resource_name, :recall => "#{controller_path}#new" }
90
+ resource = warden.authenticate(warden_opts)
91
+ if(resource.nil?)
92
+ kind = :invalid
93
+ resource = build_resource
94
+ resource.errors[:base] = I18n.t("#{resource_name}.#{kind}", {
95
+ scope: "devise.failure",
96
+ default: [kind],
97
+ resource_name: resource_name
98
+ })
99
+ else
100
+ kiss_identify resource.email
101
+ kiss_record "Signed In"
102
+ set_flash_message(:notice, :signed_in) if is_navigational_format?
103
+ sign_in(resource_name, resource)
104
+ end
105
+ respond_with resource, :location => redirect_location(resource_name, resource)
106
+ end
107
+ end
108
+ ```
109
+
110
+ A much simpler version would be an `after_sign_in_path_for` override in
111
+ `app/controllers/application_controller.rb`:
112
+
113
+ ```ruby
114
+ private
115
+
116
+ def after_sign_in_path_for(resource_or_scope)
117
+ kiss_identify resource_or_scope.email unless resource_or_scope.email.nil?
118
+ kiss_record "Signed In"
119
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
120
+ home_path = "#{scope}_root_path"
121
+ respond_to?(home_path, true) ? send(home_path) : root_path
122
+ end
123
+ ```
124
+
125
+ ### Sign Out
126
+
127
+ We added this to `app/controllers/application_controller.rb`:
128
+
129
+ ```ruby
130
+ private
131
+
132
+ ### Record a sign out
133
+ def after_sign_out_path_for(resource_or_scope)
134
+ kiss_record "Signed Out"
135
+ new_user_session_path
136
+ end
137
+ ```
138
+
139
+ The `new_user_session_path` is important: if you redirect to `root_path` you
140
+ will be redirected to the login page (as your user will now fail authorization)
141
+ and in the process your flash will be wiped clear.
142
+
143
+ ### Email Open
144
+
145
+ Our Mailers typically look like this:
146
+
147
+ ```ruby
148
+ def send_mail(user, recipient, bill_period, subject)
149
+ @recipient ||= user
150
+ @user = user
151
+ @bill_period = bill_period
152
+ @data = collate(@user, @bill_period)
153
+
154
+ mail({
155
+ to: formatted_address(@user, @recipient),
156
+ subject: subject
157
+ })
158
+ end
159
+ ```
160
+
161
+ The `@recipient` variable is important to us, it allows us to send an email
162
+ even if we don't have a user setup.
163
+
164
+ Now inside the email partial we do:
165
+
166
+ ```erb
167
+ ... our email ERB template ...
168
+ <%= kiss_metrics_email_beacon @recipient.email, "Summary" %>
169
+ </body>
170
+ </html>
171
+ ```
172
+
173
+ Points to note here:
174
+
175
+ * This only works inside HTML emails and even then not all the time. If this
176
+ doesn't make sense to you go Google 'email pixels' or 'email beacons'
177
+ * Change "Summary" to be whichever email variant you have, it could be 'Welcome
178
+ Email' or 'Bill Reminder', etc.
179
+ * We've put the `kiss_metrics_email_beacon` at the bottom of the email, right
180
+ before the closing `body` tag. This reduces the chance the pixel kills your
181
+ layout and means the open is only triggered if the email is properly
182
+ downloaded and parsed.
183
+
184
+ ### General Activity
185
+
186
+ You get this for free on every page where you have included the
187
+ `kiss_metrics_tag` included in your layout.
188
+
189
+ ### Identity
190
+
191
+ See the `kiss_identify` tag above. We use the email address but you could use
192
+ a hash of this or the user record ID if you don't want to put the email address
193
+ inside a page. We prefer the email address (it's easier to understand what's
194
+ happening on a user by user basis) but some folks don't like to put an email
195
+ address inside a web page.
196
+
197
+ ### Activation & Sign Up
198
+
199
+ This gets a bit awkward. We have an `Invite` model that is a bit unusual.
200
+ Without going into the details this is what the controller looks like:
201
+
202
+ ```ruby
203
+ class InvitesController < InheritedResources::Base
204
+ respond_to :html
205
+ actions :new, :create
206
+
207
+ def new
208
+ new! do
209
+ kiss_record "Activated"
210
+ end
211
+ end
212
+
213
+ def create
214
+ create! do |success, failure|
215
+ success.html do
216
+ kiss_record "Signed Up"
217
+ sign_in(@invite.user)
218
+ kiss_identify current_user.email
219
+ redirect_to first_page_in_your_post_sign_up_path
220
+ end
221
+ end
222
+ end
223
+ end
224
+ ```
225
+
226
+ Beyond this you're on your own here, sorry.
227
+
228
+ ### Development vs Production
229
+
230
+ If you don't setup two sites - one for prod and the other for dev - your Prod
231
+ site will get polluted with your dev work. Or you can simply disable it. See
232
+ the example above for a template.
233
+
234
+ ### Other Stuff
235
+
236
+ You can add other events to your app by simply stating:
237
+
238
+ ```ruby
239
+ kiss_record "Some Other Event"
240
+ ```
241
+
242
+ You might want to record for instance the first time someone returns to your
243
+ site after they have purchased your product. You can work these events into
244
+ KISSmetricss really easily, with no setup required on the KM side.
245
+
246
+ See the API section for more details on what tools you have for doing this.
247
+
248
+
249
+ ## Contributing to Lascivious
250
+
251
+ * Check out the latest master to make sure the feature hasn't been implemented
252
+ or the bug hasn't been fixed yet.
253
+ * Check out the issue tracker to make sure someone already hasn't requested it
254
+ and/or contributed it.
255
+ * Fork the project.
256
+ * Start a feature/bugfix branch.
257
+ * Commit and push until you are happy with your contribution.
258
+ * Make sure to add tests for it. This is important so I don't break it in a
259
+ future version unintentionally.
260
+ * Please try not to mess with the Rakefile, version, or history. If you want to
261
+ have your own version, or is otherwise necessary, that is fine, but please
262
+ isolate to its own commit so I can cherry-pick around it.
263
+
264
+ ## Copyright
265
+
266
+ Copyright (c) 2011-2012 Cloudability Inc.
267
+
268
+ See LICENSE for further details.
269
+
@@ -4,59 +4,42 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{lascivious}
8
- s.version = "0.1.0"
7
+ s.name = "lascivious"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Mat Ellis"]
12
- s.date = %q{2011-09-14}
13
- s.description = %q{Easy interface between Rails & Javascript for Kiss Metrics}
14
- s.email = %q{support@cloudability.com}
11
+ s.authors = ["Mat Ellis", "Jon Frisby"]
12
+ s.date = "2012-08-14"
13
+ s.description = "Easy interface between Rails & Javascript for KISSmetrics"
14
+ s.email = "support@cloudability.com"
15
15
  s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc"
16
+ "CHANGELOG.md",
17
+ "LICENSE",
18
+ "README.md"
18
19
  ]
19
20
  s.files = [
20
- ".document",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "LICENSE.txt",
24
- "README.rdoc",
25
- "Rakefile",
21
+ "CHANGELOG.md",
22
+ "LICENSE",
23
+ "README.md",
26
24
  "app/views/lascivious/_email_beacon.html.erb",
27
25
  "app/views/lascivious/_header.html.erb",
28
26
  "lascivious.gemspec",
29
27
  "lib/engine.rb",
30
- "lib/lascivious.rb",
31
- "lib/version.rb",
32
- "test/helper.rb",
33
- "test/test_lascivious.rb"
28
+ "lib/lascivious.rb"
34
29
  ]
35
- s.homepage = %q{https://github.com/cloudability/lascivious}
30
+ s.homepage = "https://github.com/cloudability/lascivious"
36
31
  s.licenses = ["MIT"]
37
32
  s.require_paths = ["lib"]
38
- s.rubygems_version = %q{1.6.2}
39
- s.summary = %q{Easy Kiss Metrics integration for Rails}
33
+ s.rubygems_version = "1.8.24"
34
+ s.summary = "Easy KISSmetrics integration for Rails"
40
35
 
41
36
  if s.respond_to? :specification_version then
42
37
  s.specification_version = 3
43
38
 
44
39
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
- s.add_development_dependency(%q<shoulda>, [">= 0"])
46
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
48
- s.add_development_dependency(%q<rcov>, [">= 0"])
49
40
  else
50
- s.add_dependency(%q<shoulda>, [">= 0"])
51
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
52
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
53
- s.add_dependency(%q<rcov>, [">= 0"])
54
41
  end
55
42
  else
56
- s.add_dependency(%q<shoulda>, [">= 0"])
57
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
59
- s.add_dependency(%q<rcov>, [">= 0"])
60
43
  end
61
44
  end
62
45
 
@@ -1,23 +1,23 @@
1
1
  require 'engine'
2
2
 
3
3
  module Lascivious
4
-
4
+
5
5
  # API key for Kiss Metrics. Available via https://www.kissmetrics.com/settings
6
6
  mattr_accessor :api_key
7
7
  @@api_key = ""
8
8
  ::ActionView::Base.send(:include, Lascivious)
9
9
  ::ActionController::Base.send(:include, Lascivious)
10
-
10
+
11
11
  # For use in config so we can do Lascivious.setup
12
12
  def self.setup
13
13
  yield self
14
14
  end
15
-
15
+
16
16
  # The main kiss metrics javascript & stuff
17
17
  def kiss_metrics_tag
18
18
  render :partial => "lascivious/header"
19
19
  end
20
-
20
+
21
21
  # The email beacon
22
22
  def kiss_metrics_email_beacon(email_address, variation, event_type = "Opened Email")
23
23
  render :partial => "lascivious/email_beacon", :locals => {
@@ -27,7 +27,7 @@ module Lascivious
27
27
  :variation => variation
28
28
  }
29
29
  end
30
-
30
+
31
31
  # Flash for all kiss metrics
32
32
  def kiss_metrics_flash
33
33
  messages = flash[:kiss_metrics]
@@ -45,30 +45,30 @@ module Lascivious
45
45
  def kiss_record(value)
46
46
  kiss_metric :record, value
47
47
  end
48
-
48
+
49
49
  # Set values (e.g. country: uk)
50
50
  def kiss_set(value)
51
51
  kiss_metric :set, value
52
52
  end
53
-
53
+
54
54
  # Strong identifier (e.g. user ID)
55
55
  def kiss_identify(value)
56
56
  kiss_metric :identify, value
57
57
  end
58
-
58
+
59
59
  # Weak identifier (e.g. cookie)
60
60
  def kiss_alias(value)
61
61
  kiss_metric :alias, value
62
62
  end
63
63
 
64
- #
64
+ # Record an arbitrary event-type and its value.
65
65
  def kiss_metric(event_type, value)
66
66
  flash[:kiss_metrics] ||= []
67
67
  flash[:kiss_metrics] << { event_type => value }
68
68
  end
69
-
69
+
70
70
  # Get kiss metrics key
71
71
  def kiss_metrics_api_key
72
72
  return Lascivious.api_key
73
73
  end
74
- end
74
+ end
metadata CHANGED
@@ -1,84 +1,34 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lascivious
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mat Ellis
9
+ - Jon Frisby
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2011-09-14 00:00:00.000000000 -07:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: shoulda
17
- requirement: &70221463513840 !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
23
- type: :development
24
- prerelease: false
25
- version_requirements: *70221463513840
26
- - !ruby/object:Gem::Dependency
27
- name: bundler
28
- requirement: &70221463512940 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 1.0.0
34
- type: :development
35
- prerelease: false
36
- version_requirements: *70221463512940
37
- - !ruby/object:Gem::Dependency
38
- name: jeweler
39
- requirement: &70221463511900 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ~>
43
- - !ruby/object:Gem::Version
44
- version: 1.6.4
45
- type: :development
46
- prerelease: false
47
- version_requirements: *70221463511900
48
- - !ruby/object:Gem::Dependency
49
- name: rcov
50
- requirement: &70221463485940 !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ! '>='
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
- type: :development
57
- prerelease: false
58
- version_requirements: *70221463485940
59
- description: Easy interface between Rails & Javascript for Kiss Metrics
13
+ date: 2012-08-14 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: Easy interface between Rails & Javascript for KISSmetrics
60
16
  email: support@cloudability.com
61
17
  executables: []
62
18
  extensions: []
63
19
  extra_rdoc_files:
64
- - LICENSE.txt
65
- - README.rdoc
20
+ - CHANGELOG.md
21
+ - LICENSE
22
+ - README.md
66
23
  files:
67
- - .document
68
- - Gemfile
69
- - Gemfile.lock
70
- - LICENSE.txt
71
- - README.rdoc
72
- - Rakefile
24
+ - CHANGELOG.md
25
+ - LICENSE
26
+ - README.md
73
27
  - app/views/lascivious/_email_beacon.html.erb
74
28
  - app/views/lascivious/_header.html.erb
75
29
  - lascivious.gemspec
76
30
  - lib/engine.rb
77
31
  - lib/lascivious.rb
78
- - lib/version.rb
79
- - test/helper.rb
80
- - test/test_lascivious.rb
81
- has_rdoc: true
82
32
  homepage: https://github.com/cloudability/lascivious
83
33
  licenses:
84
34
  - MIT
@@ -94,7 +44,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
44
  version: '0'
95
45
  segments:
96
46
  - 0
97
- hash: 1716301593935205180
47
+ hash: 2788297189396306074
98
48
  required_rubygems_version: !ruby/object:Gem::Requirement
99
49
  none: false
100
50
  requirements:
@@ -103,8 +53,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
53
  version: '0'
104
54
  requirements: []
105
55
  rubyforge_project:
106
- rubygems_version: 1.6.2
56
+ rubygems_version: 1.8.24
107
57
  signing_key:
108
58
  specification_version: 3
109
- summary: Easy Kiss Metrics integration for Rails
59
+ summary: Easy KISSmetrics integration for Rails
110
60
  test_files: []
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/Gemfile DELETED
@@ -1,13 +0,0 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
-
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "shoulda", ">= 0"
10
- gem "bundler", "~> 1.0.0"
11
- gem "jeweler", "~> 1.6.4"
12
- gem "rcov", ">= 0"
13
- end
@@ -1,20 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- git (1.2.5)
5
- jeweler (1.6.4)
6
- bundler (~> 1.0)
7
- git (>= 1.2.5)
8
- rake
9
- rake (0.9.2)
10
- rcov (0.9.9)
11
- shoulda (2.11.3)
12
-
13
- PLATFORMS
14
- ruby
15
-
16
- DEPENDENCIES
17
- bundler (~> 1.0.0)
18
- jeweler (~> 1.6.4)
19
- rcov
20
- shoulda
@@ -1,218 +0,0 @@
1
- = Lascivious
2
-
3
- This plugin simplifies the use of Kiss Metrics with Rails.
4
-
5
- Kiss Metrics really works best with Javascript. The problem is that in Rails the best place to decide whether to fire off an event is inside a Controller.
6
-
7
- Using a flash mechanism this plugin provides a series of helper functions to allow your Controller to inject the correct Javascript into any page.
8
-
9
- It's a work-in-progress right now and is pretty dumb: you have to RTFM on when to insert what. We will probably extend functionality to handle aliasing and strong typing of users.
10
-
11
-
12
- == Instructions
13
-
14
- 1. Install the gem by adding it to your Gemfile
15
- 2. Add an initializer in `config/initializers/kiss_metrics.rb` like:
16
-
17
- Lascivious.setup do |config|
18
- config.api_key="0000000000000000000000000000000000000000"
19
- end
20
-
21
- 3. Replace the zeroes with your API key from https://www.kissmetrics.com/settings
22
- 4. Add the kiss metrics tag to whichever layouts you want to use Kiss Metrics with, usually all of them, e.g. here's what our header partial looks like:
23
-
24
- <title><%= title %></title>
25
- <%= csrf_meta_tag %>
26
- <link rel="image_src" href="/images/facebook-icon.png"/>
27
- <%= kiss_metrics_tag %>
28
-
29
- 5. Now all you have to do is add Kiss Metrics tags in controllers or views wherever you need something. For instance:
30
-
31
- class SomeController < ApplicationController
32
- def index
33
- kiss_record "SomeController loaded"
34
- end
35
- end
36
-
37
- Currently the following commands are provided:
38
-
39
- - `kiss_record <message>` - adds a 'record' event with a message of 'message'
40
- - `kiss_metric <event_type> <message>` - adds an event of type 'event_type' with a message of 'message'
41
-
42
- We will soon add helpers for things like `kiss_alias`, etc.
43
-
44
-
45
- == How to Integrate with your app
46
-
47
- Our service is built on Rails 3 with Devise and Inherited Resources. This is how we integrated Kiss Metrics into our app.
48
-
49
- 0. Everywhere
50
-
51
- In all cases add this to the HEAD of your layouts:
52
-
53
- <%= kiss_metrics_tag %>
54
-
55
- And define your keys via an initializer in `app/config/initializers/kiss_metrics.rb` like this:
56
-
57
- Lascivious.setup do |config|
58
- if Rails.env == 'production'
59
- config.api_key="2222222222222222222222222222222222222222"
60
- else
61
- config.api_key="1111111111111111111111111111111111111111"
62
- end
63
- end
64
-
65
-
66
- 1. Sign In
67
-
68
- We use a Controller override in Devise as we want to handle a failed login very specifically. So we have in `app/controllers/users/sessions_controller.rb`:
69
-
70
- class Users::SessionsController < Devise::SessionsController
71
- def create
72
- warden_opts = { :scope => resource_name, :recall => "#{controller_path}#new" }
73
- resource = warden.authenticate(warden_opts)
74
- if(resource.nil?)
75
- kind = :invalid
76
- resource = build_resource
77
- resource.errors[:base] = I18n.t("#{resource_name}.#{kind}", {
78
- scope: "devise.failure",
79
- default: [kind],
80
- resource_name: resource_name
81
- })
82
- else
83
- kiss_identify resource.email
84
- kiss_record "Signed In"
85
- set_flash_message(:notice, :signed_in) if is_navigational_format?
86
- sign_in(resource_name, resource)
87
- end
88
- respond_with resource, :location => redirect_location(resource_name, resource)
89
- end
90
- end
91
-
92
- A much simpler version would be an `after_sign_in_path_for` override in `app/controllers/application_controller.rb`:
93
-
94
- private
95
-
96
- def after_sign_in_path_for(resource_or_scope)
97
- kiss_identify resource_or_scope.email unless resource_or_scope.email.nil?
98
- kiss_record "Signed In"
99
- scope = Devise::Mapping.find_scope!(resource_or_scope)
100
- home_path = "#{scope}_root_path"
101
- respond_to?(home_path, true) ? send(home_path) : root_path
102
- end
103
-
104
- 2. Sign Out
105
-
106
- We added this to `app/controllers/application_controller.rb`:
107
-
108
- private
109
-
110
- # Record a sign out
111
- def after_sign_out_path_for(resource_or_scope)
112
- kiss_record "Signed Out"
113
- new_user_session_path
114
- end
115
-
116
- The `new_user_session_path` is important: if you redirect to `root_path` you will be redirected to the login page (as your user will now fail authorization) and in the process your flash will be wiped clear.
117
-
118
- 3. Email Open
119
-
120
- Our Mailers typically look like this:
121
-
122
- def send_mail(user, recipient, bill_period, subject)
123
- @recipient ||= user
124
- @user = user
125
- @bill_period = bill_period
126
- @data = collate(@user, @bill_period)
127
-
128
- mail({
129
- to: formatted_address(@user, @recipient),
130
- subject: subject
131
- })
132
- end
133
-
134
- The @recipient variable is important to us, it allows us to send an email even if we don't have a user setup.
135
-
136
- Now inside the email partial we do:
137
-
138
- ... our email ERB or HAML template ...
139
- <%= kiss_metrics_email_beacon @recipient.email, "Summary" %>
140
- </body>
141
- </html>
142
-
143
- Points to note here:
144
- - This only works inside HTML emails and even then not all the time. If this doesn't make sense to you go Google 'email pixels' or 'email beacons'
145
- - Change "Summary" to be whichever email variant you have, it could be 'Welcome Email' or 'Bill Reminder', etc.
146
- - We've put the kiss_metrics_email_beacon at the bottom of the email, right before the closing BODY tag. This reduces the chance the pixel kills your layout and means the open is only triggered if the email is properly downloaded and parsed.
147
-
148
- 4. General Activity
149
-
150
- You get this for free on every page where you have included the `kiss_metrics_tag` included in your layout.
151
-
152
- 5. Identity
153
-
154
- See the kiss_identify tag in section 1 above. We use the email address but you could use a hash of this or the user record ID if you don't want to put the email address inside a page. We prefer the email address (it's easier to understand what's happening on a user by user basis) but some folks don't like to put an email address inside a web page.
155
-
156
- 6. Activation & Sign Up
157
-
158
- This gets a bit awkward. We have an 'invite' model that is a bit unusual. Without going into the details this is what the controller looks like:
159
-
160
- class InvitesController < InheritedResources::Base
161
- respond_to :html
162
- actions :new, :create
163
-
164
- def new
165
- new! do
166
- kiss_record "Activated"
167
- end
168
- end
169
-
170
- def create
171
- create! do |success, failure|
172
- success.html do
173
- kiss_record "Signed Up"
174
- sign_in(@invite.user)
175
- kiss_identify current_user.email
176
- redirect_to first_page_in_your_post_sign_up_path
177
- end
178
- end
179
- end
180
- end
181
-
182
- Beyond this you're on your own here, sorry.
183
-
184
- 7. Dev vs Prod
185
-
186
- If you don't setup two sites - one for prod and the other for dev - your Prod site will get polluted with your dev work. Or you can simply disable it. See the example in step 0 above for a template.
187
-
188
- 8. Other Stuff
189
-
190
- You can add other events to your app by simply stating:
191
-
192
- kiss_record "Some Other Event"
193
-
194
- You might want to record for instance the first time someone returns to your site after they have purchased your product. You can work these events into Kiss Metrics really easily, with no setup required on the KM side.
195
-
196
- Lascivious also supports:
197
-
198
- - kiss_set(value)
199
- - kiss_identify(value)
200
- - kiss_alias(value)
201
- - kiss_metric(event_type, value)
202
-
203
-
204
- == Contributing to lascivious
205
-
206
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
207
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
208
- * Fork the project
209
- * Start a feature/bugfix branch
210
- * Commit and push until you are happy with your contribution
211
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
212
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
213
-
214
- == Copyright
215
-
216
- Copyright (c) 2011 Cloudability Inc. See LICENSE.txt for
217
- further details.
218
-
data/Rakefile DELETED
@@ -1,53 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- require './lib/version.rb'
16
- Jeweler::Tasks.new do |gem|
17
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
- gem.name = "lascivious"
19
- gem.homepage = "https://github.com/cloudability/lascivious"
20
- gem.license = "MIT"
21
- gem.summary = %Q{Easy Kiss Metrics integration for Rails}
22
- gem.description = %Q{Easy interface between Rails & Javascript for Kiss Metrics}
23
- gem.email = "support@cloudability.com"
24
- gem.authors = ["Mat Ellis"]
25
- gem.version = Lascivious::Version::STRING
26
- # dependencies defined in Gemfile
27
- end
28
- Jeweler::RubygemsDotOrgTasks.new
29
-
30
- require 'rake/testtask'
31
- Rake::TestTask.new(:test) do |test|
32
- test.libs << 'lib' << 'test'
33
- test.pattern = 'test/**/test_*.rb'
34
- test.verbose = true
35
- end
36
-
37
- require 'rcov/rcovtask'
38
- Rcov::RcovTask.new do |test|
39
- test.libs << 'test'
40
- test.pattern = 'test/**/test_*.rb'
41
- test.verbose = true
42
- test.rcov_opts << '--exclude "gems/*"'
43
- end
44
-
45
- task :default => :test
46
-
47
- require 'rake/rdoctask'
48
- Rake::RDocTask.new do |rdoc|
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "lascivious #{Lascivious::Version::STRING}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
@@ -1,10 +0,0 @@
1
- class Lascivious
2
- module Version
3
- MAJOR = 0
4
- MINOR = 1
5
- PATCH = 0
6
- BUILD = nil
7
-
8
- STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
9
- end
10
- end
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
- require 'shoulda'
12
-
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- $LOAD_PATH.unshift(File.dirname(__FILE__))
15
- require 'lascivious'
16
-
17
- class Test::Unit::TestCase
18
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestLascivious < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end