Skip to content

Commit 34d8678

Browse files
authored
Merge pull request #1468 from AppQuality/UN-1960-tag-edit-analytics
Un 1960 tag edit analytics
2 parents f8f8813 + 10d0198 commit 34d8678

File tree

3 files changed

+82
-23
lines changed

3 files changed

+82
-23
lines changed

src/pages/Video/components/EditTagModal.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { useEffect, useRef, useState } from 'react';
1414
import { useTranslation } from 'react-i18next';
1515
import { useParams } from 'react-router-dom';
16+
import analytics from 'src/analytics';
1617
import { appTheme } from 'src/app/theme';
1718
import { ReactComponent as SaveIcon } from 'src/assets/icons/save.svg';
1819
import {
@@ -26,6 +27,7 @@ interface EditModalProps {
2627
title: string;
2728
label: string;
2829
description: string;
30+
type: 'theme' | 'extraTag';
2931
}
3032

3133
export const EditTagModal = ({
@@ -34,6 +36,7 @@ export const EditTagModal = ({
3436
title,
3537
label,
3638
description,
39+
type,
3740
}: EditModalProps) => {
3841
// Extract both the current title and the usage number in parentheses in two variables
3942

@@ -56,6 +59,13 @@ export const EditTagModal = ({
5659
}, [newName]);
5760

5861
const handleSubmit = async () => {
62+
analytics.track('tagUpdateSubmitted', {
63+
tagId: tag.id.toString(),
64+
tagType: type,
65+
associatedObservations: tag.usageNumber,
66+
submissionTime: Date.now(),
67+
});
68+
5969
if (error) return;
6070
// Update the title in the form
6171
try {
@@ -82,6 +92,15 @@ export const EditTagModal = ({
8292
{ placement: 'top' }
8393
);
8494
} catch (err: any) {
95+
analytics.track('tagUpdateFailed', {
96+
tagId: tag.id.toString(),
97+
tagType: type,
98+
attemptedTagName: newName,
99+
errorType: err.status === 409 ? 'duplicate' : 'other',
100+
errorMessage: err.message,
101+
associatedObservations: tag.usageNumber,
102+
});
103+
85104
// Handle error (e.g., show error toast)
86105
// if status code is 409, conflict with another already saved name, show specific error
87106
if (err.status === 409) {

src/pages/Video/components/ObservationForm.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Form, Formik, FormikHelpers, FormikProps } from 'formik';
1717
import { ComponentProps, useEffect, useRef, useState } from 'react';
1818
import { useTranslation } from 'react-i18next';
1919
import { useParams } from 'react-router-dom';
20+
import analytics from 'src/analytics';
2021
import { appTheme } from 'src/app/theme';
2122
import { getColorWithAlpha } from 'src/common/utils';
2223
import {
@@ -149,6 +150,7 @@ const ObservationForm = ({
149150
selected: selectedOptions.some((bt) => bt.id === tag.id),
150151
actions: ({ closeModal }) => (
151152
<EditTagModal
153+
type="extraTag"
152154
tag={tag}
153155
closeModal={closeModal}
154156
title={t('__VIDEO_PAGE_TAGS_DROPDOWN_EDIT_MODAL_TITLE')}
@@ -163,6 +165,14 @@ const ObservationForm = ({
163165
/>
164166
),
165167
actionIcon: <EditIcon />,
168+
onOptionActionClick: () => {
169+
analytics.track('tagEditModalOpened', {
170+
tagId: tag.id.toString(),
171+
tagType: 'extraTag',
172+
tagName: tag.name,
173+
associatedObservations: tag.usageNumber,
174+
});
175+
},
166176
}))
167177
);
168178
}
@@ -381,6 +391,14 @@ const ObservationForm = ({
381391
listboxAppendToNode={document.body}
382392
creatable
383393
maxItems={4}
394+
onClick={() =>
395+
analytics.track('tagDropdownOpened', {
396+
dropdownType: 'extraTags',
397+
availableTagsCount: options.length,
398+
selectedTagsCount: options.filter((o) => o.selected)
399+
.length,
400+
})
401+
}
384402
size="medium"
385403
i18n={{
386404
placeholder: t(

src/pages/Video/components/TitleDropdownNew.tsx

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import {
44
} from '@appquality/unguess-design-system';
55
import { ReactComponent as EditIcon } from '@zendeskgarden/svg-icons/src/12/pencil-stroke.svg';
66
import { FormikProps } from 'formik';
7+
import { ComponentProps, useMemo } from 'react';
78
import { useTranslation } from 'react-i18next';
89
import { useParams } from 'react-router-dom';
10+
import analytics from 'src/analytics';
911
import { ReactComponent as CopyIcon } from 'src/assets/icons/copy-icon.svg';
1012
import {
1113
GetCampaignsByCidVideoTagsApiResponse,
@@ -31,6 +33,42 @@ export const TitleDropdown = ({
3133
const { campaignId } = useParams();
3234
const [addVideoTags] = usePostCampaignsByCidVideoTagsMutation();
3335
const titleMaxLength = 70;
36+
const options: ComponentProps<typeof Autocomplete>['options'] = useMemo(
37+
() =>
38+
(titles || []).map((i) => ({
39+
id: i.id.toString(),
40+
value: i.id.toString(),
41+
label: `${i.name} (${i.usageNumber})`,
42+
isSelected: formProps.values.title === i.id,
43+
actions: ({ closeModal }) => (
44+
<EditTagModal
45+
type="theme"
46+
tag={i}
47+
closeModal={closeModal}
48+
title={t('__VIDEO_PAGE_THEMES_DROPDOWN_EDIT_MODAL_TITLE')}
49+
label={t('__VIDEO_PAGE_THEMES_DROPDOWN_EDIT_MODAL_LABEL')}
50+
description={t(
51+
'__VIDEO_PAGE_THEMES_DROPDOWN_EDIT_MODAL_DESCRIPTION',
52+
{
53+
usageNumber: i.usageNumber,
54+
count: Number(i.usageNumber),
55+
}
56+
)}
57+
/>
58+
),
59+
actionIcon: <EditIcon />,
60+
itemID: i.id.toString(),
61+
onOptionActionClick: () => {
62+
analytics.track('tagEditModalOpened', {
63+
tagId: i.id.toString(),
64+
tagType: 'theme',
65+
tagName: i.name,
66+
associatedObservations: i.usageNumber,
67+
});
68+
},
69+
})),
70+
[titles, formProps.values.title]
71+
);
3472

3573
if (!titles) {
3674
return null;
@@ -39,6 +77,7 @@ export const TitleDropdown = ({
3977
return (
4078
<Field>
4179
<Autocomplete
80+
options={options}
4281
data-qa="video-title-dropdown"
4382
isEditable
4483
isCreatable
@@ -49,6 +88,12 @@ export const TitleDropdown = ({
4988
const title = titles.find((i) => i.id === Number(selection.value));
5089
return title?.name || '';
5190
}}
91+
onClick={() =>
92+
analytics.track('tagDropdownOpened', {
93+
dropdownType: 'theme',
94+
availableTagsCount: options.length,
95+
})
96+
}
5297
selectionValue={formProps.values.title.toString()}
5398
onCreateNewOption={async (value) => {
5499
if (value.length > titleMaxLength) {
@@ -83,29 +128,6 @@ export const TitleDropdown = ({
83128
if (!selectionValue || !inputValue) return;
84129
formProps.setFieldValue('title', Number(selectionValue));
85130
}}
86-
options={(titles || []).map((i) => ({
87-
id: i.id.toString(),
88-
value: i.id.toString(),
89-
label: `${i.name} (${i.usageNumber})`,
90-
isSelected: formProps.values.title === i.id,
91-
actions: ({ closeModal }) => (
92-
<EditTagModal
93-
tag={i}
94-
closeModal={closeModal}
95-
title={t('__VIDEO_PAGE_THEMES_DROPDOWN_EDIT_MODAL_TITLE')}
96-
label={t('__VIDEO_PAGE_THEMES_DROPDOWN_EDIT_MODAL_LABEL')}
97-
description={t(
98-
'__VIDEO_PAGE_THEMES_DROPDOWN_EDIT_MODAL_DESCRIPTION',
99-
{
100-
usageNumber: i.usageNumber,
101-
count: Number(i.usageNumber),
102-
}
103-
)}
104-
/>
105-
),
106-
itemID: i.id.toString(),
107-
actionIcon: <EditIcon />,
108-
}))}
109131
startIcon={<CopyIcon />}
110132
placeholder={t(
111133
'__VIDEO_PAGE_ACTIONS_OBSERVATION_FORM_FIELD_TITLE_PLACEHOLDER'

0 commit comments

Comments
 (0)