Skip to content

Commit

Permalink
Akmal / feat: remove contract_set_up_form event from rudderstack (der…
Browse files Browse the repository at this point in the history
…iv-com#16562)

* feat: remove contract_set_up_form event from rudderstack

* fix: remove ce_contracts_set_up_form instead

* fix: remove unused imports
  • Loading branch information
akmal-deriv authored Oct 3, 2024
1 parent afaf9c3 commit f3e56bb
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 186 deletions.
1 change: 0 additions & 1 deletion packages/stores/src/mockStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,6 @@ const mock = (): TStores & { is_mock: boolean } => {
payout_choices: [],
requestProposal: jest.fn(),
resetPreviousSymbol: jest.fn(),
sendTradeParamsAnalytics: jest.fn(),
setHoveredBarrier: jest.fn(),
setIsTradeParamsExpanded: jest.fn(),
setTradeTypeTab: jest.fn(),
Expand Down
11 changes: 0 additions & 11 deletions packages/trader/src/App/Components/Form/TimePicker/time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Icon, InputField } from '@deriv/components';
import Dialog from './dialog';
import { observer, useStore } from '@deriv/stores';
import moment from 'moment';
import { useTraderStore } from 'Stores/useTraderStores';

type TTimePickerProps = {
end_times: moment.Moment[];
Expand Down Expand Up @@ -34,7 +33,6 @@ const TimePicker = observer(
validation_errors,
}: TTimePickerProps) => {
const { ui } = useStore();
const { sendTradeParamsAnalytics } = useTraderStore();
const { current_focus, setCurrentFocus } = ui;
const [is_open, setIsOpen] = React.useState(false);
const [wrapper_ref, setWrapperRef] = React.useState<HTMLDivElement | null>(null);
Expand All @@ -54,15 +52,6 @@ const TimePicker = observer(

if (value !== selected_time) {
onChange({ target: { name, value } });
sendTradeParamsAnalytics(
{
action: 'change_parameter_value',
parameter_field_type: 'time_picker',
parameter_type: 'time_picker',
parameter_value: value,
},
true
);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const TradingDatePicker = observer(({ id, is_24_hours_contract, mode, name }: TT
duration_units_list,
expiry_type,
onChange,
sendTradeParamsAnalytics,
start_date,
start_time,
symbol,
Expand Down Expand Up @@ -119,15 +118,6 @@ const TradingDatePicker = observer(({ id, is_24_hours_contract, mode, name }: TT
value,
},
});
sendTradeParamsAnalytics(
{
action: 'change_parameter_value',
parameter_field_type: 'date_picker',
parameter_type: 'date_picker',
parameter_value: `${value}`,
},
true
);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ describe('<DurationWrapper />', () => {
expiry_time: null,
onChange: jest.fn(),
onChangeMultiple: jest.fn(),
sendTradeParamsAnalytics: jest.fn(),
start_date: 0,
market_close_times: [],
market_open_times: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ describe('<DurationMobile />', () => {
onChange: jest.fn(),
onChangeMultiple: jest.fn(),
onChangeUiStore: jest.fn(),
sendTradeParamsAnalytics: jest.fn(),
server_time: moment('2023-11-21T14:30:00'),
simple_duration_unit: '',
start_date: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Tabs, RelativeDatepicker } from '@deriv/components';
import { getDurationMinMaxValues, toMoment } from '@deriv/shared';
import { getDurationMinMaxValues } from '@deriv/shared';
import { localize } from '@deriv/translations';
import { observer } from '@deriv/stores';
import { useTraderStore } from 'Stores/useTraderStores';
Expand Down Expand Up @@ -48,12 +48,7 @@ const DurationMobile = observer(
t_duration,
toggleModal,
}: TDurationMobile) => {
const {
duration_units_list,
duration_min_max,
basis: trade_basis,
sendTradeParamsAnalytics,
} = useTraderStore();
const { duration_units_list, duration_min_max, basis: trade_basis } = useTraderStore();
const duration_values = {
t_duration,
s_duration,
Expand All @@ -64,12 +59,6 @@ const DurationMobile = observer(
const [min, max] = getDurationMinMaxValues(duration_min_max, 'daily', 'd');
const handleRelativeChange = (date: number) => {
setSelectedDuration('d', date);
sendTradeParamsAnalytics({
action: 'change_parameter_value',
parameter_field_type: 'date_picker',
parameter_type: 'date_picker',
parameter_value: toMoment().add(date, 'd').format('YYYY-MM-DD'),
});
};
const selected_basis_option = () => {
if (amount_tab_idx === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const DurationWrapper = observer(({ is_minimized }: TDurationWrapper) => {
expiry_date,
expiry_epoch,
expiry_time,
sendTradeParamsAnalytics,
start_date,
onChange,
onChangeMultiple,
Expand All @@ -55,7 +54,6 @@ const DurationWrapper = observer(({ is_minimized }: TDurationWrapper) => {
onChange,
onChangeMultiple,
onChangeUiStore,
sendTradeParamsAnalytics,
simple_duration_unit,
start_date,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export type TDuration = {
onChange: TTradeStore['onChange'];
onChangeMultiple: TTradeStore['onChangeMultiple'];
onChangeUiStore: TUIStore['onChangeUiStore'];
sendTradeParamsAnalytics: TTradeStore['sendTradeParamsAnalytics'];
server_time?: moment.MomentInput;
simple_duration_unit: TUIStore['simple_duration_unit'];
start_date: TTradeStore['start_date'];
Expand All @@ -61,7 +60,6 @@ const Duration = ({
onChange,
onChangeMultiple,
onChangeUiStore,
sendTradeParamsAnalytics,
server_time,
simple_duration_unit,
start_date,
Expand Down Expand Up @@ -104,15 +102,6 @@ const Duration = ({
duration_unit: value,
duration: Number(duration_value),
});

if (name === 'advanced_duration_unit') {
sendTradeParamsAnalytics({
action: 'change_parameter_value',
durationUnit: value,
parameter_field_type: 'dropdown',
parameter_type: 'duration_type',
});
}
};

const changeDurationValue = ({ target }: { target: { name: string; value: string | number; type?: string } }) => {
Expand All @@ -122,18 +111,6 @@ const Duration = ({
// e.target.value returns string, we need to convert them to number
onChangeUiStore({ name: duration_name, value: +value });
onChange({ target: { name, value: +value } });
const displayedValue = max_value && +value > max_value ? max_value : +value;
const isTickDuration = duration_unit === 't';
sendTradeParamsAnalytics(
{
action: 'change_parameter_value',
parameter_field_type: isTickDuration ? 'tick_bar' : 'number',
parameter_type: isTickDuration ? 'tick_value' : 'duration_value',
parameter_value: `${displayedValue}`,
...(isTickDuration ? {} : { input_type: target.type ? 'manual' : 'plus_minus' }),
},
true
);
};

const onToggleDurationType = ({ target }: { target: { name: string; value: boolean } }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ const Amount = observer(({ is_minimized = false }: { is_minimized?: boolean }) =
is_vanilla,
has_equals_only,
has_open_accu_contract,
sendTradeParamsAnalytics,
stake_boundary,
onChange,
validation_errors,
Expand Down Expand Up @@ -109,29 +108,11 @@ const Amount = observer(({ is_minimized = false }: { is_minimized?: boolean }) =
const getBasisList = () => basis_list.map(item => ({ text: item.text, value: item.value }));

const changeAmount = ({ target }: { target: { name: string; value: string | number; type?: string } }) => {
const { value } = target;
onChange({ target });
sendTradeParamsAnalytics(
{
action: 'change_parameter_value',
input_type: target.type ? 'manual' : 'plus_minus',
parameter_field_type: 'number',
parameter_type: basis === 'payout' ? 'payout_value' : 'stake_value',
parameter_value: `${value}`,
},
true
);
};

const changeAllowEquals = ({ target }: { target: { name: string; value: number } }) => {
const { value } = target;
onChange({ target });
sendTradeParamsAnalytics({
action: 'change_parameter_value',
parameter_field_type: 'checkbox',
parameter_type: 'allow_equals_mode',
parameter_value: value ? 'yes' : 'no',
});
};

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import moment from 'moment';
import { waitFor } from '@testing-library/react';
import { Analytics, TEvents } from '@deriv-com/analytics';
import { mockStore } from '@deriv/stores';
import TradeStore from '../trade-store';
import { configure } from 'mobx';
Expand Down Expand Up @@ -258,60 +256,6 @@ beforeAll(async () => {
});

describe('TradeStore', () => {
describe('sendTradeParamsAnalytics', () => {
const action = 'change_parameter_value';
const passThrough = {
action,
parameter_field_type: 'dropdown',
parameter_type: 'duration_type',
} as Partial<TEvents['ce_contracts_set_up_form']>;
const payload = { ...passThrough, durationUnit: 'm' };

it('should send form_name, trade type & provided payload with ce_contracts_set_up_form event', async () => {
const spyTrackEvent = jest.spyOn(Analytics, 'trackEvent');
const spyDebouncedFunction = jest.spyOn(mockedTradeStore, 'debouncedSendTradeParamsAnalytics');

mockedTradeStore.sendTradeParamsAnalytics(payload);
await waitFor(() => {
expect(spyTrackEvent).toHaveBeenCalledWith('ce_contracts_set_up_form', {
...passThrough,
form_name: 'default',
trade_type_name: 'Rise/Fall',
duration_type: 'minutes',
});
expect(spyDebouncedFunction).not.toHaveBeenCalled();
});
});
it('should send analytics using debouncedSendTradeParamsAnalytics function when isDebounced is true', async () => {
const spyTrackEvent = jest.spyOn(Analytics, 'trackEvent');
const spyDebouncedFunction = jest.spyOn(mockedTradeStore, 'debouncedSendTradeParamsAnalytics');

mockedTradeStore.sendTradeParamsAnalytics(payload, true);
await waitFor(() => {
expect(spyTrackEvent).toHaveBeenCalledWith('ce_contracts_set_up_form', {
...passThrough,
form_name: 'default',
trade_type_name: 'Rise/Fall',
duration_type: 'minutes',
});
expect(spyDebouncedFunction).toHaveBeenCalled();
});
});
it('should not send "change_parameter_value" analytics when isDebounced is true, & payload has no duration_type or parameter_value', async () => {
jest.clearAllMocks();
const spyTrackEvent = jest.spyOn(Analytics, 'trackEvent');
const payloadWithEmptyValue = {
action,
input_type: 'manual',
parameter_field_type: 'number',
parameter_type: 'stake_value',
parameter_value: '',
} as Partial<TEvents['ce_contracts_set_up_form']>;

mockedTradeStore.sendTradeParamsAnalytics(payloadWithEmptyValue, true);
await waitFor(() => expect(spyTrackEvent).not.toHaveBeenCalled());
});
});
describe('setDigitStats', () => {
const digit_stats = [120, 86, 105, 94, 85, 86, 124, 107, 90, 103];
it('should set digit_stats', () => {
Expand Down
49 changes: 0 additions & 49 deletions packages/trader/src/Stores/Modules/Trading/trade-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
hasBarrier,
isHighLow,
CONTRACT_TYPES,
getContractTypesConfig,
setTradeURLParams,
getTradeURLParams,
isTouchContract,
Expand Down Expand Up @@ -341,13 +340,6 @@ export default class TradeStore extends BaseStore {
is_trade_params_expanded = true;
v2_params_initial_values: TV2ParamsInitialValues = {};

debouncedSendTradeParamsAnalytics = debounce((payload: TEvents['ce_contracts_set_up_form']) => {
if (payload.action === 'change_parameter_value') {
const { duration_type, parameter_value } = payload;
if (!duration_type && parameter_value === '') return;
}
Analytics.trackEvent('ce_contracts_set_up_form', payload);
}, 2000);
debouncedSetChartStatus = debounce((status: boolean) => {
runInAction(() => {
this.is_chart_loading = status;
Expand Down Expand Up @@ -544,7 +536,6 @@ export default class TradeStore extends BaseStore {
resetAccumulatorData: action.bound,
resetErrorServices: action.bound,
resetPreviousSymbol: action.bound,
sendTradeParamsAnalytics: action.bound,
setActiveSymbols: action.bound,
setActiveSymbolsV2: action.bound,
setBarrierChoices: action.bound,
Expand Down Expand Up @@ -1212,24 +1203,6 @@ export default class TradeStore extends BaseStore {
status: 'open',
});
}
if (
!this.root_store.ui.is_mobile &&
(this.basis_list.length > 1 || this.duration_units_list.length > 1)
) {
const durationMode =
this.root_store.ui.is_advanced_duration && this.expiry_type
? this.expiry_type
: ANALYTICS_DURATIONS.find(value => value.startsWith(this.duration_unit)) ?? '';
this.sendTradeParamsAnalytics({
action: 'run_contract',
...(this.duration_units_list.length && durationMode
? { switcher_duration_mode_name: durationMode }
: {}),
...(this.basis_list.length > 1 && this.basis
? { switcher_stakepayout_mode_name: this.basis }
: {}),
});
}

this.is_purchasing_contract = false;
return;
Expand Down Expand Up @@ -1261,28 +1234,6 @@ export default class TradeStore extends BaseStore {
})();
};

sendTradeParamsAnalytics = (
options: Partial<TEvents['ce_contracts_set_up_form']> & { durationUnit?: string },
isDebounced?: boolean
) => {
const { durationUnit, ...passThrough } = options;
const payload = {
...passThrough,
form_name: 'default',
trade_type_name: getContractTypesConfig()[this.contract_type]?.title,
...(durationUnit
? {
duration_type: ANALYTICS_DURATIONS.find(value => value.startsWith(durationUnit ?? '')) ?? '',
}
: {}),
} as TEvents['ce_contracts_set_up_form'];
if (isDebounced) {
this.debouncedSendTradeParamsAnalytics(payload);
} else {
Analytics.trackEvent('ce_contracts_set_up_form', payload);
}
};

/**
* Updates the store with new values
* @param {Object} new_state - new values to update the store with
Expand Down

0 comments on commit f3e56bb

Please sign in to comment.