Skip to content

Commit 41d9ea1

Browse files
committed
chore: tmp commit for test check
1 parent 780626f commit 41d9ea1

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { XPixel } from '../../../src/integrations/XPixel';
2+
3+
afterAll(() => {
4+
jest.restoreAllMocks();
5+
});
6+
const destinationInfo = {
7+
areTransformationsConnected: false,
8+
destinationId: 'sample-destination-id',
9+
};
10+
11+
const basicConfig = {
12+
pixelId: '12567839',
13+
eventToEventIdMap: [
14+
{ from: 'Sign Up', to: '123' },
15+
{ to: 'Lead', from: '1234' },
16+
{ from: 'Page View', to: '456' },
17+
{ from: 'Page View', to: '467' },
18+
{ from: 'product_added', to: '789' },
19+
],
20+
};
21+
22+
describe('XPixel init tests', () => {
23+
let xPixel;
24+
25+
test('Testing init call of XPixel', () => {
26+
xPixel = new XPixel(basicConfig, { loglevel: 'debug' }, destinationInfo);
27+
xPixel.init();
28+
expect(typeof window.twq).toBe('object');
29+
});
30+
});

packages/analytics-js-integrations/src/integrations/XPixel/browser.js

+19-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
DISPLAY_NAME,
55
} from '@rudderstack/analytics-js-common/constants/integrations/XPixel/constants';
66
import Logger from '../../utils/logger';
7+
import { getHashFromArrayWithDuplicate } from '../../utils/commonUtils';
8+
import { getTrackResponse } from './utils';
79
import { loadNativeSdk } from './nativeSdkLoader';
810

911
const logger = new Logger(DISPLAY_NAME);
@@ -14,7 +16,7 @@ class XPixel {
1416
}
1517
this.analytics = analytics;
1618
this.pixelId = config.pixelId;
17-
this.event = config.eventId;
19+
this.eventToEventIdMap = config.eventToEventIdMap;
1820
this.name = NAME;
1921
({
2022
shouldApplyDeviceModeTransformation: this.shouldApplyDeviceModeTransformation,
@@ -36,19 +38,27 @@ class XPixel {
3638
}
3739

3840
track(rudderElement) {
39-
const { event, properties } = rudderElement.message;
40-
41+
const { event } = rudderElement.message;
4142
if (!event) {
4243
logger.error('Event name is missing');
4344
return;
4445
}
46+
const properties = getTrackResponse(rudderElement.message);
47+
const standardEventsMap = getHashFromArrayWithDuplicate(this.eventsToStandard);
48+
const eventIds = standardEventsMap[event?.toLowerCase()];
49+
eventIds.forEach(eventId => {
50+
window.twq('event', eventId, properties);
51+
});
52+
}
4553

46-
if (properties) {
47-
properties.isRudderEvents = true;
48-
window.twq.track(event, properties);
49-
} else {
50-
window.twq.track(event, { isRudderEvents: true });
51-
}
54+
page(rudderElement) {
55+
const event = 'Page View';
56+
const properties = getTrackResponse(rudderElement.message);
57+
const standardEventsMap = getHashFromArrayWithDuplicate(this.eventsToStandard);
58+
const eventIds = standardEventsMap[event?.toLowerCase()];
59+
eventIds.forEach(eventId => {
60+
window.twq('event', eventId, properties);
61+
});
5262
}
5363
}
5464
export default XPixel;

0 commit comments

Comments
 (0)