|
@@ -1,163 +0,0 @@
|
1
|
|
-/* global ga */
|
2
|
|
-
|
3
|
|
-(function(ctx) {
|
4
|
|
- /**
|
5
|
|
- *
|
6
|
|
- */
|
7
|
|
- function Analytics(options) {
|
8
|
|
- /* eslint-disable */
|
9
|
|
-
|
10
|
|
- if (!options.googleAnalyticsTrackingId) {
|
11
|
|
- console.log(
|
12
|
|
- 'Failed to initialize Google Analytics handler, no tracking ID');
|
13
|
|
- return;
|
14
|
|
- }
|
15
|
|
-
|
16
|
|
- /**
|
17
|
|
- * Google Analytics
|
18
|
|
- * TODO: Keep this local, there's no need to add it to window.
|
19
|
|
- */
|
20
|
|
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
21
|
|
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
22
|
|
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
23
|
|
- ga('create', options.googleAnalyticsTrackingId, 'auto');
|
24
|
|
- ga('send', 'pageview');
|
25
|
|
-
|
26
|
|
- /* eslint-enable */
|
27
|
|
- }
|
28
|
|
-
|
29
|
|
- /**
|
30
|
|
- * Extracts the integer to use for a Google Analytics event's value field
|
31
|
|
- * from a lib-jitsi-meet analytics event.
|
32
|
|
- * @param {Object} event - The lib-jitsi-meet analytics event.
|
33
|
|
- * @returns {Object} - The integer to use for the 'value' of a Google
|
34
|
|
- * Analytics event.
|
35
|
|
- * @private
|
36
|
|
- */
|
37
|
|
- Analytics.prototype._extractAction = function(event) {
|
38
|
|
- // Page events have a single 'name' field.
|
39
|
|
- if (event.type === 'page') {
|
40
|
|
- return event.name;
|
41
|
|
- }
|
42
|
|
-
|
43
|
|
- // All other events have action, actionSubject, and source fields. All
|
44
|
|
- // three fields are required, and the often jitsi-meet and
|
45
|
|
- // lib-jitsi-meet use the same value when separate values are not
|
46
|
|
- // necessary (i.e. event.action == event.actionSubject).
|
47
|
|
- // Here we concatenate these three fields, but avoid adding the same
|
48
|
|
- // value twice, because it would only make the GA event's action harder
|
49
|
|
- // to read.
|
50
|
|
- let action = event.action;
|
51
|
|
-
|
52
|
|
- if (event.actionSubject && event.actionSubject !== event.action) {
|
53
|
|
- // Intentionally use string concatenation as analytics needs to
|
54
|
|
- // work on IE but this file does not go through babel. For some
|
55
|
|
- // reason disabling this globally for the file does not have an
|
56
|
|
- // effect.
|
57
|
|
- // eslint-disable-next-line prefer-template
|
58
|
|
- action = event.actionSubject + '.' + action;
|
59
|
|
- }
|
60
|
|
- if (event.source && event.source !== event.action
|
61
|
|
- && event.source !== event.action) {
|
62
|
|
- // eslint-disable-next-line prefer-template
|
63
|
|
- action = event.source + '.' + action;
|
64
|
|
- }
|
65
|
|
-
|
66
|
|
- return action;
|
67
|
|
- };
|
68
|
|
-
|
69
|
|
- /**
|
70
|
|
- * Extracts the integer to use for a Google Analytics event's value field
|
71
|
|
- * from a lib-jitsi-meet analytics event.
|
72
|
|
- * @param {Object} event - The lib-jitsi-meet analytics event.
|
73
|
|
- * @returns {Object} - The integer to use for the 'value' of a Google
|
74
|
|
- * Analytics event, or NaN if the lib-jitsi-meet event doesn't contain a
|
75
|
|
- * suitable value.
|
76
|
|
- * @private
|
77
|
|
- */
|
78
|
|
- Analytics.prototype._extractValue = function(event) {
|
79
|
|
- let value = event && event.attributes && event.attributes.value;
|
80
|
|
-
|
81
|
|
- // Try to extract an integer from the "value" attribute.
|
82
|
|
- value = Math.round(parseFloat(value));
|
83
|
|
-
|
84
|
|
- return value;
|
85
|
|
- };
|
86
|
|
-
|
87
|
|
- /**
|
88
|
|
- * Extracts the string to use for a Google Analytics event's label field
|
89
|
|
- * from a lib-jitsi-meet analytics event.
|
90
|
|
- * @param {Object} event - The lib-jitsi-meet analytics event.
|
91
|
|
- * @returns {string} - The string to use for the 'label' of a Google
|
92
|
|
- * Analytics event.
|
93
|
|
- * @private
|
94
|
|
- */
|
95
|
|
- Analytics.prototype._extractLabel = function(event) {
|
96
|
|
- let label = '';
|
97
|
|
-
|
98
|
|
- // The label field is limited to 500B. We will concatenate all
|
99
|
|
- // attributes of the event, except the user agent because it may be
|
100
|
|
- // lengthy and is probably included from elsewhere.
|
101
|
|
- for (const property in event.attributes) {
|
102
|
|
- if (property !== 'permanent_user_agent'
|
103
|
|
- && property !== 'permanent_callstats_name'
|
104
|
|
- && event.attributes.hasOwnProperty(property)) {
|
105
|
|
- // eslint-disable-next-line prefer-template
|
106
|
|
- label += property + '=' + event.attributes[property] + '&';
|
107
|
|
- }
|
108
|
|
- }
|
109
|
|
-
|
110
|
|
- if (label.length > 0) {
|
111
|
|
- label = label.slice(0, -1);
|
112
|
|
- }
|
113
|
|
-
|
114
|
|
- return label;
|
115
|
|
- };
|
116
|
|
-
|
117
|
|
- /**
|
118
|
|
- * This is the entry point of the API. The function sends an event to
|
119
|
|
- * google analytics. The format of the event is described in
|
120
|
|
- * AnalyticsAdapter in lib-jitsi-meet.
|
121
|
|
- * @param {Object} event - the event in the format specified by
|
122
|
|
- * lib-jitsi-meet.
|
123
|
|
- */
|
124
|
|
- Analytics.prototype.sendEvent = function(event) {
|
125
|
|
- if (!event || !ga) {
|
126
|
|
- return;
|
127
|
|
- }
|
128
|
|
-
|
129
|
|
- const ignoredEvents
|
130
|
|
- = [ 'e2e_rtt', 'rtp.stats', 'rtt.by.region', 'available.device',
|
131
|
|
- 'stream.switch.delay', 'ice.state.changed', 'ice.duration' ];
|
132
|
|
-
|
133
|
|
- // Temporary removing some of the events that are too noisy.
|
134
|
|
- if (ignoredEvents.indexOf(event.action) !== -1) {
|
135
|
|
- return;
|
136
|
|
- }
|
137
|
|
-
|
138
|
|
- const gaEvent = {
|
139
|
|
- 'eventCategory': 'jitsi-meet',
|
140
|
|
- 'eventAction': this._extractAction(event),
|
141
|
|
- 'eventLabel': this._extractLabel(event)
|
142
|
|
- };
|
143
|
|
- const value = this._extractValue(event);
|
144
|
|
-
|
145
|
|
- if (!isNaN(value)) {
|
146
|
|
- gaEvent.eventValue = value;
|
147
|
|
- }
|
148
|
|
-
|
149
|
|
- ga('send', 'event', gaEvent);
|
150
|
|
- };
|
151
|
|
-
|
152
|
|
- if (typeof ctx.JitsiMeetJS === 'undefined') {
|
153
|
|
- ctx.JitsiMeetJS = {};
|
154
|
|
- }
|
155
|
|
- if (typeof ctx.JitsiMeetJS.app === 'undefined') {
|
156
|
|
- ctx.JitsiMeetJS.app = {};
|
157
|
|
- }
|
158
|
|
- if (typeof ctx.JitsiMeetJS.app.analyticsHandlers === 'undefined') {
|
159
|
|
- ctx.JitsiMeetJS.app.analyticsHandlers = [];
|
160
|
|
- }
|
161
|
|
- ctx.JitsiMeetJS.app.analyticsHandlers.push(Analytics);
|
162
|
|
-})(window);
|
163
|
|
-/* eslint-enable prefer-template */
|