fix: Add missing referer & initiated_at.timestamp to events (#2920)
This commit is contained in:
parent
588f49cc34
commit
75329e5de1
3 changed files with 24 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
import { buildSearchParamsWithLocale } from '../helpers/urlParamsHelper';
|
import { buildSearchParamsWithLocale } from '../helpers/urlParamsHelper';
|
||||||
|
import { generateEventParams } from './events';
|
||||||
|
|
||||||
const createConversation = params => {
|
const createConversation = params => {
|
||||||
const referrerURL = window.referrerURL || '';
|
const referrerURL = window.referrerURL || '';
|
||||||
|
@ -76,6 +77,7 @@ const triggerCampaign = ({ websiteToken, campaignId }) => ({
|
||||||
name: 'campaign.triggered',
|
name: 'campaign.triggered',
|
||||||
event_info: {
|
event_info: {
|
||||||
campaign_id: campaignId,
|
campaign_id: campaignId,
|
||||||
|
...generateEventParams(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
|
|
|
@ -1,9 +1,19 @@
|
||||||
import { API } from 'widget/helpers/axios';
|
import { API } from 'widget/helpers/axios';
|
||||||
import { buildSearchParamsWithLocale } from '../helpers/urlParamsHelper';
|
import { buildSearchParamsWithLocale } from '../helpers/urlParamsHelper';
|
||||||
|
|
||||||
|
export const generateEventParams = () => ({
|
||||||
|
initiated_at: {
|
||||||
|
timestamp: new Date().toString(),
|
||||||
|
},
|
||||||
|
referer: window.referrerURL || '',
|
||||||
|
});
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
create(name) {
|
create(name) {
|
||||||
const search = buildSearchParamsWithLocale(window.location.search);
|
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(),
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,6 +47,10 @@ describe('#getConversation', () => {
|
||||||
|
|
||||||
describe('#triggerCampaign', () => {
|
describe('#triggerCampaign', () => {
|
||||||
it('should returns correct payload', () => {
|
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 websiteToken = 'ADSDJ2323MSDSDFMMMASDM';
|
||||||
const campaignId = 12;
|
const campaignId = 12;
|
||||||
expect(
|
expect(
|
||||||
|
@ -60,11 +64,18 @@ describe('#triggerCampaign', () => {
|
||||||
name: 'campaign.triggered',
|
name: 'campaign.triggered',
|
||||||
event_info: {
|
event_info: {
|
||||||
campaign_id: campaignId,
|
campaign_id: campaignId,
|
||||||
|
referer: '',
|
||||||
|
initiated_at: {
|
||||||
|
timestamp: 'mock date',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
website_token: websiteToken,
|
website_token: websiteToken,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
windowSpy.mockRestore();
|
||||||
|
|
||||||
|
spy.mockRestore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue