From 83d7c710eecbd9a7bda9a12c8802ddca2847fec8 Mon Sep 17 00:00:00 2001 From: Anant Jain Date: Wed, 9 Oct 2024 18:31:59 +0530 Subject: [PATCH 1/2] feat: add support for group in appcues --- .../integrations/Appcues/appcues.test.js | 23 +++++++++++++++++++ .../src/integrations/Appcues/browser.js | 15 +++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/analytics-js-integrations/__tests__/integrations/Appcues/appcues.test.js b/packages/analytics-js-integrations/__tests__/integrations/Appcues/appcues.test.js index 140f24876e..97ece7984f 100644 --- a/packages/analytics-js-integrations/__tests__/integrations/Appcues/appcues.test.js +++ b/packages/analytics-js-integrations/__tests__/integrations/Appcues/appcues.test.js @@ -20,6 +20,7 @@ const mockAppcuesSDK = () => { identify: jest.fn(), track: jest.fn(), page: jest.fn(), + group: jest.fn(), }; }; @@ -161,3 +162,25 @@ describe('Appcues page tests', () => { }); }); }); +describe('Appcues group tests', () => { + let appcues; + const rudderElement = { + message: { + type: 'group', + groupId: 'testid', + traits: { + name: 'test', + }, + }, + }; + it('Testing group call of Appcues', () => { + appcues = new Appcues(appcuesConfig, { loglevel: 'debug' }); + appcues.init(); + mockAppcuesSDK(); + const spy = jest.spyOn(window.Appcues, 'group'); + appcues.group(rudderElement); + expect(spy).toHaveBeenCalledWith('testid', { + name: 'test', + }); + }); +}); diff --git a/packages/analytics-js-integrations/src/integrations/Appcues/browser.js b/packages/analytics-js-integrations/src/integrations/Appcues/browser.js index 55ac6996b2..e2a08b5424 100644 --- a/packages/analytics-js-integrations/src/integrations/Appcues/browser.js +++ b/packages/analytics-js-integrations/src/integrations/Appcues/browser.js @@ -56,7 +56,7 @@ class Appcues { const { userId } = rudderElement.message; // iterate through traits and flatten any properties that are objects or arrays Object.keys(traits).forEach(key => { - if ( traits[key] && typeof traits[key] === 'object' ) { + if (traits[key] && typeof traits[key] === 'object') { Object.keys(traits[key]).forEach(subKey => { traits[`${key}.${subKey}`] = traits[key][subKey]; }); @@ -84,6 +84,19 @@ class Appcues { const { properties, name } = rudderElement.message; window.Appcues.page(name, properties); } + + // docs: https://docs.appcues.com/en_US/dev-installing-appcues/installation-overview-for-developers#identifying-groups-15 + group(rudderElement) { + const { groupId, traits } = rudderElement.message; + if (!isDefinedAndNotNullAndNotEmpty(groupId)) { + logger.error('group id is required'); + return; + } + window.Appcues.group( + groupId, // unique, required + traits, + ); + } } export default Appcues; From e2d322de7c3dc41ce477da5479a4433b3d97e507 Mon Sep 17 00:00:00 2001 From: Anant Jain Date: Thu, 10 Oct 2024 12:26:02 +0530 Subject: [PATCH 2/2] chore: increase test coverage --- .../__tests__/integrations/Appcues/appcues.test.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/analytics-js-integrations/__tests__/integrations/Appcues/appcues.test.js b/packages/analytics-js-integrations/__tests__/integrations/Appcues/appcues.test.js index 97ece7984f..33a59d4bf7 100644 --- a/packages/analytics-js-integrations/__tests__/integrations/Appcues/appcues.test.js +++ b/packages/analytics-js-integrations/__tests__/integrations/Appcues/appcues.test.js @@ -173,7 +173,7 @@ describe('Appcues group tests', () => { }, }, }; - it('Testing group call of Appcues', () => { + it('Group -> Group Id and traits present', () => { appcues = new Appcues(appcuesConfig, { loglevel: 'debug' }); appcues.init(); mockAppcuesSDK(); @@ -183,4 +183,12 @@ describe('Appcues group tests', () => { name: 'test', }); }); + it('Group -> Group Id not present', () => { + appcues = new Appcues(appcuesConfig, { loglevel: 'debug' }); + appcues.init(); + mockAppcuesSDK(); + const spy = jest.spyOn(window.Appcues, 'group'); + appcues.group({ message: {} }); + expect(spy).not.toHaveBeenCalled(); + }); });