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

Fix: Adaptive cards instrumentation #849

Merged
merged 4 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
39 changes: 20 additions & 19 deletions src/app/views/query-response/adaptive-cards/AdaptiveCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { bindActionCreators, Dispatch } from 'redux';

import { componentNames, eventTypes, telemetry } from '../../../../telemetry';
import { IAdaptiveCardProps } from '../../../../types/adaptivecard';
import { IQuery } from '../../../../types/query-runner';
import { getAdaptiveCard } from '../../../services/actions/adaptive-cards-action-creator';
import { sanitizeQueryUrl } from '../../../utils/query-url-sanitization';
import { translateMessage } from '../../../utils/translate-messages';
import { classNames } from '../../classnames';
import { Monaco } from '../../common';
Expand Down Expand Up @@ -59,7 +61,7 @@ class AdaptiveCard extends Component<IAdaptiveCardProps> {

public render() {
const { data, pending } = this.props.card;
const { body, queryStatus } = this.props;
const { body, queryStatus, sampleQuery } = this.props;
const classes = classNames(this.props);

if (!body) {
Expand Down Expand Up @@ -99,7 +101,7 @@ class AdaptiveCard extends Component<IAdaptiveCardProps> {
this.adaptiveCard!.parse(data);
const renderedCard = this.adaptiveCard!.render();
return (
<Pivot className='pivot-response' onLinkClick={onPivotItemClick}>
<Pivot className='pivot-response' onLinkClick={(pivotItem) => onPivotItemClick(sampleQuery, pivotItem)}>
<PivotItem
itemKey='card'
ariaLabel={translateMessage('card')}
Expand All @@ -119,7 +121,7 @@ class AdaptiveCard extends Component<IAdaptiveCardProps> {
/>
</PivotItem>
<PivotItem
itemKey='templateJSON'
itemKey='JSON-schema'
ariaLabel={translateMessage('JSON Schema')}
headerText={'JSON Schema'}
>
Expand All @@ -138,7 +140,10 @@ class AdaptiveCard extends Component<IAdaptiveCardProps> {
iconProps={{
iconName: 'copy',
}}
onClick={async () => genericCopy(JSON.stringify(data, null, 4))}
onClick={async () => {
genericCopy(JSON.stringify(data, null, 4));
trackJsonSchemaCopyEvent(sampleQuery)
}}
/>
<Monaco
language='json'
Expand All @@ -154,28 +159,24 @@ class AdaptiveCard extends Component<IAdaptiveCardProps> {
}
}

function onPivotItemClick(item?: PivotItem) {
function onPivotItemClick(query: IQuery | undefined, item?: PivotItem) {
if (!item) { return; }
const key = item.props.itemKey;
if (key) {
trackTabClickEvent(key);
telemetry.trackTabClickEvent(key, query);
}
}

function trackTabClickEvent(tabKey: string) {
switch (tabKey) {
case 'templateJSON': {
telemetry.trackEvent(
eventTypes.TAB_CLICK_EVENT,
{
ComponentName: componentNames.JSON_SCHEMA_TAB
});
break;
}
default: {
break;
}
function trackJsonSchemaCopyEvent(query: IQuery | undefined) {
if (!query) {
return;
}
const sanitizedUrl = sanitizeQueryUrl(query.sampleUrl);
telemetry.trackEvent(eventTypes.BUTTON_CLICK_EVENT,
{
ComponentName: componentNames.CODE_SNIPPETS_COPY_BUTTON,
QuerySignature: `${query.selectedVerb} ${sanitizedUrl}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename component name to JSON_SCHEMA_COPY_BUTTON

Copy link
Contributor

Choose a reason for hiding this comment

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

@ElinorW FYI

});
}

function mapStateToProps(state: any) {
Expand Down
24 changes: 4 additions & 20 deletions src/app/views/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Pivot, PivotItem } from 'office-ui-fabric-react';
import React from 'react';

import { componentNames, eventTypes, telemetry } from '../../../telemetry';
import { telemetry } from '../../../telemetry';
import History from './history/History';
import SampleQueries from './sample-queries/SampleQueries';


export const Sidebar = ({sampleHeaderText, historyHeaderText}: any) => {
export const Sidebar = ({ sampleHeaderText, historyHeaderText }: any) => {
return (
<div>
<Pivot onLinkClick={onPivotItemClick}>
Expand All @@ -21,26 +21,10 @@ export const Sidebar = ({sampleHeaderText, historyHeaderText}: any) => {
);
};

function onPivotItemClick (item?: PivotItem) {
function onPivotItemClick(item?: PivotItem) {
if (!item) { return; }
const key = item.props.itemKey;
if (key) {
trackTabClickEvent(key);
}
}

function trackTabClickEvent(tabKey: string) {
switch (tabKey) {
case 'history': {
telemetry.trackEvent(
eventTypes.TAB_CLICK_EVENT,
{
ComponentName: componentNames.HISTORY_TAB
});
break;
}
default: {
break;
}
telemetry.trackTabClickEvent(key);
}
}
1 change: 1 addition & 0 deletions src/telemetry/component-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const CODE_SNIPPETS_COPY_BUTTON = 'Code snippets copy button';
export const VIEW_ALL_PERMISSIONS_BUTTON = 'View all permissions button';
export const EXPORT_HISTORY_ITEM_BUTTON = 'Export history item button';
export const DELETE_HISTORY_ITEM_BUTTON = 'Delete history item button';
export const JSON_SCHEMA_COPY_BUTTON = 'JSON schema copy button';

// List items
export const SAMPLE_QUERY_LIST_ITEM = 'Sample query list item';
Expand Down
18 changes: 10 additions & 8 deletions src/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,20 @@ class Telemetry implements ITelemetry {
return withAITracking(this.reactPlugin, ComponentToTrack, componentName);
}

public trackTabClickEvent(tabKey: string, sampleQuery: IQuery) {
const sanitizedUrl = sanitizeQueryUrl(sampleQuery.sampleUrl);
public trackTabClickEvent(tabKey: string, sampleQuery: IQuery | null = null) {
let componentName = tabKey.replace('-', ' ');
componentName = `${componentName.charAt(0).toUpperCase()}${componentName.slice(1)} tab`;
telemetry.trackEvent(TAB_CLICK_EVENT,
{
ComponentName: componentName,
QuerySignature: `${sampleQuery.selectedVerb} ${sanitizedUrl}`
});
const properties: { [key: string]: any } = {
ComponentName: componentName
}
if (sampleQuery) {
const sanitizedUrl = sanitizeQueryUrl(sampleQuery.sampleUrl);
properties.QuerySignature = `${sampleQuery.selectedVerb} ${sanitizedUrl}`;
}
telemetry.trackEvent(TAB_CLICK_EVENT, properties);
}

public trackLinkClickEvent(url: string, componentName: string) {
public trackLinkClickEvent(url: string, componentName: string) {
telemetry.trackEvent(LINK_CLICK_EVENT, { ComponentName: componentName });
validateExternalLink(url, componentName);
}
Expand Down