Skip to content

Commit cf5bcb0

Browse files
authored
Merge branch 'master' into gps/amplitude
2 parents f2714cd + abd371d commit cf5bcb0

File tree

7 files changed

+123
-77
lines changed

7 files changed

+123
-77
lines changed

integrations/appboy/HISTORY.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
1.11.0 / 2019-08-08
2+
==================
3+
4+
* Excludes nested non-null objects from customer user attributes in identify method
5+
* Excludes non-null objects from custom event properties in track method
6+
* Conditionally set user-related traits (ID, name, address, etc.)
7+
* Use serviceWorkerLocation from settings if it is available.
8+
19
1.9.0 / 2019-06-19
210
==================
311

integrations/appboy/lib/index.js

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ Appboy.prototype.initializeV2 = function(customEndpoint) {
203203
openNewsFeedCardsInNewTab: options.openNewsFeedCardsInNewTab,
204204
requireExplicitInAppMessageDismissal:
205205
options.requireExplicitInAppMessageDismissal,
206+
serviceWorkerLocation: options.serviceWorkerLocation,
206207
sessionTimeoutInSeconds: Number(options.sessionTimeoutInSeconds) || 30
207208
};
208209

@@ -255,13 +256,31 @@ Appboy.prototype.identify = function(identify) {
255256
var phone = identify.phone();
256257
var traits = clone(identify.traits());
257258

258-
window.appboy.changeUser(userId);
259-
window.appboy.getUser().setAvatarImageUrl(avatar);
260-
window.appboy.getUser().setEmail(email);
261-
window.appboy.getUser().setFirstName(firstName);
262-
window.appboy.getUser().setGender(getGender(gender));
263-
window.appboy.getUser().setLastName(lastName);
264-
window.appboy.getUser().setPhoneNumber(phone);
259+
if (userId) {
260+
window.appboy.changeUser(userId);
261+
}
262+
if (avatar) {
263+
window.appboy.getUser().setAvatarImageUrl(avatar);
264+
}
265+
if (email) {
266+
window.appboy.getUser().setEmail(email);
267+
}
268+
if (firstName) {
269+
window.appboy.getUser().setFirstName(firstName);
270+
}
271+
if (gender) {
272+
window.appboy.getUser().setGender(getGender(gender));
273+
}
274+
if (lastName) {
275+
window.appboy.getUser().setLastName(lastName);
276+
}
277+
if (phone) {
278+
window.appboy.getUser().setPhoneNumber(phone);
279+
}
280+
if (address) {
281+
window.appboy.getUser().setCountry(address.country);
282+
window.appboy.getUser().setHomeCity(address.city);
283+
}
265284
if (address) {
266285
window.appboy.getUser().setCountry(address.country);
267286
window.appboy.getUser().setHomeCity(address.city);
@@ -310,10 +329,7 @@ Appboy.prototype.identify = function(identify) {
310329
// Remove nested hash objects as Braze only supports nested array objects in identify calls
311330
// https://segment.com/docs/destinations/braze/#identify
312331
each(function(value, key) {
313-
if (
314-
typeof value === 'object' &&
315-
Array.isArray(value)
316-
) {
332+
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
317333
delete traits[key];
318334
}
319335
}, traits);
@@ -336,7 +352,9 @@ Appboy.prototype.group = function(group) {
336352
var userId = group.userId();
337353
var groupIdKey = 'ab_segment_group_' + group.groupId();
338354

339-
window.appboy.changeUser(userId);
355+
if (userId) {
356+
window.appboy.changeUser(userId);
357+
}
340358
window.appboy.getUser().setCustomUserAttribute(groupIdKey, true);
341359
};
342360

@@ -367,15 +385,17 @@ Appboy.prototype.track = function(track) {
367385
delete properties[key];
368386
}, reserved);
369387

370-
// Remove nested objects as Braze doesn't support nested objects in tracking calls
388+
// Remove nested objects as Braze doesn't support objects in tracking calls
371389
// https://segment.com/docs/destinations/braze/#track
372390
each(function(value, key) {
373391
if (value != null && typeof value === 'object') {
374392
delete properties[key];
375393
}
376394
}, properties);
377395

378-
window.appboy.changeUser(userId);
396+
if (userId) {
397+
window.appboy.changeUser(userId);
398+
}
379399
window.appboy.logCustomEvent(eventName, properties);
380400
};
381401

@@ -398,7 +418,9 @@ Appboy.prototype.page = function(page) {
398418
var eventName = pageEvent.event();
399419
var properties = page.properties();
400420

401-
window.appboy.changeUser(userId);
421+
if (userId) {
422+
window.appboy.changeUser(userId);
423+
}
402424
window.appboy.logCustomEvent(eventName, properties);
403425
};
404426

@@ -419,7 +441,9 @@ Appboy.prototype.orderCompleted = function(track) {
419441
var currencyCode = track.currency();
420442
var purchaseProperties = track.properties();
421443

422-
window.appboy.changeUser(userId);
444+
if (userId) {
445+
window.appboy.changeUser(userId);
446+
}
423447

424448
// remove reduntant properties
425449
del(purchaseProperties, 'products');

integrations/appboy/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
22
"name": "@segment/analytics.js-integration-appboy",
33
"description": "The Appboy analytics.js integration.",
4-
"version": "1.10.1",
4+
"version": "1.11.0",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",
88
"segment",
9-
"Braze",
109
"Appboy"
1110
],
1211
"main": "lib/index.js",

integrations/appboy/test/index.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ describe('Appboy', function() {
229229
openInAppMessagesInNewTab: false,
230230
openNewsFeedCardsInNewTab: false,
231231
sessionTimeoutInSeconds: 30,
232+
serviceWorkerLocation: undefined,
232233
requireExplicitInAppMessageDismissal: false,
233234
enableHtmlInAppMessages: false
234235
};
@@ -335,13 +336,13 @@ describe('Appboy', function() {
335336
);
336337
});
337338

338-
it('should handle custom traits of acceptable types and excludes nested hashes', function() {
339+
it('should handle custom traits of valid types and exclude nested objects', function() {
339340
analytics.identify('userId', {
340341
song: "Who's That Chick?",
341342
artists: ['David Guetta', 'Rihanna'],
342-
details: { nested: 'object' },
343343
number: 16,
344-
date: 'Tue Apr 25 2017 14:22:48 GMT-0700 (PDT)'
344+
date: 'Tue Apr 25 2017 14:22:48 GMT-0700 (PDT)',
345+
details: { nested: 'object' }
345346
});
346347
analytics.called(window.appboy.changeUser, 'userId');
347348
analytics.called(
@@ -408,7 +409,7 @@ describe('Appboy', function() {
408409
analytics.called(window.appboy.logCustomEvent, 'event');
409410
});
410411

411-
it('should send all properties except nested arrays and hashes', function() {
412+
it('should send all properties', function() {
412413
analytics.track('event with properties', {
413414
nickname: 'noonz',
414415
spiritAnimal: 'rihanna',

integrations/nielsen-dcr/lib/index.js

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ var NielsenDCR = (module.exports = integration('Nielsen DCR')
1616
.option('appId', '')
1717
.option('instanceName', '') // the snippet lets you override the instance so make sure you don't have any global window props w same value as this setting unless you are intentionally doing that.
1818
.option('nolDevDebug', false)
19-
.option('assetIdPropertyName', 'asset_id')
19+
.option('assetIdPropertyName', '') // deprecated
20+
.option('contentAssetIdPropertyName', '')
21+
.option('adAssetIdPropertyName', '')
2022
.option('subbrandPropertyName', '')
2123
.option('clientIdPropertyName', '')
2224
.option('contentLengthPropertyName', 'total_length')
@@ -114,10 +116,13 @@ NielsenDCR.prototype.page = function(page) {
114116

115117
NielsenDCR.prototype.heartbeat = function(assetId, position, options) {
116118
var self = this;
117-
var newPosition;
119+
var newPosition = position;
118120
var opts = options || {};
121+
// if position is not sent as a string
119122
try {
120-
if (typeof position !== 'number') newPosition = parseInt(position, 10); // in case it is sent as a string
123+
if (typeof position !== 'number') {
124+
newPosition = parseInt(position, 10);
125+
} // in case it is sent as a string
121126
} catch (e) {
122127
// if we can't parse position into an Int for some reason, early return
123128
// to prevent internal errors every second
@@ -159,12 +164,18 @@ NielsenDCR.prototype.heartbeat = function(assetId, position, options) {
159164

160165
NielsenDCR.prototype.getContentMetadata = function(track, type) {
161166
var properties = 'properties.';
162-
if (type && type === 'preroll') properties = 'properties.content.';
167+
var assetIdProp = 'asset_id';
168+
if (type) {
169+
if (type === 'preroll') properties = 'properties.content.';
170+
if (type === 'video') assetIdProp = 'content_asset_id';
171+
}
163172

164173
var integrationOpts = track.options(this.name);
165174
var contentMetadata = {
166175
type: 'content',
167-
assetid: getAssetId(track, this.options.assetIdPropertyName, type),
176+
assetid: this.options.contentAssetIdPropertyName
177+
? track.proxy(properties + this.options.contentAssetIdPropertyName)
178+
: track.proxy(properties + assetIdProp),
168179
program: track.proxy(properties + 'program'),
169180
title: track.proxy(properties + 'title'),
170181
isfullepisode: track.proxy(properties + 'full_episode') ? 'y' : 'n',
@@ -214,15 +225,15 @@ NielsenDCR.prototype.getContentMetadata = function(track, type) {
214225

215226
NielsenDCR.prototype.getAdMetadata = function(track) {
216227
var type = track.proxy('properties.type');
217-
var adMetadata;
218-
var assetId = getAssetId(track, this.options.assetIdPropertyName);
219-
220228
if (typeof type === 'string') type = type.replace('-', '');
221229

222-
adMetadata = {
223-
assetid: track.proxy('ad_asset_id') || assetId,
230+
var adMetadata = {
231+
assetid: this.options.adAssetIdPropertyName
232+
? track.proxy('properties.' + this.options.adAssetIdPropertyName)
233+
: track.proxy('properties.ad_asset_id'),
224234
type: type
225235
};
236+
226237
return adMetadata;
227238
};
228239

@@ -260,7 +271,9 @@ NielsenDCR.prototype.videoContentStarted = function(track) {
260271
NielsenDCR.prototype.videoContentPlaying = function(track) {
261272
clearInterval(this.heartbeatId);
262273

263-
var assetId = getAssetId(track, this.options.assetIdPropertyName);
274+
var assetId = this.options.contentAssetIdPropertyName
275+
? track.proxy('properties.' + this.options.contentAssetIdPropertyName)
276+
: track.proxy('properties.asset_id');
264277
var position = track.proxy('properties.position');
265278
var livestream = track.proxy('properties.livestream');
266279

@@ -300,11 +313,9 @@ NielsenDCR.prototype.videoContentCompleted = function(track) {
300313
NielsenDCR.prototype.videoAdStarted = function(track) {
301314
clearInterval(this.heartbeatId);
302315

303-
var adAssetId = getAssetId(
304-
track,
305-
this.options.assetIdPropertyName,
306-
'adMetadata'
307-
);
316+
var adAssetId = this.options.adAssetIdPropertyName
317+
? track.proxy('properties.' + this.options.adAssetIdPropertyName)
318+
: track.proxy('properties.asset_id');
308319
var position = track.proxy('properties.position');
309320
var type = track.proxy('properties.type');
310321
if (typeof type === 'string') type = type.replace('-', '');
@@ -332,7 +343,9 @@ NielsenDCR.prototype.videoAdStarted = function(track) {
332343
NielsenDCR.prototype.videoAdPlaying = function(track) {
333344
clearInterval(this.heartbeatId);
334345

335-
var assetId = getAssetId(track, this.options.assetIdPropertyName);
346+
var assetId = this.options.adAssetIdPropertyName
347+
? track.proxy('properties.' + this.options.adAssetIdPropertyName)
348+
: track.proxy('properties.asset_id');
336349
var position = track.proxy('properties.position');
337350
this.heartbeat(assetId, position, { type: 'ad' });
338351
};
@@ -362,7 +375,9 @@ NielsenDCR.prototype.videoPlaybackInterrupted = function(track) {
362375

363376
// if properly implemented, the point in which the playback is resumed
364377
// you should _only_ be sending the asset_id of whatever you are pausing in: content or ad
365-
var adAssetId = track.proxy('properties.ad_asset_id');
378+
var adAssetId = this.options.adAssetIdPropertyName
379+
? track.proxy('properties.' + this.options.adAssetIdPropertyName)
380+
: track.proxy('properties.ad_asset_id');
366381
// if playback was interrupted during an ad, we only call `stop`
367382
// if interrupted during content play, we call both `end` and `stop`
368383
var position = track.proxy('properties.position');
@@ -381,8 +396,12 @@ NielsenDCR.prototype.videoPlaybackInterrupted = function(track) {
381396
NielsenDCR.prototype.videoPlaybackSeekCompleted = function(track) {
382397
clearInterval(this.heartbeatId);
383398

384-
var contentAssetId = track.proxy('properties.content_asset_id');
385-
var adAssetId = track.proxy('properties.ad_asset_id');
399+
var contentAssetId = this.options.contentAssetIdPropertyName
400+
? track.proxy('properties.' + this.options.contentAssetIdPropertyName)
401+
: track.proxy('properties.content_asset_id');
402+
var adAssetId = this.options.adAssetIdPropertyName
403+
? track.proxy('properties.' + this.options.adAssetIdPropertyName)
404+
: track.proxy('properties.ad_asset_id');
386405
var position = track.proxy('properties.position');
387406
var livestream = track.proxy('properties.livestream');
388407
// if properly implemented, the point in which the playback is resumed
@@ -394,7 +413,10 @@ NielsenDCR.prototype.videoPlaybackSeekCompleted = function(track) {
394413
if (type === 'ad') {
395414
this._client.ggPM('loadMetadata', this.getAdMetadata(track));
396415
} else if (type === 'content') {
397-
this._client.ggPM('loadMetadata', this.getContentMetadata(track));
416+
this._client.ggPM(
417+
'loadMetadata',
418+
this.getContentMetadata(track, 'video')
419+
);
398420
}
399421
}
400422

@@ -426,8 +448,12 @@ NielsenDCR.prototype.videoPlaybackPaused = function(track) {
426448
NielsenDCR.prototype.videoPlaybackResumed = function(track) {
427449
clearInterval(this.heartbeatId);
428450

429-
var contentAssetId = track.proxy('properties.content_asset_id');
430-
var adAssetId = track.proxy('properties.ad_asset_id');
451+
var contentAssetId = this.options.contentAssetIdPropertyName
452+
? track.proxy('properties.' + this.options.contentAssetIdPropertyName)
453+
: track.proxy('properties.content_asset_id');
454+
var adAssetId = this.options.adAssetIdPropertyName
455+
? track.proxy('properties.' + this.options.adAssetIdPropertyName)
456+
: track.proxy('properties.ad_asset_id');
431457
var position = track.proxy('properties.position');
432458
// if properly implemented, the point in which the playback is resumed
433459
// you should _only_ be sending the asset_id of whatever you are resuming in: content or ad
@@ -438,7 +464,10 @@ NielsenDCR.prototype.videoPlaybackResumed = function(track) {
438464
if (type === 'ad') {
439465
this._client.ggPM('loadMetadata', this.getAdMetadata(track));
440466
} else if (type === 'content') {
441-
this._client.ggPM('loadMetadata', this.getContentMetadata(track));
467+
this._client.ggPM(
468+
'loadMetadata',
469+
this.getContentMetadata(track, 'video')
470+
);
442471
}
443472
}
444473

@@ -468,27 +497,3 @@ NielsenDCR.prototype.videoPlaybackCompleted = function(track) {
468497
this.currentAssetId = null;
469498
this.heartbeatId = null;
470499
};
471-
472-
/**
473-
* Get Asset ID
474-
*
475-
* @param {Track} track
476-
* @return {string}
477-
* @api private
478-
*/
479-
480-
function getAssetId(track, customAssetId, type) {
481-
var assetIdValue;
482-
var properties = 'properties.';
483-
if (type === 'preroll') {
484-
var assetIdKey = 'asset_id';
485-
if (customAssetId !== 'asset_id') assetIdKey = customAssetId;
486-
properties = 'properties.content.';
487-
assetIdValue = track.proxy(properties + assetIdKey);
488-
} else if (customAssetId !== 'asset_id' && type !== 'adMetadata') {
489-
assetIdValue = track.proxy(properties + customAssetId);
490-
} else {
491-
assetIdValue = track.proxy(properties + 'asset_id');
492-
}
493-
return assetIdValue;
494-
}

integrations/nielsen-dcr/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@segment/analytics.js-integration-nielsen-dcr",
33
"description": "The Nielsen DCR analytics.js integration.",
4-
"version": "1.1.2",
4+
"version": "1.2.2",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

0 commit comments

Comments
 (0)