intercom-rails 0.3.1 → 0.3.2

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: bb3a67b75d0175cc439a84fd9a0a43f04af84ce7
4
- data.tar.gz: 23bce387796262445d5e9f746c5bb91651996ad0
3
+ metadata.gz: 08651bb54d9b9c588783f70646f08de114e2d7fc
4
+ data.tar.gz: 9bb02e0bdcb79a59d7e3a5ba6cde2ad7f5982caa
5
5
  SHA512:
6
- metadata.gz: cc95465f7ad019d4825b4b07f780f6b37644da6497f03561798a3740b18a00882a40d9037144b4e3d9c769ac83c0f110e10ae0b5970e7153af8b4e1a7758cb50
7
- data.tar.gz: ced904423a285003bc91f79fbc8d28a7cda81ff33d1ae4aa5e4afe67e5cb044767a3cdba92573727810c3fabf71340a7ceb95cba1fc4b07188ff1fac2979f724
6
+ metadata.gz: 72371243fbae2337000a1f3eb7dbf0beb32bb98ff3cf08b1430f04e7f7be2e755685910518742ae884a605359927247e6b2adcdba6d5da51d3bc08e5a231368c
7
+ data.tar.gz: a5b853032d971f3c50ef477982f065f3c55b3739ebc02a64f91e91f432b05c466e9ab08c37a76aabf305d2f4b6cbab6744a9613772adb51cbd3104db6d5af805
@@ -173,6 +173,38 @@ end
173
173
  Attributes must be accessible in order to sync with intercom.
174
174
  Additionally, attributes ending in "_at" will be parsed as times.
175
175
 
176
+ ### Custom attributes for non-signed up users
177
+
178
+ In situations where you want to pass in specific request based custom data for non-signed up users or leads,
179
+ you can do that by setting custom attributes in ```config/initializers/intercom.rb```.
180
+
181
+ Any of these attributes can be used to pass in custom data.
182
+
183
+ Example:
184
+
185
+ **in ```config/initializers/intercom.rb```**
186
+
187
+ ```ruby
188
+ config.user.lead_attributes = %w(ref_data utm_source)
189
+ ```
190
+
191
+ **in ```app/controllers/posts_controller.rb```**
192
+
193
+ ```ruby
194
+ class PostsController < ApplicationController
195
+
196
+ before_action :set_custom_attributes, only: [:index]
197
+
198
+ # Your logic here
199
+
200
+ protected
201
+ def set_custom_attributes
202
+ intercom_custom_data.user[:ref_data] = params[:api_ref_data]
203
+ intercom_custom_data.user[:utm_source] = params[:api_utm_source]
204
+ end
205
+ end
206
+ ```
207
+
176
208
  ### Companies
177
209
 
178
210
  By default, Intercom treats all Users as unrelated individuals. If for example you know users are part of a company, you can group them as such.
@@ -106,8 +106,12 @@ module IntercomRails
106
106
  config_accessor :current, &IS_PROC_OR_ARRAY_OF_PROC_VALIDATOR
107
107
  config_accessor :exclude_if, &IS_PROC_VALIDATOR
108
108
  config_accessor :model, &IS_PROC_VALIDATOR
109
- config_accessor :company_association, &IS_PROC_VALIDATOR
109
+ config_accessor :lead_attributes, &ARRAY_VALIDATOR
110
110
  config_accessor :custom_data, &CUSTOM_DATA_VALIDATOR
111
+
112
+ def self.company_association=(*)
113
+ warn "Setting a company association is no longer supported; remove the `config.user.company_association = ...` line from config/initializers/intercom.rb"
114
+ end
111
115
  end
112
116
 
113
117
  config_group :company do
@@ -11,14 +11,6 @@ module IntercomRails
11
11
  config_delegator :plan
12
12
  config_delegator :monthly_spend
13
13
 
14
- def self.companies_for_user(user)
15
- return unless config(:user).company_association.present?
16
- companies = config(:user).company_association.call(user.user)
17
- return unless companies.kind_of?(Array)
18
-
19
- companies.map { |company| new(company) }.select { |company_proxy| company_proxy.valid? }
20
- end
21
-
22
14
  def self.current_in_context(search_object)
23
15
  begin
24
16
  if config.current.present?
@@ -19,6 +19,10 @@ module IntercomRails
19
19
  @show_everywhere = options[:show_everywhere]
20
20
  @session_duration = session_duration_from_config
21
21
  self.user_details = options[:find_current_user_details] ? find_current_user_details : options[:user_details]
22
+
23
+ # Request specific custom data for non-signed up users base on lead_attributes
24
+ self.user_details = self.user_details.merge(find_lead_attributes)
25
+
22
26
  self.company_details = if options[:find_current_company_details]
23
27
  find_current_company_details
24
28
  elsif options[:user_details]
@@ -78,6 +82,16 @@ module IntercomRails
78
82
  csp_hash
79
83
  end
80
84
 
85
+ def find_lead_attributes
86
+ lead_attributes = IntercomRails.config.user.lead_attributes
87
+ return {} unless controller.present? && lead_attributes && lead_attributes.size > 0
88
+
89
+ # Get custom data. This also allows to retrieve custom data
90
+ # set via helper function intercom_custom_data
91
+ custom_data = controller.intercom_custom_data.user.with_indifferent_access
92
+ custom_data.select {|k, v| lead_attributes.map(&:to_s).include?(k)}
93
+ end
94
+
81
95
  private
82
96
  def intercom_javascript
83
97
  intercom_settings_json = ActiveSupport::JSON.encode(intercom_settings).gsub('<', '\u003C')
@@ -1,3 +1,3 @@
1
1
  module IntercomRails
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -50,6 +50,13 @@ IntercomRails.config do |config|
50
50
  #
51
51
  # config.user.model = Proc.new { User }
52
52
 
53
+ # == Lead/custom attributes for non-signed up users
54
+ # Pass additional attributes to for potential leads or
55
+ # non-signed up users as an an array.
56
+ # Any attribute contained in config.user.lead_attributes can be used
57
+ # as custom attribute in the application.
58
+ # config.user.lead_attributes = %w(ref_data utm_source)
59
+
53
60
  # == Exclude users
54
61
  # A Proc that given a user returns true if the user should be excluded
55
62
  # from imports and Javascript inclusion, false otherwise.
@@ -66,14 +73,6 @@ IntercomRails.config do |config|
66
73
  # :favorite_color => :favorite_color
67
74
  # }
68
75
 
69
- # == User -> Company association
70
- # A Proc that given a user returns an array of companies
71
- # that the user belongs to.
72
- # This is only used for importing users using rake command but it will not inject a list of companies in the intercom widget
73
- #
74
- # config.user.company_association = Proc.new { |user| user.companies.to_a }
75
- # config.user.company_association = Proc.new { |user| [user.company] }
76
-
77
76
  # == Current company method/variable
78
77
  # The method/variable that contains the current company for the current user,
79
78
  # in your controllers. 'Companies' are generic groupings of users, so this
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intercom-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben McRedmond
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-06-24 00:00:00.000000000 Z
13
+ date: 2016-06-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -202,9 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  version: '0'
203
203
  requirements: []
204
204
  rubyforge_project: intercom-rails
205
- rubygems_version: 2.4.8
205
+ rubygems_version: 2.5.1
206
206
  signing_key:
207
207
  specification_version: 4
208
208
  summary: Rails helper for emitting javascript script tags for Intercom
209
209
  test_files: []
210
- has_rdoc: