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

chore: onboard Adobe Analytics to transformer proxy #2858

Merged
merged 8 commits into from
Dec 11, 2023
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
1 change: 1 addition & 0 deletions src/v0/destinations/adobe_analytics/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ module.exports = {
ECOM_PRODUCT_EVENTS,
commonConfig: MAPPING_CONFIG[CONFIG_CATEGORIES.COMMON.name],
formatDestinationConfig,
DESTINATION: 'ADOBE_ANALYTICS'
};
54 changes: 54 additions & 0 deletions src/v0/destinations/adobe_analytics/networkHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const { InstrumentationError } = require('@rudderstack/integrations-lib');
const { proxyRequest, prepareProxyRequest } = require('../../../adapters/network');
const {
processAxiosResponse,
} = require('../../../adapters/utils/networkUtils');
const { DESTINATION } = require('./config');


/**
* Extract data inside different tags from an xml payload
* @param {*} xml
* @param {*} tagName
* @returns data inside the tagName
*/
function extractContent(xmlPayload, tagName) {
const pattern = new RegExp(`<${tagName}>(.*?)</${tagName}>`);
const match = xmlPayload.match(pattern);
return match ? match[1] : null;
}

const responseHandler = (destinationResponse, dest) => {
const message = `[${DESTINATION}] - Request Processed Successfully`;
const { response, status } = destinationResponse;

// Extract values between different tags
const responseStatus = extractContent(response, 'status');
const reason = extractContent(response, 'reason');

// if the status tag in XML contains FAILURE, we build and throw an explicit error
if (responseStatus === 'FAILURE') {
sanpj2292 marked this conversation as resolved.
Show resolved Hide resolved
if (reason) {
throw new InstrumentationError(`[${DESTINATION} Response Handler] Request failed for destination ${dest} : ${reason}` )
sanpj2292 marked this conversation as resolved.
Show resolved Hide resolved
} else {
throw new InstrumentationError(`[${DESTINATION} Response Handler] Request failed for destination ${dest} with a general error`)
}
}

return {
anantjain45823 marked this conversation as resolved.
Show resolved Hide resolved
status,
message,
destinationResponse,
};
};

function networkHandler() {
this.responseHandler = responseHandler;
this.proxy = proxyRequest;
this.prepareProxy = prepareProxyRequest;
this.processAxiosResponse = processAxiosResponse;
}

