intel 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6afd8d515e1b008debd378f41f709f6a9e59b20
4
- data.tar.gz: e514f5ffc47f3e45bdb1ab72b68117d50201e981
3
+ metadata.gz: 31879a36e725be72dc34b53afa077f6d2f31bc7b
4
+ data.tar.gz: 697d5bf3d20c5cc93c5d42df6ab868cb24834df8
5
5
  SHA512:
6
- metadata.gz: ba504e4d707d5bdd3aa542443bb3769418bf4e13aa5d1ddef9cc855f1aeca7e99faea8034c66c12a7f0ba4dd42d57d4aa3696a890408d3d71048c4af3ca2a151
7
- data.tar.gz: ba7dae63eaa56c1380733f31acde069c9e1a84be927af85dd1109abb44b358c7c1e2aeccbb2823d1c8d6062e0c63fd8dbea92ffdfbce5c5c73efb0231cffc34c
6
+ metadata.gz: e62375f43d6f457a653b9e45c56801620948d0b81a53e55b83a8e7ecd3aa1d69bf42c67f8498c7c994facb9ef0e292446ee5d2ddc53955db8b2437d3bf288b4f
7
+ data.tar.gz: 9266b4153c82fc6bf57390a5b3143401e2a483b74dbc6129dfde691d3b079aaeff189ae25a218c3f3ccc518ef98bc27061bb452ae8c25cf29e5d38635325490e
data/README.md CHANGED
@@ -63,41 +63,22 @@ It’s that easy.
63
63
 
64
64
  ### Track Conversions
65
65
 
