Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions integrations/appboy/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
1.11.0 / 2019-08-08
==================

* Excludes nested non-null objects from customer user attributes in identify method
* Excludes non-null objects from custom event properties in track method
* Conditionally set user-related traits (ID, name, address, etc.)
* Use serviceWorkerLocation from settings if it is available.

1.9.0 / 2019-06-19
==================

Expand Down
65 changes: 54 additions & 11 deletions integrations/appboy/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ Appboy.prototype.initializeV2 = function(customEndpoint) {
openNewsFeedCardsInNewTab: options.openNewsFeedCardsInNewTab,
requireExplicitInAppMessageDismissal:
options.requireExplicitInAppMessageDismissal,
serviceWorkerLocation: options.serviceWorkerLocation,
sessionTimeoutInSeconds: Number(options.sessionTimeoutInSeconds) || 30
};

Expand Down Expand Up @@ -255,13 +256,31 @@ Appboy.prototype.identify = function(identify) {
var phone = identify.phone();
var traits = clone(identify.traits());

window.appboy.changeUser(userId);
window.appboy.getUser().setAvatarImageUrl(avatar);
window.appboy.getUser().setEmail(email);
window.appboy.getUser().setFirstName(firstName);
window.appboy.getUser().setGender(getGender(gender));
window.appboy.getUser().setLastName(lastName);
window.appboy.getUser().setPhoneNumber(phone);
if (userId) {
window.appboy.changeUser(userId);
}
if (avatar) {
window.appboy.getUser().setAvatarImageUrl(avatar);
}
if (email) {
window.appboy.getUser().setEmail(email);
}
if (firstName) {
window.appboy.getUser().setFirstName(firstName);
}
if (gender) {
window.appboy.getUser().setGender(getGender(gender));
}
if (lastName) {
window.appboy.getUser().setLastName(lastName);
}
if (phone) {
window.appboy.getUser().setPhoneNumber(phone);
}
if (address) {
window.appboy.getUser().setCountry(address.country);
window.appboy.getUser().setHomeCity(address.city);
}
if (address) {
window.appboy.getUser().setCountry(address.country);
window.appboy.getUser().setHomeCity(address.city);
Expand Down Expand Up @@ -307,6 +326,14 @@ Appboy.prototype.identify = function(identify) {
delete traits[key];
}, reserved);

// Remove nested hash objects as Braze only supports nested array objects in identify calls
// https://segment.com/docs/destinations/braze/#identify
each(function(value, key) {
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
delete traits[key];
}
}, traits);

each(function(value, key) {
window.appboy.getUser().setCustomUserAttribute(key, value);
}, traits);
Expand All @@ -325,7 +352,9 @@ Appboy.prototype.group = function(group) {
var userId = group.userId();
var groupIdKey = 'ab_segment_group_' + group.groupId();

window.appboy.changeUser(userId);
if (userId) {
window.appboy.changeUser(userId);
}
window.appboy.getUser().setCustomUserAttribute(groupIdKey, true);
};

Expand Down Expand Up @@ -356,7 +385,17 @@ Appboy.prototype.track = function(track) {
delete properties[key];
}, reserved);

window.appboy.changeUser(userId);
// Remove nested objects as Braze doesn't support objects in tracking calls
// https://segment.com/docs/destinations/braze/#track
each(function(value, key) {
if (value != null && typeof value === 'object') {
delete properties[key];
}
}, properties);

if (userId) {
window.appboy.changeUser(userId);
}
window.appboy.logCustomEvent(eventName, properties);
};

Expand All @@ -379,7 +418,9 @@ Appboy.prototype.page = function(page) {
var eventName = pageEvent.event();
var properties = page.properties();

window.appboy.changeUser(userId);
if (userId) {
window.appboy.changeUser(userId);
}
window.appboy.logCustomEvent(eventName, properties);
};

Expand All @@ -400,7 +441,9 @@ Appboy.prototype.orderCompleted = function(track) {
var currencyCode = track.currency();
var purchaseProperties = track.properties();

window.appboy.changeUser(userId);
if (userId) {
window.appboy.changeUser(userId);
}

// remove reduntant properties
del(purchaseProperties, 'products');
Expand Down
2 changes: 1 addition & 1 deletion integrations/appboy/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@segment/analytics.js-integration-appboy",
"description": "The Appboy analytics.js integration.",
"version": "1.10.0",
"version": "1.11.0",
"keywords": [
"analytics.js",
"analytics.js-integration",
Expand Down
14 changes: 10 additions & 4 deletions integrations/appboy/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ describe('Appboy', function() {
openInAppMessagesInNewTab: false,
openNewsFeedCardsInNewTab: false,
sessionTimeoutInSeconds: 30,
serviceWorkerLocation: undefined,
requireExplicitInAppMessageDismissal: false,
enableHtmlInAppMessages: false
};
Expand Down Expand Up @@ -335,12 +336,13 @@ describe('Appboy', function() {
);
});

it('should handle custom traits of all types', function() {
it('should handle custom traits of valid types and exclude nested objects', function() {
analytics.identify('userId', {
song: "Who's That Chick?",
artists: ['David Guetta', 'Rihanna'],
number: 16,
date: 'Tue Apr 25 2017 14:22:48 GMT-0700 (PDT)'
date: 'Tue Apr 25 2017 14:22:48 GMT-0700 (PDT)',
details: { nested: 'object' }
});
analytics.called(window.appboy.changeUser, 'userId');
analytics.called(
Expand Down Expand Up @@ -411,15 +413,19 @@ describe('Appboy', function() {
analytics.track('event with properties', {
nickname: 'noonz',
spiritAnimal: 'rihanna',
best_friend: 'han'
best_friend: 'han',
number_of_friends: 12,
idols: ['beyonce', 'madonna'],
favoriteThings: { whiskers: 'on-kittins' }
});
analytics.called(
window.appboy.logCustomEvent,
'event with properties',
{
nickname: 'noonz',
spiritAnimal: 'rihanna',
best_friend: 'han'
best_friend: 'han',
number_of_friends: 12
}
);
});
Expand Down