module.exports = {
networkHandler,
};
142 changes: 142 additions & 0 deletions test/integrations/destinations/adobe_analytics/dataDelivery/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
export const data = [
{
name: 'adobe_analytics',
description: 'Test 0: Failure response from Adobe Analytics with reason',
feature: 'dataDelivery',
module: 'destination',
version: 'v0',
input: {
request: {
body: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://adobe.failure.omtrdc.net/b/ss//6',
headers: {
'Content-type': 'application/xml',
},
params: {},
body: {
JSON: {},
JSON_ARRAY: {},
XML: {
payload:
'<?xml version="1.0" encoding="utf-8"?><request><browserHeight>1794</browserHeight><browserWidth>1080</browserWidth><campaign>sales campaign</campaign><channel>web</channel><currencyCode>USD</currencyCode><ipaddress>127.0.0.1</ipaddress><language>en-US</language><userAgent>Dalvik/2.1.0 (Linux; U; Android 9; Android SDK built for x86 Build/PSR1.180720.075)</userAgent><referrer>https://www.google.com/search?q=estore+bestseller</referrer><marketingcloudorgid/><events>prodView</events><products>Games;;11;148.39</products><reportSuiteID>failureReport</reportSuiteID></request>',
},
FORM: {},
},
files: {},
},
method: 'POST',
},
},
output: {
response: {
status: 400,
statTags: {
errorCategory: 'dataValidation',
errorType: 'instrumentation',
destType: 'ADOBE_ANALYTICS',
module: 'destination',
implementation: 'native',
feature: 'dataDelivery',
destinationId: '2S3s0dXXXXXX7m0UfBwyblDrzs',
workspaceId: '1pKWrE6GXXXXXKBikka1SbRgrSN',
},
destinationResponse: '',
authErrorCategory: '',
message:
'[ADOBE_ANALYTICS Response Handler] Request failed for destination adobe_analytics : NO pagename OR pageurl',
ItsSudip marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
{
name: 'adobe_analytics',
description: 'Test 1: Failure response from Adobe Analytics without reason (Generic error)',
feature: 'dataDelivery',
module: 'destination',
version: 'v0',
input: {
request: {
body: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://adobe.failure2.omtrdc.net/b/ss//6',
headers: {
'Content-type': 'application/xml',
},
params: {},
body: {
JSON: {},
JSON_ARRAY: {},
XML: {
payload:
'<?xml version="1.0" encoding="utf-8"?><request><browserHeight>1794</browserHeight><browserWidth>1080</browserWidth><campaign>sales campaign</campaign><channel>web</channel><currencyCode>USD</currencyCode><ipaddress>127.0.0.1</ipaddress><language>en-US</language><userAgent>Dalvik/2.1.0 (Linux; U; Android 9; Android SDK built for x86 Build/PSR1.180720.075)</userAgent><referrer>https://www.google.com/search?q=estore+bestseller</referrer><marketingcloudorgid/><events>prodView</events><products>Games;;11;148.39</products><reportSuiteID>failureReportgeneric</reportSuiteID></request>',
},
FORM: {},
},
files: {},
},
method: 'POST',
},
},
output: {
response: {
status: 400,
statTags: {
errorCategory: 'dataValidation',
errorType: 'instrumentation',
destType: 'ADOBE_ANALYTICS',
module: 'destination',
implementation: 'native',
feature: 'dataDelivery',
destinationId: '2S3s0dXXXXXX7m0UfBwyblDrzs',
workspaceId: '1pKWrE6GXXXXXKBikka1SbRgrSN',
},
destinationResponse: '',
authErrorCategory: '',
message:
'[ADOBE_ANALYTICS Response Handler] Request failed for destination adobe_analytics with a general error',
},
},
},
{
name: 'adobe_analytics',
description: 'Test 2: Success response from Adobe Analytics',
feature: 'dataDelivery',
module: 'destination',
version: 'v0',
input: {
request: {
body: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://adobe.success.omtrdc.net/b/ss//6',
headers: {
'Content-type': 'application/xml',
},
params: {},
body: {
JSON: {},
JSON_ARRAY: {},
XML: {
payload:
'<?xml version="1.0" encoding="utf-8"?><request><ipaddress>127.0.1.0</ipaddress><pageUrl>www.google.co.in</pageUrl><pageName>Google</pageName><visitorID>id1110011</visitorID><events>prodView</events><products>Games;Monopoly;1;14.00,Games;UNO;2;6.90</products><reportSuiteID>successreport</reportSuiteID></request>',
},
FORM: {},
},
files: {},
},
method: 'POST',
},
},
output: {
response: {
status: 200,
destinationResponse: '<?xml version="1.0" encoding="UTF-8"?><status>SUCCESS</status>',
},
},
},
];
47 changes: 47 additions & 0 deletions test/integrations/destinations/adobe_analytics/network.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export const networkCallsData = [
{
httpReq: {
url: 'https://adobe.failure.omtrdc.net/b/ss//6',
data: '<?xml version="1.0" encoding="utf-8"?><request><browserHeight>1794</browserHeight><browserWidth>1080</browserWidth><campaign>sales campaign</campaign><channel>web</channel><currencyCode>USD</currencyCode><ipaddress>127.0.0.1</ipaddress><language>en-US</language><userAgent>Dalvik/2.1.0 (Linux; U; Android 9; Android SDK built for x86 Build/PSR1.180720.075)</userAgent><referrer>https://www.google.com/search?q=estore+bestseller</referrer><marketingcloudorgid/><events>prodView</events><products>Games;;11;148.39</products><reportSuiteID>failureReport</reportSuiteID></request>',
params: {},
headers: {
'Content-Type': 'application/xml',
},
method: 'POST',
},
httpRes: {
status: 200,
data: '<?xml version="1.0" encoding="UTF-8"?><status>FAILURE</status><reason>NO pagename OR pageurl</reason>',
},
},
{
httpReq: {
url: 'https://adobe.failure2.omtrdc.net/b/ss//6',
data: '<?xml version="1.0" encoding="utf-8"?><request><browserHeight>1794</browserHeight><browserWidth>1080</browserWidth><campaign>sales campaign</campaign><channel>web</channel><currencyCode>USD</currencyCode><ipaddress>127.0.0.1</ipaddress><language>en-US</language><userAgent>Dalvik/2.1.0 (Linux; U; Android 9; Android SDK built for x86 Build/PSR1.180720.075)</userAgent><referrer>https://www.google.com/search?q=estore+bestseller</referrer><marketingcloudorgid/><events>prodView</events><products>Games;;11;148.39</products><reportSuiteID>failureReportgeneric</reportSuiteID></request>',
params: {},
headers: {
'Content-Type': 'application/xml',
},
method: 'POST',
},
httpRes: {
status: 200,
data: '<?xml version="1.0" encoding="UTF-8"?><status>FAILURE</status>',
},
},
{
httpReq: {
url: 'https://adobe.success.omtrdc.net/b/ss//6',
data: '<?xml version="1.0" encoding="utf-8"?><request><ipaddress>127.0.1.0</ipaddress><pageUrl>www.google.co.in</pageUrl><pageName>Google</pageName><visitorID>id1110011</visitorID><events>prodView</events><products>Games;Monopoly;1;14.00,Games;UNO;2;6.90</products><reportSuiteID>successreport</reportSuiteID></request>',
params: {},
headers: {
'Content-Type': 'application/xml',
},
method: 'POST',
},
httpRes: {
status: 200,
data: '<?xml version="1.0" encoding="UTF-8"?><status>SUCCESS</status>',
},
},
];
Loading