66
- Tracking conversions is super important.
66
+ First, choose a conversion metric. At [Instacart](https://www.instacart.com/), an item added to the cart from the search results page counts as a conversion.
67
67
 
68
- First, define your conversion metric. This is specific to your application.
68
+ Next, when a user searches, keep track of the search id. With Searchkick, you can get the id with `@results.search.id`.
69
69
 
70
- Next, when a user searches, keep track of the search id.
70
+ When a user converts, find the record and call `converted`.
71
71
 
72
72
  ```ruby
73
- @items = Item.search "apple", track: true
74
- @items.search.id # returns search id
73
+ search = Intel::Search.find params[:id]
74
+ search.converted
75
75
  ```
76
76
 
77
- When a user converts, mark it.
78
-
79
- ```ruby
80
- search = Intel::Search.find params[:search_id]
81
- search.converted_at = Time.now
82
- search.save
83
- ```
84
-
85
- Better yet, record the result that converted.
77
+ Better yet, record the model that converted.
86
78
 
87
79
  ```ruby
88
80
  item = Item.find params[:item_id]
89
- search.convertable = item
90
- search.save
91
- ```
92
-
93
- The item will appear in the live stream. Add the `intel_name` method to your model to change what is displayed.
94
-
95
- ```ruby
96
- class Item < ActiveRecord::Base
97
- def intel_name
98
- title # use the title method
99
- end
100
- end
81
+ search.converted(item)
101
82
  ```
102
83
 
103
84
  ### Authentication
@@ -139,6 +120,14 @@ Change the number of top searches shown with:
139
120
  Intel.top_searches = 500 # defaults to 100
140
121
  ```
141
122
 
123
+ #### Live Conversions
124
+
125
+ Show the conversion name in the live stream.
126
+
127
+ ```ruby
128
+ Intel.conversion_name = proc{|model| model.name }
129
+ ```
130
+
142
131
  ## TODO
143
132
 
144
133
  - customize views
@@ -31,15 +31,8 @@ module Intel
31
31
  def stream
32
32
  end
33
33
 
34
- # suspiciously similar to bootstrap 3
35
- COLORS = %w[5bc0de d9534f 5cb85c f0ad4e]
36
-
37
34
  def recent
38
35
  @searches = Intel::Search.order("created_at desc").limit(10)
39
- @color = {}
40
- @search_types.each_with_index do |search_type, i|
41
- @color[search_type] = COLORS[i % COLORS.size]
42
- end
43
36
  render layout: false
44
37
  end
45
38
 
@@ -54,7 +47,7 @@ module Intel
54
47
  end
55
48
 
56
49
  def set_time_zone
57
- @time_zone = Intel.time_zone
50
+ @time_zone = Intel.time_zone || Time.zone
58
51
  end
59
52
 
60
53
  def set_time_range
@@ -1,6 +1,6 @@
1
1
  <h1>
2
2
  <%= @search_type %> Searches
3
- <small style="color: #999; font-weight: normal;">Top <%= @limit %></small>
3
+ <small>Top <%= @limit %></small>
4
4
  </h1>
5
5
 
6
6
  <table>
@@ -6,7 +6,7 @@
6
6
  <thead>
7
7
  <tr>
8
8
  <th>Top Searches</th>
9
- <th class="num"><%= link_to "View all", intel.searches_path(search_type: params[:search_type]) %></th>
9
+ <th class="num"><%= link_to "View all", intel.searches_path(search_type: @search_type) %></th>
10
10
  </tr>
11
11
  </thead>
12
12
  <tbody>
@@ -24,7 +24,7 @@
24
24
  <thead>
25
25
  <tr>
26
26
  <th>Low Conversions</th>
27
- <th class="num"><%= link_to "View all", intel.searches_path(search_type: params[:search_type], sort: "conversion_rate") %></th>
27
+ <th class="num"><%= link_to "View all", intel.searches_path(search_type: @search_type, sort: "conversion_rate") %></th>
28
28
  </tr>
29
29
  </thead>
30
30
  <tbody>
@@ -1,20 +1,18 @@
1
1
  <% @searches.each do |search| %>
2
2
  <tr>
3
3
  <td style="width: 15%;">
4
- <%= link_to search.search_type, intel.overview_searches_path(search_type: search.search_type), class: "type-link", style: "background-color: ##{@color[search.search_type]};" %>
4
+ <%= link_to search.search_type, intel.overview_searches_path(search_type: search.search_type), class: "type-link type-link-#{@search_types.index(search.search_type)}" %>
5
5
  </td>
6
6
  <td><%= search.query %></td>
7
- <td style="width: 35%;">
7
+ <td style="width: 35%; color: #5cb85c;">
8
8
  <% if search.converted_at %>
9
- <span style="color: #5cb85c;">
10
- <span style="font-weight: bold;">✓</span>
11
- <%= search.convertable ? (search.convertable.respond_to?(:intel_name) ? search.convertable.intel_name : "#{search.convertable_type} #{search.convertable_id}") : "Converted" %>
12
- </span>
9
+ <strong>✓</strong>
10
+ <%= search.convertable ? (Intel.conversion_name ? Intel.conversion_name.call(search.convertable) : "#{search.convertable_type} #{search.convertable_id}") : "Converted" %>
13
11
  <% end %>
14
12
  </td>
15
13
  <td style="width: 20%;" class="num">
16
14
  <%= time_ago_in_words search.created_at %> ago
17
- <div style="color: #999;"><%= pluralize search.results_count, "result" %></div>
15
+ <div class="text-muted"><%= pluralize search.results_count, "result" %></div>
18
16
  </td>
19
17
  </tr>
20
18
  <% end %>
@@ -40,6 +40,11 @@
40
40
  font-size: 20px;
41
41
  }
42
42
 
43
+ h1 small {
44
+ color: #999;
45
+ font-weight: normal;
46
+ }
47
+
43
48
  h2 {
44
49
  font-size: 16px;
45
50
  }
@@ -57,6 +62,10 @@
57
62
  border-top: solid 1px #ddd;
58
63
  }
59
64
 
65
+ .text-muted {
66
+ color: #999;
67
+ }
68
+
60
69
  #brand {
61
70
  font-size: 18px;
62
71
  line-height: 20px;
@@ -69,15 +78,29 @@
69
78
  }
70
79
 
71
80
  a.type-link {
72
- color: #fff;
73
- padding: 8px;
74
- border-radius: 4px;
81
+ background-color: #f0ad4e;
82
+ color: #fff;
83
+ padding: 8px;
84
+ border-radius: 4px;
75
85
  }
76
86
 
77
87
  a.type-link:hover {
78
88
  text-decoration: none;
79
89
  }
80
90
 
91
+ /* suspiciously similar to bootstrap 3 */
92
+ a.type-link-0 {
93
+ background-color: #5bc0de;
94
+ }
95
+
96
+ a.type-link-1 {
97
+ background-color: #d9534f;
98
+ }
99
+
100
+ a.type-link-2 {
101
+ background-color: #5cb85c;
102
+ }
103
+
81
104
  #header {
82
105
  border-bottom: solid 1px #ddd;
83
106
  padding-bottom: 20px;
@@ -262,28 +285,26 @@
262
285
  </head>
263
286
  <body>
264
287
  <div class="container">
265
- <% if !@skip_header %>
266
- <div id="header">
267
- <div class="grid">
268
- <div class="col-1-2">
269
- <ul class="nav">
270
- <li id="brand">Intel</li>
271
- <li><%= link_to "Live Stream", intel.root_path, class: ("active" if !@search_type) %></li>
272
- <% @search_types.each do |search_type| %>
273
- <li><%= link_to search_type, intel.overview_searches_path(search_type: search_type), class: ("active" if @search_type == search_type) %></li>
274
- <% end %>
275
- </ul>
276
- </div>
277
-
278
- <div class="col-1-2" style="text-align: right;">
279
- <% if %w[overview index].include?(params[:action]) and @time_range %>
280
- <%= @time_range.first.strftime("%b %-e, %Y") %> to <%= @time_range.last.strftime("%b %-e, %Y") %>
281
- <span style="color: #999;"><%= @time_zone.name.sub(" (US & Canada)", "") %></span>
288
+ <div id="header">
289
+ <div class="grid">
290
+ <div class="col-1-2">
291
+ <ul class="nav">
292
+ <li id="brand">Intel</li>
293
+ <li><%= link_to "Live Stream", intel.root_path, class: ("active" if !@search_type) %></li>
294
+ <% @search_types.each do |search_type| %>
295
+ <li><%= link_to search_type, intel.overview_searches_path(search_type: search_type), class: ("active" if @search_type == search_type) %></li>
282
296
  <% end %>
283
- </div>
297
+ </ul>
298
+ </div>
299
+
300
+ <div class="col-1-2" style="text-align: right;">
301
+ <% if @time_range %>
302
+ <%= @time_range.first.strftime("%b %-e, %Y") %> to <%= @time_range.last.strftime("%b %-e, %Y") %>
303
+ <span class="text-muted"><%= @time_zone.name.sub(" (US & Canada)", "") %></span>
304
+ <% end %>
284
305
  </div>
285
306
  </div>
286
- <% end %>
307
+ </div>
287
308
 
288
309
  <%= yield %>
289
310
  </div>
data/lib/intel/search.rb CHANGED
@@ -4,6 +4,14 @@ module Intel
4
4
 
5
5
  before_save :set_normalized_query
6
6
 
7
+ def converted(convertable = nil)
8
+ if !converted?
9
+ self.converted_at = Time.now
10
+ self.convertable = convertable
11
+ save(validate: false)
12
+ end
13
+ end
14
+
7
15
  def converted?
8
16
  converted_at.present?
9
17
  end
data/lib/intel/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Intel
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/intel.rb CHANGED
@@ -16,6 +16,9 @@ module Intel
16
16
  # top searches
17
17
  mattr_accessor :top_searches
18
18
  self.top_searches = 100
19
+
20
+ # conversion name
21
+ mattr_accessor :conversion_name
19
22
  end
20
23
 
21
24
  if defined?(Searchkick)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane