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 1 commit
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,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',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
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 @@
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;

Check warning on line 93 in packages/analytics-js-integrations/src/integrations/Appcues/browser.js

View check run for this annotation

Codecov / codecov/patch

packages/analytics-js-integrations/src/integrations/Appcues/browser.js#L92-L93

Added lines #L92 - L93 were not covered by tests
}
window.Appcues.group(
groupId, // unique, required
traits,
);
}
}

export default Appcues;