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

Add pluginType and refactor eventType #1233

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -25,7 +25,7 @@ describe('analyticsHook', () => {
};
onStartHandler(req);
expect(createAnalyticsEvent).toHaveBeenCalled();
expect(createAnalyticsEvent).toHaveBeenCalledWith('mocked_sessionID','Adyen-GetPaymentMethods', 'START', 'EXPECTED', 'info');
expect(createAnalyticsEvent).toHaveBeenCalledWith('mocked_sessionID','Adyen-GetPaymentMethods', 'expectedStart', 'EXPECTED', 'info');
})
it('should not create Start event when adyen analytics is disabled in BM', () => {
const req = {
Expand All @@ -51,7 +51,7 @@ describe('analyticsHook', () => {
};
onCompleteHandler(req, res);
expect(createAnalyticsEvent).toHaveBeenCalled();
expect(createAnalyticsEvent).toHaveBeenCalledWith('mocked_sessionID','Adyen-GetPaymentMethods', 'END', 'EXPECTED', 'info');
expect(createAnalyticsEvent).toHaveBeenCalledWith('mocked_sessionID','Adyen-GetPaymentMethods', 'expectedEnd', 'EXPECTED', 'info');
})
it('should create End event with unexpected status when onCompleteHandler is called for error in route', () => {
const req = {
Expand All @@ -62,7 +62,7 @@ describe('analyticsHook', () => {
};
onCompleteHandler(req, res);
expect(createAnalyticsEvent).toHaveBeenCalled();
expect(createAnalyticsEvent).toHaveBeenCalledWith('mocked_sessionID','Adyen-GetPaymentMethods', 'END', 'UNEXPECTED', 'info');
expect(createAnalyticsEvent).toHaveBeenCalledWith('mocked_sessionID','Adyen-GetPaymentMethods', 'unexpectedEnd', 'UNEXPECTED', 'info');
})
it('should not create End event when adyen analytics is disabled in BM', () => {
const req = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function onStartHandler(req) {
analyticsEvent.createAnalyticsEvent(
session.sessionID,
path.join('-'),
analyticsConstants.eventType.START,
analyticsConstants.eventType.EXPECTED_START,
analyticsConstants.eventStatus.EXPECTED,
analyticsConstants.eventCode.INFO,
);
Expand All @@ -75,15 +75,15 @@ function onCompleteHandler(req, res) {
analyticsEvent.createAnalyticsEvent(
session.sessionID,
path.join('-'),
analyticsConstants.eventType.END,
analyticsConstants.eventType.UNEXPECTED_END,
analyticsConstants.eventStatus.UNEXPECTED,
analyticsConstants.eventCode.INFO,
);
} else {
analyticsEvent.createAnalyticsEvent(
session.sessionID,
path.join('-'),
analyticsConstants.eventType.END,
analyticsConstants.eventType.EXPECTED_END,
analyticsConstants.eventStatus.EXPECTED,
analyticsConstants.eventCode.INFO,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const AdyenHelper = require('*/cartridge/adyen/utils/adyenHelper');
const AdyenConfigs = require('*/cartridge/adyen/utils/adyenConfigs');
const constants = require('*/cartridge/adyen/config/constants');
const AdyenLogs = require('*/cartridge/adyen/logs/adyenCustomLogs');
const analyticsConstants = require('*/cartridge/adyen/analytics/constants');

function execute(serviceType, requestObject, checkoutAttemptID = '') {
const service = AdyenHelper.getService(serviceType);
Expand Down Expand Up @@ -42,6 +43,7 @@ function createCheckoutAttemptId() {
applicationInfo: AdyenHelper.getApplicationInfo(),
channel: 'Web',
platform: 'Web',
pluginType: analyticsConstants.pluginType,
};

const response = execute(constants.SERVICE.ADYEN_ANALYTICS, requestObject);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module.exports = {
analyticsEventObjectId: 'AdyenAnalyticsEvents',
pluginType: 'salesforceCommerceCloud',
eventType: {
START: 'START',
END: 'END',
EXPECTED_START: 'expectedStart',
UNEXPECTED_START: 'unexpectedStart',
EXPECTED_END: 'expectedEnd',
UNEXPECTED_END: 'unexpectedEnd',
},
eventStatus: {
EXPECTED: 'EXPECTED',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function createRequestObjectForAllReferenceIds(groupedObjects) {
const requestObject = {
channel: 'Web',
platform: 'Web',
pluginType: constants.pluginType,
};

// Iterate over all referenceIds and group events into one requestObject
Expand All @@ -17,20 +18,20 @@ function createRequestObjectForAllReferenceIds(groupedObjects) {
events.forEach((event) => {
const eventObject = {
timestamp: new Date(event.creationDate).getTime().toString(),
type: 'focus', // this has to be changed once API accepts our event types
type: event.eventType,
target: event.eventStatus,
id: event.eventId,
component: event.eventSource,
};

const eventCode = event.eventCode.toLowerCase();
const eventTypes = [
const eventCodeList = [
constants.eventCode.INFO,
constants.eventCode.ERROR,
constants.eventCode.LOG,
];

if (eventTypes.includes(eventCode)) {
if (eventCodeList.includes(eventCode)) {
if (!requestObject[eventCode]) {
requestObject[eventCode] = [];
}
Expand Down
Loading