forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
65 lines (56 loc) · 1.81 KB
/
Copy pathindex.ts
File metadata and controls
65 lines (56 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { isFunction } from '@snowplow/browser-core';
import { Core, Plugin } from '@snowplow/tracker-core';
import isUndefined from 'lodash/isUndefined';
declare global {
interface MimeTypeArray {
[index: string]: MimeType;
}
}
const windowAlias = window,
navigatorAlias = navigator;
export const BrowserFeaturesPlugin = (): Plugin => {
return {
coreInit: (core: Core) => {
let mimeType,
pluginMap: Record<string, string> = {
// document types
pdf: 'application/pdf',
// media players
qt: 'video/quicktime',
realp: 'audio/x-pn-realaudio-plugin',
wma: 'application/x-mplayer2',
// interactive multimedia
dir: 'application/x-director',
fla: 'application/x-shockwave-flash',
// RIA
java: 'application/x-java-vm',
gears: 'application/x-googlegears',
ag: 'application/x-silverlight',
};
// General plugin detection
if (navigatorAlias.mimeTypes && navigatorAlias.mimeTypes.length) {
for (const i in pluginMap) {
if (Object.prototype.hasOwnProperty.call(pluginMap, i)) {
mimeType = navigatorAlias.mimeTypes[pluginMap[i]];
if (mimeType) {
core.addPayloadPair('f_' + i, mimeType.enabledPlugin ? '1' : '0');
}
}
}
}
// Safari and Opera
// IE6/IE7 navigator.javaEnabled can't be aliased, so test directly
if (
navigatorAlias.constructor === window.Navigator &&
!isUndefined(navigatorAlias.javaEnabled) &&
navigatorAlias.javaEnabled()
) {
core.addPayloadPair('f_java', '1');
}
// Firefox
if (isFunction((windowAlias as any).GearsFactory)) {
core.addPayloadPair('f_gears', '1');
}
},
};
};