Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

MM-2998 Add telemetry for product notices #6934

Merged
merged 5 commits into from Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -81,6 +81,7 @@ exports[`ProductNoticesModal Match snapshot for user notice 1`] = `
className="GenericModal__button actionButton"
href="http://download.com/path"
id="actionButton"
onClick={[Function]}
rel="noopener noreferrer"
target="_blank"
>
Expand Down Expand Up @@ -150,6 +151,7 @@ exports[`ProductNoticesModal Should match snapshot for system admin notice 1`] =
className="GenericModal__button actionButton"
href="http://download.com/path"
id="actionButton"
onClick={[Function]}
rel="noopener noreferrer"
target="_blank"
>
Expand Down
16 changes: 16 additions & 0 deletions components/product_notices_modal/product_notices.test.tsx
Expand Up @@ -6,10 +6,18 @@ import {shallow} from 'enzyme';

import GenericModal from 'components/generic_modal';
import {isDesktopApp, getDesktopVersion} from 'utils/user_agent';
import {trackEvent} from 'actions/diagnostics_actions.jsx';
sudheerDev marked this conversation as resolved.
Show resolved Hide resolved

import ProductNoticesModal from './product_notices_modal';

jest.mock('utils/user_agent');
jest.mock('actions/diagnostics_actions.jsx', () => {
const original = jest.requireActual('actions/diagnostics_actions.jsx');
return {
...original,
trackEvent: jest.fn(),
};
});

describe('ProductNoticesModal', () => {
const noticesData = [{
Expand Down Expand Up @@ -99,6 +107,7 @@ describe('ProductNoticesModal', () => {
await baseProps.actions.getInProductNotices();
wrapper.setState({noticesData: [noticesData[1]]});
wrapper.find(GenericModal).prop('handleConfirm')?.();
expect(trackEvent).toHaveBeenCalledWith('ui', 'notice_click_123');
expect(window.open).toHaveBeenCalledWith(noticesData[1].actionParam, '_blank');
});

Expand Down Expand Up @@ -173,4 +182,11 @@ describe('ProductNoticesModal', () => {

expect(baseProps.actions.getInProductNotices).toHaveBeenCalledTimes(1);
});

test('Should call for trackEvent on click of action button', async () => {
const wrapper = shallow(<ProductNoticesModal {...baseProps}/>);
await baseProps.actions.getInProductNotices();
wrapper.find('.actionButton').simulate('click');
expect(trackEvent).toHaveBeenCalledWith('ui', 'notice_click_124');
});
});
8 changes: 8 additions & 0 deletions components/product_notices_modal/product_notices_modal.tsx
Expand Up @@ -6,6 +6,7 @@ import {FormattedMessage} from 'react-intl';

import {ProductNotices, ProductNotice} from 'mattermost-redux/types/product_notices';
import {WebsocketStatus} from 'mattermost-redux/types/websocket';
import {trackEvent} from 'actions/diagnostics_actions.jsx';

import Markdown from 'components/markdown';
import GenericModal from 'components/generic_modal';
Expand Down Expand Up @@ -186,6 +187,11 @@ export default class ProductNoticesModal extends React.PureComponent<Props, Stat
return null;
}

private trackClickEvent = () => {
const presentNoticeInfo = this.state.noticesData[this.state.presentNoticeIndex];
trackEvent('ui', `notice_click_${presentNoticeInfo.id}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

not to change it right now, but feels like 'ui' should really be a constant so we use the same string throughout the code prevent typos

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya, i agree. All events strings need to be changed to constants. I think we can run a campaign on this

}

private renderActionButton(presentNoticeInfo: ProductNotice) {
const noOfNotices = this.state.noticesData.length;

Expand All @@ -197,6 +203,7 @@ export default class ProductNoticesModal extends React.PureComponent<Props, Stat
rel='noopener noreferrer'
className='GenericModal__button actionButton'
href={presentNoticeInfo.actionParam}
onClick={this.trackClickEvent}
>
{presentNoticeInfo.actionText}
</a>
Expand All @@ -209,6 +216,7 @@ export default class ProductNoticesModal extends React.PureComponent<Props, Stat
const presentNoticeInfo = this.state.noticesData[this.state.presentNoticeIndex];
const noOfNotices = this.state.noticesData.length;
if (noOfNotices === 1 && presentNoticeInfo.actionText) {
this.trackClickEvent();
window.open(presentNoticeInfo.actionParam, '_blank');
} else if (this.state.presentNoticeIndex + 1 < noOfNotices) {
const nextNoticeInfo = this.state.noticesData[this.state.presentNoticeIndex + 1];
Expand Down