Skip to content

Commit 3a7e2d9

Browse files
authored
Merge pull request guardian#3996 from guardian/rm/more-telemetry
Add telemetry to 'free only' and 'uploaded by me' filters
2 parents 6dbafdc + 9e24e2d commit 3a7e2d9

3 files changed

Lines changed: 52 additions & 17 deletions

File tree

kahuna/public/js/search/query.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {guDateRange} from '../components/gu-date-range/gu-date-range';
1111
import template from './query.html';
1212
import {syntax} from './syntax/syntax';
1313
import {grStructuredQuery} from './structured-query/structured-query';
14+
import { sendTelemetryForQuery } from '../services/telemetry';
1415

1516
export var query = angular.module('kahuna.search.query', [
1617
// Note: temporarily disabled for performance reasons, see above
@@ -180,6 +181,9 @@ query.controller('SearchQueryCtrl', [
180181
Object.assign(filter, {nonFree: newNonFree, uploadedByMe: false, uploadedBy: undefined});
181182
}
182183

184+
const { nonFree, uploadedByMe } = ctrl.filter;
185+
sendTelemetryForQuery(ctrl.filter.query, nonFree, uploadedByMe);
186+
183187
$state.go('search.results', filter);
184188
}));
185189

@@ -229,6 +233,9 @@ query.controller('SearchQueryCtrl', [
229233
function resetQuery() {
230234
ctrl.filter.query = undefined;
231235
}
236+
237+
const { nonFree, uploadedByMe } = ctrl.filter;
238+
sendTelemetryForQuery(ctrl.filter.query, nonFree, uploadedByMe);
232239
}]);
233240

234241
query.directive('searchQuery', [function() {

kahuna/public/js/search/structured-query/structured-query.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import angular from 'angular';
22
import Rx from 'rx';
3-
import { v4 } from 'uuid';
43

54
import './structured-query.css';
65

@@ -10,7 +9,6 @@ import {rxUtil} from '../../util/rx';
109

1110
import {querySuggestions, filterFields} from './query-suggestions';
1211
import {renderQuery, structureQuery} from './syntax';
13-
import { sendTelemetryEvent } from '../../services/telemetry';
1412

1513
export const grStructuredQuery = angular.module('gr.structuredQuery', [
1614
rxUtil.name,
@@ -69,21 +67,6 @@ grStructuredQuery.directive('grStructuredQuery', ['subscribe$', function(subscri
6967

7068
subscribe$(scope, ctrl.newQuery$, query => {
7169
ngModelCtrl.$setViewValue(query);
72-
const structuredQuery = structureQuery(query);
73-
const searchUuid = v4();
74-
structuredQuery.forEach(queryComponent => {
75-
// e.g. filter or search:
76-
// search > {type: 'text', value: 'my search'}
77-
// filter > {type: 'filter', filterType: 'inclusion', key: 'is', value: 'cool'}
78-
const { type } = queryComponent;
79-
const formattedType = (type) => {
80-
if (type === 'text') { return 'GRID_SEARCH'; }
81-
if (type === 'filter') { return 'GRID_FILTER'; }
82-
return `GRID_${type.toUpperCase()}`;
83-
};
84-
// In case search is empty, as with a search containing only filters
85-
sendTelemetryEvent(formattedType(type), {...queryComponent, searchUuid: searchUuid}, 1);
86-
});
8770
});
8871
}
8972
};

kahuna/public/js/services/telemetry.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {UserTelemetryEventSender, IUserTelemetryEvent} from '@guardian/user-telemetry-client';
22
import { v4 } from 'uuid';
3+
import { structureQuery } from '../search/structured-query/syntax';
34

45
const getStoredId = (storage: Storage, key: string): string => {
56
const maybeId = storage.getItem(key);
@@ -37,3 +38,47 @@ export const sendTelemetryEvent = (type: string, tags?: IUserTelemetryEvent["tag
3738
tags: {...tags, browserUuid: getBrowserId(), sessionUuid: getSessionId()}
3839
});
3940
};
41+
42+
const sendFilterTelemetryEvent = (key: string, value: string, searchUuid: string) => {
43+
sendTelemetryEvent('GRID_FILTER', {
44+
type: 'filter',
45+
filterType: 'inclusion',
46+
key: key,
47+
value: value,
48+
searchUuid: searchUuid
49+
}, 1);
50+
};
51+
52+
export const sendTelemetryForQuery = (query: string, nonFree?: boolean | string, uploadedByMe?: boolean ) => {
53+
const structuredQuery = structureQuery(query);
54+
const searchUuid = v4();
55+
// nonFree is unfortunately either a boolean, stringified boolean, or undefined
56+
const freeToUseOnly = (!(nonFree === 'true' || nonFree === true));
57+
const uploadedByMeOnly = (uploadedByMe);
58+
59+
// Only log for true - matching how these filters work in Grid (only applied when true)
60+
if (freeToUseOnly) {
61+
sendFilterTelemetryEvent('freeToUseOnly', 'true', searchUuid);
62+
}
63+
if (uploadedByMeOnly) {
64+
sendFilterTelemetryEvent('uploadedByMeOnly', 'true', searchUuid);
65+
}
66+
67+
structuredQuery.forEach(queryComponent => {
68+
// e.g. filter or search:
69+
// search > {type: 'text', value: 'my search'}
70+
// filter > {type: 'filter', filterType: 'inclusion', key: 'is', value: 'cool'}
71+
const { type } = queryComponent;
72+
const formattedType = (type: string) => {
73+
if (type === 'text') { return 'GRID_SEARCH'; }
74+
if (type === 'filter') { return 'GRID_FILTER'; }
75+
return `GRID_${type.toUpperCase()}`;
76+
};
77+
78+
// In case search is empty, as with a search containing only filters
79+
sendTelemetryEvent(formattedType(type), {
80+
...queryComponent,
81+
searchUuid: searchUuid
82+
}, 1);
83+
});
84+
};

0 commit comments

Comments
 (0)