Skip to content

Commit

Permalink
Include serviceName in tracked events from Search Form (#842)
Browse files Browse the repository at this point in the history
Signed-off-by: vvvprabhakar <prabhakar.vemparala@freshworks.com>

Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
  • Loading branch information
vvvprabhakar and yurishkuro committed Mar 4, 2022
1 parent b4b863b commit ce9368d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
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

0 comments on commit ce9368d

Please sign in to comment.