Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maryia/dtra-369/Send chart events using stateChangeListener for analytics collection #1439

Merged
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d960caf
feat: add action for choosing chart type
maryia-deriv Aug 28, 2023
1e47460
feat: add state change events for chart type and interval
maryia-deriv Aug 28, 2023
ce5492d
feat: add open & close events for chart mode modal
maryia-deriv Aug 31, 2023
4814974
refactor: CHART_TYPE_CHANGE event
maryia-deriv Aug 31, 2023
5b18f1f
Merge branch 'master' of github.com:binary-com/SmartCharts into maryi…
maryia-deriv Sep 1, 2023
6aa4022
chore: add event for opening and closing markets list
maryia-deriv Sep 1, 2023
0fca774
feat: added symbol_change state change event
maryia-deriv Sep 1, 2023
79ea276
chore: add more events
maryia-deriv Sep 3, 2023
1e053ee
chore: add more events
maryia-deriv Sep 3, 2023
582a225
chore: add more events
maryia-deriv Sep 3, 2023
2c565df
feat: added event for adding indicator
maryia-deriv Sep 4, 2023
483b066
fix: symbol change & info redirect events
maryia-deriv Sep 5, 2023
7f7aeed
refactor: getSymbolMarketCategory
maryia-deriv Sep 5, 2023
4603a2a
feat: added final events for indicators
maryia-deriv Sep 5, 2023
e45a521
refactor: united info
maryia-deriv Sep 5, 2023
a10dfff
Merge branch 'master' into maryia/dtra-369/rudderstack
maryia-deriv Sep 5, 2023
73570e6
feat: add event for clear all button
maryia-deriv Sep 5, 2023
2ad7bbc
fix: delete event for indicators
maryia-deriv Sep 5, 2023
ee0eea6
test: getSymbolMarketCategory & getTimeIntervalName
maryia-deriv Sep 5, 2023
2fe0f12
refactor: linting
maryia-deriv Sep 5, 2023
2e45c0f
fix: against empty initial chart type value
maryia-deriv Sep 5, 2023
75cfd84
fix: indicator events
maryia-deriv Sep 5, 2023
32722ff
fix: send id instead of name since english version is needed for any …
maryia-deriv Sep 6, 2023
40a4490
fix: set symbol instea
maryia-deriv Sep 6, 2023
f13f208
refactor: rename variables
maryia-deriv Sep 6, 2023
b3cfd72
Merge branch 'master' into maryia/dtra-369/rudderstack
maryia-deriv Sep 6, 2023
ab6d6d5
refactor: remove unnecessary empty object param
maryia-deriv Sep 7, 2023
67d9432
Merge branch 'master' of github.com:binary-com/SmartCharts into maryi…
maryia-deriv Sep 13, 2023
c8924af
Merge branch 'master' into maryia/dtra-369/rudderstack
maryia-deriv Sep 21, 2023
0cd7e29
Merge branch 'master' into maryia/dtra-369/rudderstack
maryia-deriv Sep 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/Constant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -552,11 +552,26 @@ export const Languages = [
];

export const STATE = {
CHART_INTERVAL_CHANGE: 'CHART_INTERVAL_CHANGE',
CHART_MODE_TOGGLE: 'CHART_MODE_TOGGLE',
CHART_TYPE_CHANGE: 'CHART_TYPE_CHANGE',
FAVORITE_MARKETS_TOGGLE: 'FAVORITE_MARKETS_TOGGLE',
INDICATOR_ADDED: 'INDICATOR_ADDED',
INDICATOR_DELETED: 'INDICATOR_DELETED',
INDICATOR_INFO_TOGGLE: 'INDICATOR_INFO_TOGGLE',
INDICATOR_SEARCH: 'INDICATOR_SEARCH',
INDICATOR_SETTINGS_OPEN: 'INDICATOR_SETTINGS_OPEN',
INDICATORS_CLEAR_ALL: 'INDICATORS_CLEAR_ALL',
INDICATORS_MODAL_TOGGLE: 'INDICATORS_MODAL_TOGGLE',
INITIAL: 'INITIAL',
MARKET_INFO_REDIRECT: 'MARKET_INFO_REDIRECT',
MARKET_SEARCH: 'MARKET_SEARCH',
MARKET_STATE_CHANGE: 'MARKET_STATE_CHANGE',
MARKETS_LIST_TOGGLE: 'MARKETS_LIST_TOGGLE',
READY: 'READY',
SCROLL_TO_LEFT: 'SCROLL_TO_LEFT',
MARKET_STATE_CHANGE: 'MARKET_STATE_CHANGE',
};
SYMBOL_CHANGE: 'SYMBOL_CHANGE',
} as const;

