diff --git a/integrations/appboy/lib/index.js b/integrations/appboy/lib/index.js index 17e10539e..c616df4e5 100644 --- a/integrations/appboy/lib/index.js +++ b/integrations/appboy/lib/index.js @@ -307,6 +307,17 @@ 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 ( + typeof value === 'object' && + Array.isArray(value) + ) { + delete traits[key]; + } + }, traits); + each(function(value, key) { window.appboy.getUser().setCustomUserAttribute(key, value); }, traits); @@ -356,6 +367,14 @@ Appboy.prototype.track = function(track) { delete properties[key]; }, reserved); + // Remove nested objects as Braze doesn't support nested 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); + window.appboy.changeUser(userId); window.appboy.logCustomEvent(eventName, properties); }; diff --git a/integrations/appboy/package.json b/integrations/appboy/package.json index c5d13c9b8..311b9132a 100644 --- a/integrations/appboy/package.json +++ b/integrations/appboy/package.json @@ -1,11 +1,12 @@ { "name": "@segment/analytics.js-integration-appboy", "description": "The Appboy analytics.js integration.", - "version": "1.10.0", + "version": "1.10.1", "keywords": [ "analytics.js", "analytics.js-integration", "segment", + "Braze", "Appboy" ], "main": "lib/index.js", diff --git a/integrations/appboy/test/index.test.js b/integrations/appboy/test/index.test.js index eeeee9770..5c4c181bf 100644 --- a/integrations/appboy/test/index.test.js +++ b/integrations/appboy/test/index.test.js @@ -335,10 +335,11 @@ describe('Appboy', function() { ); }); - it('should handle custom traits of all types', function() { + it('should handle custom traits of acceptable types and excludes nested hashes', function() { analytics.identify('userId', { song: "Who's That Chick?", artists: ['David Guetta', 'Rihanna'], + details: { nested: 'object' }, number: 16, date: 'Tue Apr 25 2017 14:22:48 GMT-0700 (PDT)' }); @@ -407,11 +408,14 @@ describe('Appboy', function() { analytics.called(window.appboy.logCustomEvent, 'event'); }); - it('should send all properties', function() { + it('should send all properties except nested arrays and hashes', 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 +423,8 @@ describe('Appboy', function() { { nickname: 'noonz', spiritAnimal: 'rihanna', - best_friend: 'han' + best_friend: 'han', + number_of_friends: 12 } ); });