diff --git a/integrations/appboy/HISTORY.md b/integrations/appboy/HISTORY.md index e5fcbfe0e..7550ba56b 100644 --- a/integrations/appboy/HISTORY.md +++ b/integrations/appboy/HISTORY.md @@ -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 ================== diff --git a/integrations/appboy/lib/index.js b/integrations/appboy/lib/index.js index 17e10539e..8fbadad60 100644 --- a/integrations/appboy/lib/index.js +++ b/integrations/appboy/lib/index.js @@ -203,6 +203,7 @@ Appboy.prototype.initializeV2 = function(customEndpoint) { openNewsFeedCardsInNewTab: options.openNewsFeedCardsInNewTab, requireExplicitInAppMessageDismissal: options.requireExplicitInAppMessageDismissal, + serviceWorkerLocation: options.serviceWorkerLocation, sessionTimeoutInSeconds: Number(options.sessionTimeoutInSeconds) || 30 }; @@ -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); @@ -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); @@ -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); }; @@ -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); }; @@ -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); }; @@ -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'); diff --git a/integrations/appboy/package.json b/integrations/appboy/package.json index c5d13c9b8..8eec60487 100644 --- a/integrations/appboy/package.json +++ b/integrations/appboy/package.json @@ -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", diff --git a/integrations/appboy/test/index.test.js b/integrations/appboy/test/index.test.js index eeeee9770..8650f0d4a 100644 --- a/integrations/appboy/test/index.test.js +++ b/integrations/appboy/test/index.test.js @@ -229,6 +229,7 @@ describe('Appboy', function() { openInAppMessagesInNewTab: false, openNewsFeedCardsInNewTab: false, sessionTimeoutInSeconds: 30, + serviceWorkerLocation: undefined, requireExplicitInAppMessageDismissal: false, enableHtmlInAppMessages: false }; @@ -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( @@ -411,7 +413,10 @@ 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, @@ -419,7 +424,8 @@ describe('Appboy', function() { { nickname: 'noonz', spiritAnimal: 'rihanna', - best_friend: 'han' + best_friend: 'han', + number_of_friends: 12 } ); });