fix: Add missing referer & initiated_at.timestamp to events (#2920)

This commit is contained in:
Pranav Raj S 2021-08-31 11:46:15 +05:30 committed by GitHub
parent 588f49cc34
commit 75329e5de1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View file

@ -1,4 +1,5 @@
import { buildSearchParamsWithLocale } from '../helpers/urlParamsHelper';
import { generateEventParams } from './events';
const createConversation = params => {
const referrerURL = window.referrerURL || '';
@ -76,6 +77,7 @@ const triggerCampaign = ({ websiteToken, campaignId }) => ({
name: 'campaign.triggered',
event_info: {
campaign_id: campaignId,
...generateEventParams(),
},
},
params: {

View file

@ -1,9 +1,19 @@
import { API } from 'widget/helpers/axios';
import { buildSearchParamsWithLocale } from '../helpers/urlParamsHelper';
export const generateEventParams = () => ({
initiated_at: {
timestamp: new Date().toString(),
},
referer: window.referrerURL || '',
});
export default {
create(name) {
const search = buildSearchParamsWithLocale(window.location.search);
return API.post(`/api/v1/widget/events${search}`, { name });
return API.post(`/api/v1/widget/events${search}`, {
name,
event_info: generateEventParams(),
});
},
};

View file

@ -47,6 +47,10 @@ describe('#getConversation', () => {
describe('#triggerCampaign', () => {
it('should returns correct payload', () => {
const spy = jest.spyOn(global, 'Date').mockImplementation(() => ({
toString: () => 'mock date',
}));
const windowSpy = jest.spyOn(window, 'window', 'get');
const websiteToken = 'ADSDJ2323MSDSDFMMMASDM';
const campaignId = 12;
expect(
@ -60,11 +64,18 @@ describe('#triggerCampaign', () => {
name: 'campaign.triggered',
event_info: {
campaign_id: campaignId,
referer: '',
initiated_at: {
timestamp: 'mock date',
},
},
},
params: {
website_token: websiteToken,
},
});
windowSpy.mockRestore();
spy.mockRestore();
});
});