-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add redis support in shopify pixel for id stitching (#3957)
- Loading branch information
1 parent
d74c4ab
commit e417613
Showing
11 changed files
with
377 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/v1/sources/shopify/pixelEventsMappings/campaignObjectMappings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"sourceKeys": "utm_campaign", | ||
"destKeys": "name" | ||
}, | ||
{ | ||
"sourceKeys": "utm_medium", | ||
"destKeys": "medium" | ||
}, | ||
{ | ||
"sourceKeys": "utm_term", | ||
"destKeys": "term" | ||
}, | ||
{ | ||
"sourceKeys": "utm_content", | ||
"destKeys": "content" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const { RedisDB } = require('../../../util/redis/redisConnector'); | ||
|
||
const NO_OPERATION_SUCCESS = { | ||
outputToSource: { | ||
body: Buffer.from('OK').toString('base64'), | ||
contentType: 'text/plain', | ||
}, | ||
statusCode: 200, | ||
}; | ||
|
||
const isIdentifierEvent = (payload) => ['rudderIdentifier'].includes(payload?.event); | ||
|
||
const processIdentifierEvent = async (event) => { | ||
const { cartToken, anonymousId } = event; | ||
await RedisDB.setVal(`${cartToken}`, ['anonymousId', anonymousId]); | ||
return NO_OPERATION_SUCCESS; | ||
}; | ||
|
||
module.exports = { | ||
processIdentifierEvent, | ||
isIdentifierEvent, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const { isIdentifierEvent, processIdentifierEvent } = require('./utils'); | ||
const { RedisDB } = require('../../../util/redis/redisConnector'); | ||
|
||
describe('Identifier Utils Tests', () => { | ||
describe('test isIdentifierEvent', () => { | ||
it('should return true if the event is rudderIdentifier', () => { | ||
const event = { event: 'rudderIdentifier' }; | ||
expect(isIdentifierEvent(event)).toBe(true); | ||
}); | ||
|
||
it('should return false if the event is not rudderIdentifier', () => { | ||
const event = { event: 'checkout started' }; | ||
expect(isIdentifierEvent(event)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('test processIdentifierEvent', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should set the anonymousId in redis and return NO_OPERATION_SUCCESS', async () => { | ||
const setValSpy = jest.spyOn(RedisDB, 'setVal').mockResolvedValue('OK'); | ||
const event = { cartToken: 'cartTokenTest1', anonymousId: 'anonymousIdTest1' }; | ||
|
||
const response = await processIdentifierEvent(event); | ||
|
||
expect(setValSpy).toHaveBeenCalledWith('cartTokenTest1', ['anonymousId', 'anonymousIdTest1']); | ||
expect(response).toEqual({ | ||
outputToSource: { | ||
body: Buffer.from('OK').toString('base64'), | ||
contentType: 'text/plain', | ||
}, | ||
statusCode: 200, | ||
}); | ||
}); | ||
|
||
it('should handle redis errors', async () => { | ||
jest.spyOn(RedisDB, 'setVal').mockRejectedValue(new Error('Redis connection failed')); | ||
const event = { cartToken: 'cartTokenTest1', anonymousId: 'anonymousIdTest1' }; | ||
|
||
await expect(processIdentifierEvent(event)).rejects.toThrow('Redis connection failed'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.