Skip to content

Commit

Permalink
feat: add support for group in appcues (#1877)
Browse files Browse the repository at this point in the history
* feat: add support for group in appcues

* chore: increase test coverage
  • Loading branch information
anantjain45823 authored Oct 14, 2024
1 parent 97f028a commit d01522a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const mockAppcuesSDK = () => {
identify: jest.fn(),
track: jest.fn(),
page: jest.fn(),
group: jest.fn(),
};
};

Expand Down Expand Up @@ -161,3 +162,33 @@ describe('Appcues page tests', () => {
});
});
});
describe('Appcues group tests', () => {
let appcues;
const rudderElement = {
message: {
type: 'group',
groupId: 'testid',
traits: {
name: 'test',
},
},
};
it('Group -> Group Id and traits present', () => {
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',
});
});
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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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];
});
Expand Down Expand Up @@ -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;

0 comments on commit d01522a

Please sign in to comment.