Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for group in appcues #1877

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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;