typeahead-client-logger 0.0.1-security → 2.532.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of typeahead-client-logger might be problematic. Click here for more details.
- package/LICENSE +21 -0
- package/README.md +23 -3
- package/build.js +128 -0
- package/dist/ClientMetricsLogger.js +69 -0
- package/dist/EssClientLogger.js +127 -0
- package/dist/EssSelectedSuggestionLogger.js +372 -0
- package/dist/Experiments.js +52 -0
- package/dist/InteractionMetrics.js +73 -0
- package/dist/PerformanceMetrics.js +212 -0
- package/dist/RecommendationEvent.js +122 -0
- package/dist/SystemEvent.js +31 -0
- package/dist/TypeaheadEvent.js +345 -0
- package/dist/TypeaheadEventLogger.js +429 -0
- package/dist/index.js +15 -0
- package/dist/utils/Optional.js +45 -0
- package/dist/utils/Utils.js +88 -0
- package/package.json +19 -3
@@ -0,0 +1,345 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TypeaheadEvent = exports.EventName = void 0;
|
4
|
+
var Utils_1 = require("./utils/Utils");
|
5
|
+
var EventName;
|
6
|
+
(function (EventName) {
|
7
|
+
EventName["FOCUS"] = "typeaheadFocused";
|
8
|
+
EventName["BLUR"] = "typeaheadBlurred";
|
9
|
+
EventName["SELECT"] = "typeaheadSuggestionSelected";
|
10
|
+
EventName["CURRENT_LOCATION"] = "currentLocation";
|
11
|
+
})((EventName = exports.EventName || (exports.EventName = {})));
|
12
|
+
var EventType;
|
13
|
+
(function (EventType) {
|
14
|
+
EventType["TYPEAHEAD_INTERACTION"] = "typeaheadInteraction";
|
15
|
+
})(EventType || (EventType = {}));
|
16
|
+
var SearchField;
|
17
|
+
(function (SearchField) {
|
18
|
+
SearchField["O"] = "Origin";
|
19
|
+
SearchField["D"] = "Destination";
|
20
|
+
SearchField["U"] = "UNKNOWN";
|
21
|
+
})(SearchField || (SearchField = {}));
|
22
|
+
var SourceSystem;
|
23
|
+
(function (SourceSystem) {
|
24
|
+
SourceSystem["GAIA"] = "GAIA";
|
25
|
+
SourceSystem["LCM"] = "LCM";
|
26
|
+
SourceSystem["GOOGLE"] = "GOOGLE";
|
27
|
+
SourceSystem["UNKNOWN"] = "UNKNOWN";
|
28
|
+
})(SourceSystem || (SourceSystem = {}));
|
29
|
+
var SuggestionType;
|
30
|
+
(function (SuggestionType) {
|
31
|
+
SuggestionType["ALTERNATE"] = "Alternate";
|
32
|
+
SuggestionType["CURRENT_LOCATION"] = "CurrentLocation";
|
33
|
+
SuggestionType["POPULAR"] = "Popular";
|
34
|
+
SuggestionType["GOOGLE"] = "Google";
|
35
|
+
SuggestionType["NORMAL"] = "Normal";
|
36
|
+
SuggestionType["RECENT_HISTORY"] = "RecentHistory";
|
37
|
+
})(SuggestionType || (SuggestionType = {}));
|
38
|
+
// tslint:disable-next-line:max-line-length
|
39
|
+
|
40
|
+
var TypeaheadEvent = /** @class */ (function () {
|
41
|
+
function TypeaheadEvent(eventName, session) {
|
42
|
+
var _a, _b;
|
43
|
+
var isCurrLoc = EventName.CURRENT_LOCATION === eventName;
|
44
|
+
if (isCurrLoc) {
|
45
|
+
eventName = EventName.SELECT;
|
46
|
+
}
|
47
|
+
this.typeaheadEvent = {
|
48
|
+
event: {
|
49
|
+
name: eventName,
|
50
|
+
type: EventType.TYPEAHEAD_INTERACTION,
|
51
|
+
},
|
52
|
+
numberOfBackspaces: session.noOfBackspaces,
|
53
|
+
page: {
|
54
|
+
actionLocation: session.fieldName,
|
55
|
+
lineOfBusiness:
|
56
|
+
session.metadata.lob +
|
57
|
+
this.getSublob(session.metadata.lob, session.metadata.subLob),
|
58
|
+
pageName: this.getPageName(session.metadata.client || "", session.href),
|
59
|
+
},
|
60
|
+
searchField: this.getSearchField(session.fieldName),
|
61
|
+
searchFieldContent:
|
62
|
+
EventName.FOCUS === eventName
|
63
|
+
? ((_a = session.input) === null || _a === void 0
|
64
|
+
? void 0
|
65
|
+
: _a.value) || ""
|
66
|
+
: session.query === session.prefill
|
67
|
+
? ""
|
68
|
+
: session.query || "",
|
69
|
+
timestamps: {
|
70
|
+
receivedAt: Date.now(),
|
71
|
+
},
|
72
|
+
};
|
73
|
+
if (EventName.FOCUS === eventName) {
|
74
|
+
// we are setting the initial time stamp when user first interacts with typeahead input box
|
75
|
+
session.isResolve = false;
|
76
|
+
session.focusTime = new Date().toString();
|
77
|
+
}
|
78
|
+
if ([EventName.SELECT, EventName.BLUR].indexOf(eventName) > -1) {
|
79
|
+
if (session.response) {
|
80
|
+
this.setSuggestionShownFields(session.response);
|
81
|
+
}
|
82
|
+
if (session.selected) {
|
83
|
+
if (EventName.BLUR === eventName) {
|
84
|
+
this.typeaheadEvent.typeaheadSelection = true;
|
85
|
+
this.typeaheadEvent.charactersTyped =
|
86
|
+
this.typeaheadEvent.searchFieldContent.length;
|
87
|
+
this.calculateTimeSpendOnTypeaheadInput(session);
|
88
|
+
}
|
89
|
+
this.setSuggestionSelectedFields(session.selected);
|
90
|
+
}
|
91
|
+
if (session.selected === undefined && EventName.BLUR === eventName) {
|
92
|
+
this.calculateTimeSpendOnTypeaheadInput(session);
|
93
|
+
this.typeaheadEvent.typeaheadSelection = false;
|
94
|
+
this.typeaheadEvent.charactersTyped =
|
95
|
+
this.typeaheadEvent.searchFieldContent.length;
|
96
|
+
var input =
|
97
|
+
(_b = document.getElementsByName("regionId")) === null ||
|
98
|
+
_b === void 0
|
99
|
+
? void 0
|
100
|
+
: _b.item(0);
|
101
|
+
var regionId =
|
102
|
+
(input === null || input === void 0 ? void 0 : input.value) ||
|
103
|
+
"UNKNOWN";
|
104
|
+
this.typeaheadEvent.searchDestination = {
|
105
|
+
id: session.isResolve ? "UNKNOWN" : regionId,
|
106
|
+
sourceSystem: "UNKNOWN",
|
107
|
+
fullName: session.isResolve ? session.query : session.prefill || "",
|
108
|
+
};
|
109
|
+
}
|
110
|
+
if (isCurrLoc) {
|
111
|
+
this.setCurrentLocationSelectedFields();
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
TypeaheadEvent.prototype.getTypeaheadEventMessage = function () {
|
116
|
+
return {
|
117
|
+
messageContent: this.typeaheadEvent,
|
118
|
+
schemaName: "typeahead",
|
119
|
+
};
|
120
|
+
};
|
121
|
+
TypeaheadEvent.prototype.getFlattenedJsonMessage = function () {
|
122
|
+
var _a, _b, _c;
|
123
|
+
return {
|
124
|
+
"ta.page.actionLocation": this.typeaheadEvent.page.actionLocation,
|
125
|
+
"ta.page.lob": this.typeaheadEvent.page.lineOfBusiness,
|
126
|
+
"ta.page.name": this.typeaheadEvent.page.pageName,
|
127
|
+
"ta.searchField": this.typeaheadEvent.searchField,
|
128
|
+
"ta.searchFieldContent": this.typeaheadEvent.searchFieldContent,
|
129
|
+
"ta.timestamps.receivedAt": this.typeaheadEvent.timestamps.receivedAt,
|
130
|
+
"ta.noOfSuggestions": this.typeaheadEvent.noOfSuggestions,
|
131
|
+
"ta.requestId": this.typeaheadEvent.serviceRequestLogId,
|
132
|
+
"ta.suggestionType": this.typeaheadEvent.suggestionType,
|
133
|
+
"ta.searchDestination":
|
134
|
+
((_a = this.typeaheadEvent.searchDestination) === null || _a === void 0
|
135
|
+
? void 0
|
136
|
+
: _a.sourceSystem) +
|
137
|
+
":" +
|
138
|
+
((_b = this.typeaheadEvent.searchDestination) === null || _b === void 0
|
139
|
+
? void 0
|
140
|
+
: _b.id),
|
141
|
+
"ta.selectionDepth": this.typeaheadEvent.selectionDepth,
|
142
|
+
"ta.suggestionList":
|
143
|
+
(_c = this.typeaheadEvent.suggestionList) === null || _c === void 0
|
144
|
+
? void 0
|
145
|
+
: _c
|
146
|
+
.map(function (s) {
|
147
|
+
return s.sourceSystem + ":" + s.id;
|
148
|
+
})
|
149
|
+
.join(","),
|
150
|
+
};
|
151
|
+
};
|
152
|
+
TypeaheadEvent.prototype.setSuggestionShownFields = function (response) {
|
153
|
+
this.typeaheadEvent.noOfSuggestions = response.sr.length;
|
154
|
+
this.typeaheadEvent.serviceRequestLogId = response.rid;
|
155
|
+
if (response.sr && response.sr.length) {
|
156
|
+
this.typeaheadEvent.suggestionType = this.getSuggestionType(
|
157
|
+
response.sr[0].category
|
158
|
+
);
|
159
|
+
this.typeaheadEvent.suggestionList = this.getSuggestionList(response.sr);
|
160
|
+
}
|
161
|
+
};
|
162
|
+
TypeaheadEvent.prototype.setSuggestionSelectedFields = function (selected) {
|
163
|
+
this.typeaheadEvent.suggestionType = this.getSuggestionType(
|
164
|
+
selected.category
|
165
|
+
);
|
166
|
+
this.typeaheadEvent.searchDestination = this.getGeoEntity(selected);
|
167
|
+
this.typeaheadEvent.selectionDepth = parseInt(selected.index, 10);
|
168
|
+
if (selected && selected.displayType !== "CATEGORIZED")
|
169
|
+
this.typeaheadEvent.selectionDepth += 1;
|
170
|
+
};
|
171
|
+
TypeaheadEvent.prototype.setCurrentLocationSelectedFields = function () {
|
172
|
+
this.typeaheadEvent.suggestionType = SuggestionType.CURRENT_LOCATION;
|
173
|
+
this.typeaheadEvent.typeaheadSelection = true;
|
174
|
+
this.typeaheadEvent.searchDestination = {
|
175
|
+
fullName: "CurrentLocation",
|
176
|
+
id: "",
|
177
|
+
type: SuggestionType.CURRENT_LOCATION,
|
178
|
+
};
|
179
|
+
this.typeaheadEvent.selectionDepth = 1;
|
180
|
+
};
|
181
|
+
TypeaheadEvent.prototype.getSearchField = function (domElementId) {
|
182
|
+
if (!domElementId) {
|
183
|
+
return SearchField.U;
|
184
|
+
}
|
185
|
+
return Utils_1.Utils.isOrigin(domElementId)
|
186
|
+
? SearchField.O
|
187
|
+
: Utils_1.Utils.isDestination(domElementId)
|
188
|
+
? SearchField.D
|
189
|
+
: SearchField.U;
|
190
|
+
};
|
191
|
+
TypeaheadEvent.prototype.getGeoEntity = function (selected) {
|
192
|
+
return {
|
193
|
+
fullName: selected.regionNames.lastSearchName,
|
194
|
+
id: this.getSourceId(selected),
|
195
|
+
shortName: selected.regionNames.shortName,
|
196
|
+
sourceSystem: this.getSourceSystem(selected),
|
197
|
+
type: selected.type,
|
198
|
+
};
|
199
|
+
};
|
200
|
+
TypeaheadEvent.prototype.getSourceId = function (s) {
|
201
|
+
var _a;
|
202
|
+
return (
|
203
|
+
s.sourceId ||
|
204
|
+
((_a = s.essId) === null || _a === void 0 ? void 0 : _a.sourceId) ||
|
205
|
+
s.hotelId ||
|
206
|
+
s.gaiaId ||
|
207
|
+
Utils_1.Utils.UNKNOWN
|
208
|
+
);
|
209
|
+
};
|
210
|
+
TypeaheadEvent.prototype.getSourceSystem = function (s) {
|
211
|
+
var _a;
|
212
|
+
var sourceName =
|
213
|
+
s.sourceName ||
|
214
|
+
((_a = s.essId) === null || _a === void 0 ? void 0 : _a.sourceName) ||
|
215
|
+
(s.hotelId ? "LCM" : s.gaiaId ? "GAI" : "");
|
216
|
+
switch (sourceName) {
|
217
|
+
case "GAI":
|
218
|
+
return SourceSystem.GAIA;
|
219
|
+
case "LCM":
|
220
|
+
return SourceSystem.LCM;
|
221
|
+
case "GPA":
|
222
|
+
return SourceSystem.GOOGLE;
|
223
|
+
default:
|
224
|
+
return sourceName || SourceSystem.UNKNOWN;
|
225
|
+
}
|
226
|
+
};
|
227
|
+
TypeaheadEvent.prototype.getSuggestionType = function (category) {
|
228
|
+
switch (category) {
|
229
|
+
case "GOOGLEMAPS":
|
230
|
+
return SuggestionType.GOOGLE;
|
231
|
+
case "USERHISTORY":
|
232
|
+
return SuggestionType.RECENT_HISTORY;
|
233
|
+
case "ALTERNATE":
|
234
|
+
return SuggestionType.ALTERNATE;
|
235
|
+
case "POPULAR":
|
236
|
+
return SuggestionType.POPULAR;
|
237
|
+
case "CURRENTLOCATION":
|
238
|
+
return SuggestionType.CURRENT_LOCATION;
|
239
|
+
default:
|
240
|
+
return SuggestionType.NORMAL;
|
241
|
+
}
|
242
|
+
};
|
243
|
+
TypeaheadEvent.prototype.getSuggestionList = function (suggestions) {
|
244
|
+
var _this = this;
|
245
|
+
return suggestions.map(function (s) {
|
246
|
+
var suggId = {
|
247
|
+
id: _this.getSourceId(s),
|
248
|
+
sourceSystem: _this.getSourceSystem(s),
|
249
|
+
type: s.type,
|
250
|
+
};
|
251
|
+
if (
|
252
|
+
s.hierarchyInfo &&
|
253
|
+
s.hierarchyInfo.relation &&
|
254
|
+
s.hierarchyInfo.relation.length
|
255
|
+
) {
|
256
|
+
suggId.reason = s.hierarchyInfo.relation[0];
|
257
|
+
}
|
258
|
+
return suggId;
|
259
|
+
});
|
260
|
+
};
|
261
|
+
TypeaheadEvent.prototype.getSublob = function (lob, sublob) {
|
262
|
+
sublob = Utils_1.Utils.getSubLob(lob, sublob);
|
263
|
+
return sublob ? "." + sublob : "";
|
264
|
+
};
|
265
|
+
TypeaheadEvent.prototype.getPageName = function (client, href) {
|
266
|
+
/* Cases:
|
267
|
+
Case 1: If Client = Homepage,
|
268
|
+
then check for Href because currently we are getting Client=Homepage for landing page as well
|
269
|
+
Case 2: If Client is not Homepage
|
270
|
+
then we first deduce the page name with client if found UNKNOWN then we use Href
|
271
|
+
Case 3: If Client is not present,
|
272
|
+
then check the Href if it belongs to HomePage then resolve otherwise check for other possibility
|
273
|
+
Case 4: If client is not Homepage but the href is of Homepage(Special Case)
|
274
|
+
*/
|
275
|
+
href = href.toLowerCase();
|
276
|
+
client = client.toLowerCase();
|
277
|
+
if (client && !(client.indexOf("homepage") !== -1)) {
|
278
|
+
var pageName = this.checkIfHomepage(href)
|
279
|
+
? "Homepage"
|
280
|
+
: this.findPageName(client);
|
281
|
+
return pageName.indexOf("UNKNOWN") !== -1
|
282
|
+
? this.findPageName(href)
|
283
|
+
: pageName;
|
284
|
+
} else {
|
285
|
+
return this.checkIfHomepage(href) ? "Homepage" : this.findPageName(href);
|
286
|
+
}
|
287
|
+
};
|
288
|
+
TypeaheadEvent.prototype.checkIfHomepage = function (href) {
|
289
|
+
// RegExp for homePage
|
290
|
+
// Match with https://www.expedia.co.in/ , https://www.travelocity.com/ and similar hrefs
|
291
|
+
var regex = new RegExp(
|
292
|
+
"^(https:\\/\\/)[a-zA-Z]{2,}\\.[a-zA-Z0-9]{1,61}\\.[a-zA-Z.]{2,}((\\/\\?)|\\/$)"
|
293
|
+
);
|
294
|
+
return regex.test(href);
|
295
|
+
};
|
296
|
+
TypeaheadEvent.prototype.findPageName = function (pageName) {
|
297
|
+
if (
|
298
|
+
pageName.indexOf("package") !== -1 ||
|
299
|
+
pageName.indexOf("packagetype") !== -1
|
300
|
+
) {
|
301
|
+
return this.returnPageName("Packages", pageName);
|
302
|
+
}
|
303
|
+
if (pageName.indexOf("flight") !== -1) {
|
304
|
+
return this.returnPageName("Flights", pageName);
|
305
|
+
}
|
306
|
+
if (pageName.indexOf("hotel") !== -1) {
|
307
|
+
return this.returnPageName("Hotels", pageName);
|
308
|
+
}
|
309
|
+
if (pageName.indexOf("car") !== -1) {
|
310
|
+
return this.returnPageName("Cars", pageName);
|
311
|
+
}
|
312
|
+
if (
|
313
|
+
pageName.indexOf("lx") !== -1 ||
|
314
|
+
pageName.indexOf("activities") !== -1 ||
|
315
|
+
pageName.indexOf("things-to-do") !== -1
|
316
|
+
) {
|
317
|
+
return this.returnPageName("Activities", pageName);
|
318
|
+
}
|
319
|
+
if (pageName.indexOf("rail") !== -1) {
|
320
|
+
return this.returnPageName("Rails", pageName);
|
321
|
+
}
|
322
|
+
return "UNKNOWN";
|
323
|
+
};
|
324
|
+
TypeaheadEvent.prototype.returnPageName = function (name, pathName) {
|
325
|
+
if (pathName.indexOf("search") !== -1) {
|
326
|
+
return name + ".Search";
|
327
|
+
}
|
328
|
+
return name + "LandingPage";
|
329
|
+
};
|
330
|
+
/*
|
331
|
+
This method is used to calculate the time spent by user on typeahead input box
|
332
|
+
It first calculate the timestamp and store it in case of blur event only.
|
333
|
+
*/
|
334
|
+
TypeaheadEvent.prototype.calculateTimeSpendOnTypeaheadInput = function (
|
335
|
+
session
|
336
|
+
) {
|
337
|
+
// @ts-ignore
|
338
|
+
var focus = session.focusTime;
|
339
|
+
this.typeaheadEvent.timestamps.timeFromFocusToBlur =
|
340
|
+
new Date().getTime() - new Date(focus).getTime();
|
341
|
+
};
|
342
|
+
return TypeaheadEvent;
|
343
|
+
})();
|
344
|
+
exports.TypeaheadEvent = TypeaheadEvent;
|
345
|
+
//# sourceMappingURL=TypeaheadEvent.js.map
|