Skip to content

Commit

Permalink
[BOT] Farabi/bot-2299/add-usage-tracking-for-announcements (deriv-com…
Browse files Browse the repository at this point in the history
…#17186)

* chore: added rudderstack track events for announcement click

* chore: added announcement action and close events

* fix: pass announcement name as the main title and subform names

* chore: added load strategy open event on import announcement click

* fix: call the open load strategy event from config
  • Loading branch information
farabi-deriv authored Oct 17, 2024
1 parent 8ed6de6 commit 4d74694
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/bot-web-ui/src/analytics/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export enum ACTION {
GOOGLE_DRIVE_CONNECT = 'google_drive_connect',
GOOGLE_DRIVE_DISCONNECT = 'google_drive_disconnect',
SWITCH_LOAD_STRATEGY_TAB = 'switch_load_strategy_tab',
ANNOUNCEMENT_CLICK = 'announcement_click',
ANNOUNCEMENT_ACTION = 'announcement_action',
}

export type TFormStrategy = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const rudderStackSendCloseEvent = ({
quick_strategy_tab,
selected_strategy,
load_strategy_tab,
announcement_name,
}: TEvents['ce_bot_form'] & TFormStrategy) => {
Analytics.trackEvent('ce_bot_form', {
action: ACTION.CLOSE,
Expand All @@ -31,6 +32,7 @@ export const rudderStackSendCloseEvent = ({
quick_strategy_tab,
strategy_name: getRsStrategyType(selected_strategy),
load_strategy_tab,
announcement_name,
});
};

Expand Down
24 changes: 24 additions & 0 deletions packages/bot-web-ui/src/analytics/rudderstack-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,27 @@ export const rudderStackSendDashboardClickEvent = ({ dashboard_click_name, subpa
dashboard_click_name,
});
};

export const rudderStackSendAnnouncementClickEvent = ({ announcement_name }: TEvents['ce_bot_form']) => {
Analytics.trackEvent('ce_bot_form', {
action: ACTION.ANNOUNCEMENT_CLICK,
form_name,
subform_name: 'announcements',
subform_source: 'dashboard',
announcement_name,
});
};

export const rudderStackSendAnnouncementActionEvent = ({
announcement_name,
announcement_action,
}: TEvents['ce_bot_form']) => {
Analytics.trackEvent('ce_bot_form', {
action: ACTION.ANNOUNCEMENT_ACTION,
form_name,
subform_name: 'announcements',
subform_source: 'dashboard',
announcement_name,
announcement_action,
});
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Dialog, Text } from '@deriv/components';
import { LabelPairedCheckCaptionFillIcon } from '@deriv/quill-icons';
import { rudderStackSendCloseEvent } from '../../../analytics/rudderstack-common-events';
import { IconAnnounceModal } from './announcement-components';
import { TAnnounce, TContentItem } from './config';
import './announcement-dialog.scss';
Expand Down Expand Up @@ -44,7 +45,13 @@ const AnnouncementDialog = ({
onCancel={handleOnCancel}
is_mobile_full_width
has_close_icon
onClose={() => setIsAnnounceDialogOpen(false)}
onClose={() => {
setIsAnnounceDialogOpen(false);
rudderStackSendCloseEvent({
subform_name: 'announcements',
announcement_name: main_title,
});
}}
className={is_tablet ? `${base_classname} ${base_classname}--tablet` : base_classname}
>
<div className={`${base_classname}__body-text`}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { observer } from '@deriv/stores';
import { localize } from '@deriv/translations';
import { Notifications as Announcement } from '@deriv-com/ui';
import { useDBotStore } from 'Stores/useDBotStore';
import { rudderStackSendOpenEvent } from '../../../analytics/rudderstack-common-events';
import {
rudderStackSendAnnouncementActionEvent,
rudderStackSendAnnouncementClickEvent,
} from '../../../analytics/rudderstack-dashboard';
import { guide_content } from '../../tutorials/constants';
import { performButtonAction } from './utils/accumulator-helper-functions';
import { MessageAnnounce, TitleAnnounce } from './announcement-components';
Expand Down Expand Up @@ -42,6 +47,7 @@ const Announcements = observer(({ is_mobile, is_tablet, handleTabChange }: TAnno
setSelectedAnnouncement(announcement);
setIsAnnounceDialogOpen(true);
setIsOpenAnnounceList(prev => !prev);
rudderStackSendAnnouncementClickEvent({ announcement_name: announcement.announcement.main_title });

let data: Record<string, boolean> | null = null;
data = JSON.parse(localStorage.getItem('bot-announcements') ?? '{}');
Expand Down Expand Up @@ -102,6 +108,10 @@ const Announcements = observer(({ is_mobile, is_tablet, handleTabChange }: TAnno
};

const handleOnCancel = () => {
rudderStackSendAnnouncementActionEvent({
announcement_name: selected_announcement?.announcement.main_title,
announcement_action: selected_announcement?.announcement.cancel_button_text,
});
if (selected_announcement?.switch_tab_on_cancel) {
handleTabChange(selected_announcement.switch_tab_on_cancel);
if (selected_announcement.announcement.id === 'ACCUMULATOR_ANNOUNCE') {
Expand All @@ -113,6 +123,10 @@ const Announcements = observer(({ is_mobile, is_tablet, handleTabChange }: TAnno
};

const handleOnConfirm = () => {
rudderStackSendAnnouncementActionEvent({
announcement_name: selected_announcement?.announcement.main_title,
announcement_action: selected_announcement?.announcement.confirm_button_text,
});
if (selected_announcement?.switch_tab_on_confirm) {
handleTabChange(selected_announcement.switch_tab_on_confirm);
}
Expand All @@ -136,7 +150,15 @@ const Announcements = observer(({ is_mobile, is_tablet, handleTabChange }: TAnno
<div className='announcements'>
<button
className='announcements__button'
onClick={() => setIsOpenAnnounceList(prevState => !prevState)}
onClick={() => {
setIsOpenAnnounceList(prevState => !prevState);
if (!is_open_announce_list) {
rudderStackSendOpenEvent({
subform_name: 'announcements',
subform_source: 'dashboard',
});
}
}}
data-testid='btn-announcements'
>
<StandaloneBullhornRegularIcon fill='var(--icon-black-plus)' iconSize='sm' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { OpenLiveChatLink } from '@deriv/components';
import { Localize, localize } from '@deriv/translations';
import { DBOT_TABS } from 'Constants/bot-contents';
import { rudderStackSendOpenEvent } from '../../../analytics/rudderstack-common-events';
import { handleOnConfirmAccumulator } from './utils/accumulator-helper-functions';
import { IconAnnounce } from './announcement-components';

Expand Down Expand Up @@ -75,6 +76,14 @@ export const ANNOUNCEMENTS: Record<string, TAnnouncement> = {
should_not_be_cancel: true,
should_toggle_modal: true,
switch_tab_on_confirm: DBOT_TABS.BOT_BUILDER,
onConfirm: () => {
rudderStackSendOpenEvent({
subpage_name: 'bot_builder',
subform_source: 'announcements',
subform_name: 'load_strategy',
load_strategy_tab: 'recent',
});
},
},

BLOCKLY_ANNOUNCE: {
Expand Down

0 comments on commit 4d74694

Please sign in to comment.