Skip to content

Commit

Permalink
chore: refactor, add pixel transformation definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
yashasvibajpai committed Aug 27, 2024
1 parent fbcc53a commit 754d8a3
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions src/v1/sources/shopify/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const trackPayloadBuilder = (event, shopifyTopic) => {

const processEvent = async (inputEvent, metricMetadata) => {
let message;
const event = lodash.cloneDeep(inputEvent.event);
const event = lodash.cloneDeep(inputEvent);
let redisData;
const shopifyTopic = getShopifyTopic(event);
delete event.query_parameters;
Expand Down Expand Up @@ -276,20 +276,41 @@ const processIdentifierEvent = async (event, metricMetadata) => {
return NO_OPERATION_SUCCESS;

Check warning on line 276 in src/v1/sources/shopify/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/shopify/transform.js#L276

Added line #L276 was not covered by tests
};

const processEventV2 = async (event) => event;
const process = async (event) => {
const { source } = event;
function processPixelEvent(inputEvent) {
const { name, data, context, clientId } = inputEvent;
const payload = {

Check warning on line 281 in src/v1/sources/shopify/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/shopify/transform.js#L279-L281

Added lines #L279 - L281 were not covered by tests
type: 'track',
event: name,
properties: data,
anonymousId: clientId,
context,
};
return payload;

Check warning on line 288 in src/v1/sources/shopify/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/shopify/transform.js#L288

Added line #L288 was not covered by tests
}

const processEventV2 = async (event, metricMetadata) => {
const { pixelEventLabel } = event;

Check warning on line 292 in src/v1/sources/shopify/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/shopify/transform.js#L292

Added line #L292 was not covered by tests
if (pixelEventLabel) {
// this is a web pixel event fired from the browser
const pixelEvent = processPixelEvent(event);
return removeUndefinedAndNullValues(pixelEvent);

Check warning on line 296 in src/v1/sources/shopify/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/shopify/transform.js#L295-L296

Added lines #L295 - L296 were not covered by tests
}
return processEvent(event, metricMetadata);

Check warning on line 298 in src/v1/sources/shopify/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/shopify/transform.js#L298

Added line #L298 was not covered by tests
};
const process = async (inputEvent) => {
const { event, source } = inputEvent;
const metricMetadata = {
// eslint-disable-next-line unicorn/consistent-destructuring
writeKey: event.query_parameters?.writeKey?.[0],
source: 'SHOPIFY',
};
if (source) {
const { version } = source.Config;

Check warning on line 308 in src/v1/sources/shopify/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/shopify/transform.js#L308

Added line #L308 was not covered by tests
if (version === 'v2') {
const responseV2 = await processEventV2(event);
const responseV2 = await processEventV2(event, metricMetadata);
return responseV2;

Check warning on line 311 in src/v1/sources/shopify/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/shopify/transform.js#L310-L311

Added lines #L310 - L311 were not covered by tests
}
}
const metricMetadata = {
writeKey: event.query_parameters?.writeKey?.[0],
source: 'SHOPIFY',
};
if (isIdentifierEvent(event)) {
return processIdentifierEvent(event, metricMetadata);

Check warning on line 315 in src/v1/sources/shopify/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/shopify/transform.js#L315

Added line #L315 was not covered by tests
}
Expand Down

0 comments on commit 754d8a3

Please sign in to comment.