@@ -9,6 +9,7 @@ var defaults = require('@ndhoule/defaults');
9
9
var del = require ( 'obj-case' ) . del ;
10
10
var integration = require ( '@segment/analytics.js-integration' ) ;
11
11
var is = require ( 'is-type' ) ;
12
+ var extend = require ( '@ndhoule/extend' ) ;
12
13
13
14
/**
14
15
* Expose `Intercom` integration.
@@ -57,8 +58,9 @@ Intercom.prototype.loaded = function() {
57
58
* @param {Page } page
58
59
*/
59
60
60
- Intercom . prototype . page = function ( ) {
61
- this . bootOrUpdate ( ) ;
61
+ Intercom . prototype . page = function ( page ) {
62
+ var integrationSettings = page . options ( this . name ) ;
63
+ this . bootOrUpdate ( { } , integrationSettings ) ;
62
64
} ;
63
65
64
66
/**
@@ -72,14 +74,14 @@ Intercom.prototype.page = function() {
72
74
73
75
Intercom . prototype . identify = function ( identify ) {
74
76
var traits = identify . traits ( { userId : 'user_id' } ) ;
75
- var opts = identify . options ( this . name ) ;
77
+ var integrationSettings = identify . options ( this . name ) ;
76
78
var companyCreated = identify . companyCreated ( ) ;
77
79
var created = identify . created ( ) ;
78
80
var name = identify . name ( ) ;
79
81
var id = identify . userId ( ) ;
80
82
var group = this . analytics . group ( ) ;
81
83
82
- if ( ! id && ! traits . email ) {
84
+ if ( ! id && ! identify . email ( ) ) {
83
85
return ;
84
86
}
85
87
@@ -113,10 +115,10 @@ Intercom.prototype.identify = function(identify) {
113
115
traits = convertDates ( traits , formatDate ) ;
114
116
115
117
// handle options
116
- if ( opts . userHash ) traits . user_hash = opts . userHash ;
117
- if ( opts . user_hash ) traits . user_hash = opts . user_hash ;
118
+ if ( integrationSettings . userHash ) traits . user_hash = integrationSettings . userHash ;
119
+ if ( integrationSettings . user_hash ) traits . user_hash = integrationSettings . user_hash ;
118
120
119
- this . bootOrUpdate ( traits ) ;
121
+ this . bootOrUpdate ( traits , integrationSettings ) ;
120
122
} ;
121
123
122
124
/**
@@ -135,7 +137,10 @@ Intercom.prototype.group = function(group) {
135
137
props = convertDates ( props , formatDate ) ;
136
138
var id = group . groupId ( ) ;
137
139
if ( id ) props . id = id ;
138
- api ( 'update' , { company : props } ) ;
140
+ var integrationSettings = group . options ( this . name ) ;
141
+ var traits = extend ( { company : props } , hideDefaultLauncher ( integrationSettings ) ) ;
142
+
143
+ api ( 'update' , traits ) ;
139
144
} ;
140
145
141
146
/**
@@ -156,7 +161,7 @@ Intercom.prototype.track = function(track) {
156
161
* @param {Object } options
157
162
*/
158
163
159
- Intercom . prototype . bootOrUpdate = function ( options ) {
164
+ Intercom . prototype . bootOrUpdate = function ( options , integrationSettings ) {
160
165
options = options || { } ;
161
166
var method = this . booted === true ? 'update' : 'boot' ;
162
167
var activator = this . options . activator ;
@@ -168,6 +173,8 @@ Intercom.prototype.bootOrUpdate = function(options) {
168
173
if ( activator !== '#IntercomDefaultWidget' ) {
169
174
options . widget = { activator : activator } ;
170
175
}
176
+ // Check for selective showing of messenger option
177
+ options = extend ( options , hideDefaultLauncher ( integrationSettings ) ) ;
171
178
172
179
api ( method , options ) ;
173
180
this . booted = true ;
@@ -194,3 +201,20 @@ function formatDate(date) {
194
201
function api ( ) {
195
202
window . Intercom . apply ( window . Intercom , arguments ) ;
196
203
}
204
+
205
+ /**
206
+ * Selectively hide messenger
207
+ * https://docs.intercom.io/configure-intercom-for-your-product-or-site/customize-the-intercom-messenger/customize-the-intercom-messenger-technical#show-the-intercom-messenger-to-selected-users-for-web-
208
+ * @param {Object } options
209
+ * @return {Object } ret
210
+ * @api private
211
+ */
212
+
213
+ function hideDefaultLauncher ( options ) {
214
+ var ret = { } ;
215
+ var setting = options . hideDefaultLauncher ;
216
+ if ( setting === undefined || typeof setting !== 'boolean' ) return ret ;
217
+ ret . hide_default_launcher = setting ;
218
+ return ret ;
219
+ }
220
+
0 commit comments