segment_rails 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07161f46bb75eee60819900280f1bd5041044f49
4
- data.tar.gz: 27cd794e9a7b631615e44a5d534ec11a7b784cbc
3
+ metadata.gz: b3cc0e7317a4be2398f2845fad440ec6f7d6d620
4
+ data.tar.gz: 0239c02f96c3b938007accd27f3ef852b01c2c0a
5
5
  SHA512:
6
- metadata.gz: f5b263b84825924fe12b597eb1389f5352b2af0091ea9b4154c12cd0693080fb688386f8fd4988604c7c738b9cc330044579c064337c48be6678dc079e643f23
7
- data.tar.gz: 05e9b199bbbf0c7da71308d81686796611ba87f7f152fb31bde2bf979d4840a831d10c6f8d84fef402e4a5ff19dde7920cbfad57be8075e00be0130ca9751166
6
+ metadata.gz: 874c52ec7cc6db92006887ac2bdf82c883e65395897aa8e60869051dd8833b1d5d7bd11cb7652e1ff3825db63facbd1f6870ba65130e7fdf4c28e41258017e66
7
+ data.tar.gz: 9178bf6d36c20637850618a001091d1c430453bfb52a195d9854dbdc36364e7d7c45e2ed19ecb397934b74bca0df5f6a626492ee199ebc6bc7bb61e9009dca98
data/README.md CHANGED
@@ -19,7 +19,15 @@ with Segment. Mmmm, now we get the lovely referring domain and utm data!
19
19
  ## Installation + Usage
20
20
 
21
21
  1. Add `segment_rails` to your Gemfile
22
- 2. Add `include SegmentRails` to your `ApplicationController`
22
+ 2. Configure `segment_rails` in your `ApplicationController`
23
+ ```
24
+ class ApplicationController < ActionController::Base
25
+ include SegmentRails
26
+ set_user_identifier ->() do
27
+ current_user ? current_user.id : nil
28
+ end
29
+ end
30
+ ```
23
31
  3. Instrument your controllers with `track_event("Timmy fell down the
24
32
  well", { reporter: :lassie })`
25
33
  4. Profit! (Or at least, observe behaviors which you hope will lead to profit)
data/lib/segment_rails.rb CHANGED
@@ -1,12 +1,33 @@
1
+ require 'json'
1
2
  module SegmentRails
2
- module Rails
3
- class Engine < ::Rails::Engine
3
+ if const_defined? :Rails
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
4
7
  end
5
8
  end
6
9
 
10
+ module ClassMethods
11
+ def set_user_identifier(callback)
12
+ @user_identifier = callback
13
+ end
14
+
15
+ def user_identifier
16
+ @user_identifier ? @user_identifier.call() : nil
17
+ end
18
+ end
19
+
20
+ def self.included(klazz)
21
+ klazz.extend(ClassMethods)
22
+ end
23
+
24
+ def user_identifier
25
+ self.class.user_identifier
26
+ end
27
+
7
28
  def track_event(event_name, properties={})
8
29
  analytics = cookies[:analytics] ? JSON.parse(cookies[:analytics]) : {}
9
- analytics[:uuid] = current_user.uuid if current_user
30
+ analytics[:uuid] = user_identifier if user_identifier
10
31
  analytics[:events] ||= []
11
32
  analytics[:events].push({ name: event_name, properties: properties})
12
33
  cookies[:analytics] = JSON.dump(analytics)
@@ -1,4 +1,4 @@
1
1
  module SegmentRails
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: segment_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zee Spencer