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 redis support in shopify pixel for id stitching #3957

Merged
merged 16 commits into from
Jan 20, 2025
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
1 change: 1 addition & 0 deletions src/v0/sources/shopify/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ module.exports = {
createPropertiesForEcomEvent,
extractEmailFromPayload,
getAnonymousIdAndSessionId,
getCartToken,
checkAndUpdateCartItems,
getHashLineItems,
getDataFromRedis,
Expand Down
20 changes: 20 additions & 0 deletions src/v1/sources/shopify/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,30 @@
const {
process: processPixelWebhookEvents,
} = require('./webhookTransformations/serverSideTransform');
const { RedisDB } = require('../../../util/redis/redisConnector');

const NO_OPERATION_SUCCESS = {
outputToSource: {
body: Buffer.from('OK').toString('base64'),
contentType: 'text/plain',
},
statusCode: 200,
};

const isIdentifierEvent = (event) => ['rudderIdentifier'].includes(event?.event);
yashasvibajpai marked this conversation as resolved.
Show resolved Hide resolved

const processIdentifierEvent = async (event) => {
const { cartToken, anonymousId } = event;
await RedisDB.setVal(`${cartToken}`, anonymousId);
return NO_OPERATION_SUCCESS;

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

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/shopify/transform.js#L20-L22

Added lines #L20 - L22 were not covered by tests
};

const process = async (inputEvent) => {
const { event } = inputEvent;
const { query_parameters } = event;
if (isIdentifierEvent(event)) {
return processIdentifierEvent(event);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L29 was not covered by tests
}
// check identify the event is from the web pixel based on the pixelEventLabel property.
const { pixelEventLabel: pixelClientEventLabel } = event;
if (pixelClientEventLabel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const stats = require('../../../../util/stats');
const { getShopifyTopic, extractEmailFromPayload } = require('../../../../v0/sources/shopify/util');
const { removeUndefinedAndNullValues, isDefinedAndNotNull } = require('../../../../v0/util');
const { RedisDB } = require('../../../../util/redis/redisConnector');
const Message = require('../../../../v0/sources/message');
const { EventType } = require('../../../../constants');
const {
Expand All @@ -21,6 +22,7 @@
getProductsFromLineItems,
getAnonymousIdFromAttributes,
} = require('./serverSideUtlis');
const { getCartToken } = require('../../../../v0/sources/shopify/util');

const NO_OPERATION_SUCCESS = {
outputToSource: {
Expand Down Expand Up @@ -125,6 +127,13 @@
const anonymousId = getAnonymousIdFromAttributes(event);
if (isDefinedAndNotNull(anonymousId)) {
message.setProperty('anonymousId', anonymousId);
} else {

Check warning on line 130 in src/v1/sources/shopify/webhookTransformations/serverSideTransform.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/shopify/webhookTransformations/serverSideTransform.js#L130

Added line #L130 was not covered by tests
// if anonymousId is not present in note_attributes or note_attributes is not present, query redis for anonymousId
const cartToken = getCartToken(message);
const redisData = await RedisDB.getVal(cartToken);

Check warning on line 133 in src/v1/sources/shopify/webhookTransformations/serverSideTransform.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/shopify/webhookTransformations/serverSideTransform.js#L132-L133

Added lines #L132 - L133 were not covered by tests
if (redisData?.anonymousId) {
message.setProperty('anonymousId', redisData.anonymousId);

Check warning on line 135 in src/v1/sources/shopify/webhookTransformations/serverSideTransform.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/shopify/webhookTransformations/serverSideTransform.js#L135

Added line #L135 was not covered by tests
}
}
}
message.setProperty(`integrations.${INTEGERATION}`, true);
Expand Down
Loading