Skip to content
This repository was archived by the owner on Oct 29, 2025. It is now read-only.
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
2 changes: 1 addition & 1 deletion lib/pxapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function callServer(ctx, config, callback) {
data.additional.px_cookie = JSON.stringify(ctx.decodedCookie);
}

pxUtil.prepareCustomParams(config, data.additional);
pxUtil.prepareCustomParams(config, data.additional, ctx.originalRequest);

const reqHeaders = {
Authorization: 'Bearer ' + config.AUTH_TOKEN,
Expand Down
2 changes: 1 addition & 1 deletion lib/pxclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PxClient {
}
if (ctx.pxhdClient && (activityType === 'page_requested' || activityType === 'block')) {
pxData.pxhd = ctx.pxhdClient;
pxUtil.prepareCustomParams(config, details);
pxUtil.prepareCustomParams(config, details, ctx.originalRequest);
}
pxData.details = details;

Expand Down
1 change: 1 addition & 0 deletions lib/pxcontext.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class PxContext {
this.userAgent = userAgent;
this.uri = req.originalUrl || '/';
this.fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
this.originalRequest = req.originalRequest;
this.httpVersion = req.httpVersion || '';
this.httpMethod = req.method || '';
this.sensitiveRoute = this.isSpecialRoute(config.SENSITIVE_ROUTES, this.uri);
Expand Down
5 changes: 3 additions & 2 deletions lib/pxutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ function filterConfig(config) {
* it will populate to @dict with the proper custom params
* @param {pxconfig} config - The config object of the application
* @param {object} dict - the object that should be populated with the custom params
* @param {object} originalRequest - (optional) original request based on the calling framework
* */
function prepareCustomParams(config, dict) {
function prepareCustomParams(config, dict, originalRequest) {
const customParams = {
'custom_param1': '',
'custom_param2': '',
Expand All @@ -154,7 +155,7 @@ function prepareCustomParams(config, dict) {
'custom_param10': ''
};
if (config.ENRICH_CUSTOM_PARAMETERS) {
const enrichedCustomParams = config.ENRICH_CUSTOM_PARAMETERS(customParams);
const enrichedCustomParams = config.ENRICH_CUSTOM_PARAMETERS(customParams, originalRequest);
for (const param in enrichedCustomParams) {
if (param.match(/^custom_param([1-9]|10)$/) && enrichedCustomParams[param] !== '') {
dict[param] = enrichedCustomParams[param];
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions test/pxutils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('PX Utils - pxutils.js', () => {

it('should receive custom params function and custom params object and add only 2 of them', (done) => {
const dict = {};
pxutil.prepareCustomParams(pxConfig.conf, dict);
pxutil.prepareCustomParams(pxConfig.conf, dict, {uri: '/index.html'});
dict['custom_param1'].should.be.exactly('1');
dict['custom_param2'].should.be.exactly('2');
dict['custom_param10'].should.be.exactly('10');
Expand All @@ -47,11 +47,14 @@ describe('PX Utils - pxutils.js', () => {

});

function enrichCustomParameters(params) {
function enrichCustomParameters(params, origReq) {
params['custom_param1'] = '1';
params['custom_param2'] = '2';
params['custom_param10'] = '10';
params['custom_param11'] = '11';
params['custom'] = '6';
if ('/index.html' === origReq.uri) {
params['custom_param5'] = 'index';
}
return params;
}
}