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

Track Event for Service Name in Search Form #842

Merged
merged 5 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export function submitForm(fields, searchTraces) {
end = times.end;
}

trackFormInput(resultsLimit, operation, tags, minDuration, maxDuration, lookback);
trackFormInput(resultsLimit, operation, tags, minDuration, maxDuration, lookback, service);

searchTraces({
service,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
CATEGORY_OPERATION,
CATEGORY_SORTBY,
CATEGORY_TAGS,
CATEGORY_SERVICE,
} from './SearchForm.track';
import { FORM_CHANGE_ACTION_TYPE } from '../../constants/search-form';
import { trackEvent } from '../../utils/tracking';
Expand All @@ -39,8 +40,8 @@ describe('GA tracking', () => {

it('sends form input to GA', () => {
trackEvent.mockClear();
trackFormInput(0, '', {}, 0, 0, '');
expect(trackEvent.mock.calls.length).toBe(6);
trackFormInput(0, '', {}, 0, 0, '', '');
expect(trackEvent.mock.calls.length).toBe(7);
const categoriesTracked = trackEvent.mock.calls.map(call => call[0]).sort();
expect(categoriesTracked).toEqual(
[
Expand All @@ -50,6 +51,7 @@ describe('GA tracking', () => {
CATEGORY_MAX_DURATION,
CATEGORY_MIN_DURATION,
CATEGORY_LOOKBACK,
CATEGORY_SERVICE,
].sort()
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,23 @@ export const CATEGORY_TAGS = `${FORM_CATEGORY_BASE}/tags`;
export const CATEGORY_MIN_DURATION = `${FORM_CATEGORY_BASE}/min_duration`;
export const CATEGORY_MAX_DURATION = `${FORM_CATEGORY_BASE}/max_duration`;
export const CATEGORY_LIMIT = `${FORM_CATEGORY_BASE}/limit`;

export const CATEGORY_SERVICE = `${FORM_CATEGORY_BASE}/serviceName`;
export function trackFormInput(
resultsLimit: number,
operation: string,
tags: any,
minDuration: number,
maxDuration: number,
lookback: string
lookback: string,
serviceName: string
) {
trackEvent(CATEGORY_OPERATION, operation === constants.DEFAULT_OPERATION ? ACTION_DEFAULT : ACTION_SET);
trackEvent(CATEGORY_LIMIT, resultsLimit === constants.DEFAULT_LIMIT ? ACTION_DEFAULT : ACTION_SET);
trackEvent(CATEGORY_MAX_DURATION, maxDuration ? ACTION_SET : ACTION_CLEAR);
trackEvent(CATEGORY_MIN_DURATION, minDuration ? ACTION_SET : ACTION_CLEAR);
trackEvent(CATEGORY_TAGS, tags ? ACTION_SET : ACTION_CLEAR);
trackEvent(CATEGORY_LOOKBACK, lookback);
trackEvent(CATEGORY_SERVICE, serviceName);
}

export const middlewareHooks = {
Expand Down