export const TooltipsContent = {
predictionIndicator: t.translate(
Expand Down
17 changes: 11 additions & 6 deletions src/components/ChartTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import ReactDOM from 'react-dom';
import { TProcessedSymbolItem } from 'src/binaryapi/ActiveSymbols';
import { useStores } from 'src/store';
import { TOpenMarket } from 'src/types';
import { getSymbolMarketCategory } from 'src/utils';
import { STATE } from 'src/Constant';
import '../../sass/components/_chart-title.scss';
import { CategoricalDisplay } from './categoricaldisplay';
import Menu from './Menu';
Expand All @@ -21,9 +23,8 @@ export type TChartTitleProps = {
};

const ChartTitle = (props: TChartTitleProps) => {
const { chartTitle, chart, chartSetting } = useStores();
const { chartTitle, chart, chartSetting, state } = useStores();
const { isMobile } = chart;

const { theme } = chartSetting;
const {
menuStore,
Expand All @@ -36,7 +37,6 @@ const ChartTitle = (props: TChartTitleProps) => {
} = chartTitle;
const onChange = props.onChange || setSymbol;
const setMenuOpen = menuStore.setOpen;

const { containerId, enabled, portalNodeId, searchInputClassName, open, open_market, isNestedList } = props;

React.useEffect(() => {
Expand Down Expand Up @@ -68,9 +68,14 @@ const ChartTitle = (props: TChartTitleProps) => {
store={categoricalDisplay}
isNestedList={isNestedList}
searchInputClassName={searchInputClassName}
onSelectItem={(x: TProcessedSymbolItem) => {
if (x.symbol !== currentSymbol.symbol) {
onChange(x.symbol);
onSelectItem={(symbol_object: TProcessedSymbolItem, category_id: string) => {
if (symbol_object.symbol !== currentSymbol.symbol) {
onChange(symbol_object.symbol);
state.stateChange(STATE.SYMBOL_CHANGE, {
tab_market_name:
category_id === 'favorite' ? 'favorites' : getSymbolMarketCategory(symbol_object),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referring to this it could also be symbol_market_category name instead of tab_market_name https://github.com/binary-com/deriv-app/pull/9848/files#r1316656672

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henry-deriv Please see this comment in the related deriv-app deriv-com/deriv-app#9848 (comment)
I stuck to the properties requested by marketing.
Here I explain what options we have: #1439 (comment)

market_type_name: symbol_object.symbol,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im just wondering why are we setting market_type_name to symbol name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henry-deriv it's because we need to send it in this form to rudderstack via deriv-app. I can either call this property straight the way it needs to go to analytics and have less logic in deriv-app - it's what I do know, or name it in the way we want here and rename this properties later when they are received inside deriv-app.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry. i was under the impression that market_type_name referrers to derived, forex, cryptocurrencies, etc. Thats why i was confused as to why symbol is passed as market_type_name

Screenshot 2023-09-06 at 4 14 23 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henry-deriv marketing team has their own names for all this :)) hm, I think I can change it here, and rename the property in deriv-app PR before we send it to rudderstack

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good

});
}
setMenuOpen(false);
}}
Expand Down
10 changes: 9 additions & 1 deletion src/components/ChartTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import React from 'react';
import { observer } from 'mobx-react-lite';
import { useStores } from 'src/store';
import { ChartType, TIcon } from 'src/types';
import { getTimeIntervalName } from 'src/utils';
import { TListItem } from 'src/store/ListStore';
import { Intervals, STATE } from 'src/Constant';
import Tooltip from './Tooltip';
import '../../sass/components/_chart-types.scss';
import List from './List';
Expand All @@ -23,7 +25,7 @@ type TChartTypesProps = {
};

const ChartTypes = ({ enabled, newDesign, onChange: onChangeFn }: TChartTypesProps) => {
const { chartType, chart } = useStores();
const { chartType, chart, state } = useStores();

const { listStore, setTypeFromUI, updateProps, types, type, menuStore } = chartType;
const { open: menuOpen, setOpen } = chartType.menuStore;
Expand All @@ -35,6 +37,12 @@ const ChartTypes = ({ enabled, newDesign, onChange: onChangeFn }: TChartTypesPro

const onItemClick = (chart_type: ChartType) => {
if (type.id !== chart_type.id) {
if (chart_type.id) {
state.stateChange(STATE.CHART_TYPE_CHANGE, {
chart_type_name: chart_type.id === 'colored_bar' ? chart_type.text : chart_type.text.toLowerCase(),
time_interval_name: getTimeIntervalName(state.granularity, Intervals),
});
}
onChange(chart_type.id);
}
setOpen(false);
Expand Down
9 changes: 8 additions & 1 deletion src/components/Favorite.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';
import classNames from 'classnames';
import { useStores } from 'src/store';
import { STATE } from 'src/Constant';
import { FavoriteIcon } from './Icons';
import FavoriteStore from '../store/FavoriteStore';
import { logEvent, LogCategories, LogActions } from '../utils/ga';
Expand All @@ -11,6 +13,7 @@ type TFavoriteProps = {
};

const Favorite = ({ category, id }: TFavoriteProps) => {
const { chart, state } = useStores();
const [store] = React.useState(FavoriteStore.getInstance());
const [is_favorite, setFavorite] = React.useState(false);

Expand All @@ -19,8 +22,12 @@ const Favorite = ({ category, id }: TFavoriteProps) => {
e.stopPropagation();
(e as TCustomEvent).nativeEvent.isHandledByDialog = true; // prevent close dialog
store.toggleFavorite(category, id);
state.stateChange(STATE.FAVORITE_MARKETS_TOGGLE, {
is_favorite: store.isFavorite(category, id),
market_type_name: chart.activeSymbols?.symbolMap[id]?.symbol,
});
},
[store, category, id]
[chart, state, store, category, id]
);
const onFavoriteUpdate = React.useCallback(() => {
const isFavorite = store.isFavorite(category, id);
Expand Down
52 changes: 43 additions & 9 deletions src/components/StudyLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Tooltip from './Tooltip';
import Scroll from './Scroll';
import { IndicatorIcon, ActiveIcon, EmptyStateIcon, SettingIcon, DeleteIcon, InfoCircleIcon, BackIcon } from './Icons';
import '../../sass/components/_studylegend.scss';
import { TActiveItem, TooltipsContent } from '../Constant';
import { STATE, TActiveItem, TooltipsContent } from '../Constant';
import Menu from './Menu';
import SearchInput from './SearchInput';

Expand Down Expand Up @@ -109,7 +109,9 @@ const IndicatorList = ({
}
content={
Item.isPrediction && isTick
? t.translate('This indicator does not support 1-tick intervals. To use this indicator, change your chart time interval to 1 minute or more.')
? t.translate(
'This indicator does not support 1-tick intervals. To use this indicator, change your chart time interval to 1 minute or more.'
)
: `${Item.name} ${Item.bars ? `(${Item.bars})` : ''}`
}
>
Expand Down Expand Up @@ -259,7 +261,7 @@ const TabularDisplay = ({
);

const StudyLegend = ({ portalNodeId }: TStudyLegendProps) => {
const { studies, chart, timeperiod } = useStores();
const { studies, chart, state, timeperiod } = useStores();

const {
menuStore,
Expand All @@ -286,6 +288,18 @@ const StudyLegend = ({ portalNodeId }: TStudyLegendProps) => {
const activeStudiesNo = activeItems.length;

updatePortalNode(portalNodeId);

const getIndicatorCategoryName = (id: string) =>
items.find(i => i.items.some(el => el.id === id))?.id.replace('-', ' ') ?? '';

const handleStateChange = (id: string, type: string, payload?: { is_info_open: boolean }) => {
state.stateChange(type, {
indicator_type_name: id,
indicators_category_name: getIndicatorCategoryName(id),
...(payload ?? {}),
});
};

return (
<Menu
store={menuStore}
Expand All @@ -298,7 +312,12 @@ const StudyLegend = ({ portalNodeId }: TStudyLegendProps) => {
customHead={
infoItem ? (
<div className='sc-dialog__head--info'>
<BackIcon onClick={() => onInfoItem(null)} />
<BackIcon
onClick={() => {
onInfoItem(null);
handleStateChange(infoItem.id, STATE.INDICATOR_INFO_TOGGLE);
}}
/>
{infoItem.name}
</div>
) : (
Expand Down Expand Up @@ -331,7 +350,10 @@ const StudyLegend = ({ portalNodeId }: TStudyLegendProps) => {
<button
type='button'
className='sc-btn sc-btn--primary sc-btn--w100'
onClick={() => onSelectItem(infoItem?.id)}
onClick={() => {
onSelectItem(infoItem?.id);
handleStateChange(infoItem?.id, STATE.INDICATOR_ADDED, { is_info_open: true });
}}
disabled={infoItem?.disabledAddBtn}
>
{t.translate('Add')}
Expand All @@ -345,10 +367,22 @@ const StudyLegend = ({ portalNodeId }: TStudyLegendProps) => {
selectedTab={selectedTab}
categories={items}
searchedCategories={searchedItems}
onSelectItem={onSelectItem}
onDeleteItem={deleteStudy}
onEditItem={editStudy}
onInfoItem={onInfoItem}
onSelectItem={(id: string) => {
onSelectItem(id);
handleStateChange(id, STATE.INDICATOR_ADDED);
}}
onDeleteItem={(item: TActiveItem['dataObject']['sd']) => {
deleteStudy(item);
handleStateChange(item.type, STATE.INDICATOR_DELETED);
}}
onEditItem={(study: TActiveItem['dataObject']) => {
editStudy(study);
handleStateChange(study.sd.type, STATE.INDICATOR_SETTINGS_OPEN);
}}
onInfoItem={(item: TActiveItem) => {
onInfoItem(item);
handleStateChange(item.id, STATE.INDICATOR_INFO_TOGGLE, { is_info_open: true });
}}
activeItems={activeItems}
clearAll={deleteAll}
searchQuery={searchQuery}
Expand Down
6 changes: 3 additions & 3 deletions src/components/categoricaldisplay/CategoricalDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type TCategoricalDisplayProps = {
searchInputClassName?: string;
isNestedList?: boolean;
id?: string;
onSelectItem?: (item: TProcessedSymbolItem) => void;
onSelectItem?: (item: TProcessedSymbolItem, category_id: string) => void;
disableAll?: boolean;
};

Expand Down Expand Up @@ -50,8 +50,8 @@ const CategoricalDisplay = ({

const innerPanel = (
<ResultsPanel
onSelectItem={(item: TProcessedSymbolItem) => {
onSelectItem?.(item);
onSelectItem={(item: TProcessedSymbolItem, category_id: string) => {
onSelectItem?.(item, category_id);
setFilterText('');
}}
disableAll={disableAll}
Expand Down
Loading