Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 12966d0

Browse files
authored
Merge pull request #1255 from matrix-org/t3chguy/i18n_analytics
un-i18n Modal Analytics
2 parents d3ba1f4 + 41843f0 commit 12966d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+163
-160
lines changed

src/Analytics.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import { getCurrentLanguage } from './languageHandler';
18-
import MatrixClientPeg from './MatrixClientPeg';
1918
import PlatformPeg from './PlatformPeg';
2019
import SdkConfig from './SdkConfig';
2120

@@ -32,8 +31,17 @@ const customVariables = {
3231
'Chosen Language': 4,
3332
'Instance': 5,
3433
'RTE: Uses Richtext Mode': 6,
34+
'Homeserver URL': 7,
35+
'Identity Server URL': 8,
3536
};
3637

38+
function whitelistRedact(whitelist, str) {
39+
if (whitelist.includes(str)) return str;
40+
return '<redacted>';
41+
}
42+
43+
const whitelistedHSUrls = ["https://matrix.org"];
44+
const whitelistedISUrls = ["https://vector.im"];
3745

3846
class Analytics {
3947
constructor() {
@@ -77,7 +85,7 @@ class Analytics {
7785
this._paq.push(['trackAllContentImpressions']);
7886
this._paq.push(['discardHashTag', false]);
7987
this._paq.push(['enableHeartBeatTimer']);
80-
this._paq.push(['enableLinkTracking', true]);
88+
// this._paq.push(['enableLinkTracking', true]);
8189

8290
const platform = PlatformPeg.get();
8391
this._setVisitVariable('App Platform', platform.getHumanReadableName());
@@ -131,20 +139,15 @@ class Analytics {
131139
this._paq.push(['deleteCookies']);
132140
}
133141

134-
login() { // not used currently
135-
const cli = MatrixClientPeg.get();
136-
if (this.disabled || !cli) return;
137-
138-
this._paq.push(['setUserId', `@${cli.getUserIdLocalpart()}:${cli.getDomain()}`]);
139-
}
140-
141142
_setVisitVariable(key, value) {
142143
this._paq.push(['setCustomVariable', customVariables[key], key, value, 'visit']);
143144
}
144145

145-
setGuest(guest) {
146+
setLoggedIn(isGuest, homeserverUrl, identityServerUrl) {
146147
if (this.disabled) return;
147-
this._setVisitVariable('User Type', guest ? 'Guest' : 'Logged In');
148+
this._setVisitVariable('User Type', isGuest ? 'Guest' : 'Logged In');
149+
this._setVisitVariable('Homeserver URL', whitelistRedact(whitelistedHSUrls, homeserverUrl));
150+
this._setVisitVariable('Identity Server URL', whitelistRedact(whitelistedISUrls, identityServerUrl));
148151
}
149152

150153
setRichtextMode(state) {

src/CallHandler.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function _setCallListeners(call) {
143143
pause("ringbackAudio");
144144
play("busyAudio");
145145
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
146-
Modal.createDialog(ErrorDialog, {
146+
Modal.createTrackedDialog('Call Handler', 'Call Timeout', ErrorDialog, {
147147
title: _t('Call Timeout'),
148148
description: _t('The remote side failed to pick up') + '.',
149149
});
@@ -205,7 +205,7 @@ function _onAction(payload) {
205205
_setCallState(undefined, newCall.roomId, "ended");
206206
console.log("Can't capture screen: " + screenCapErrorString);
207207
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
208-
Modal.createDialog(ErrorDialog, {
208+
Modal.createTrackedDialog('Call Handler', 'Unable to capture screen', ErrorDialog, {
209209
title: _t('Unable to capture screen'),
210210
description: screenCapErrorString,
211211
});
@@ -225,7 +225,7 @@ function _onAction(payload) {
225225
case 'place_call':
226226
if (module.exports.getAnyActiveCall()) {
227227
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
228-
Modal.createDialog(ErrorDialog, {
228+
Modal.createTrackedDialog('Call Handler', 'Existing Call', ErrorDialog, {
229229
title: _t('Existing Call'),
230230
description: _t('You are already in a call.'),
231231
});
@@ -235,7 +235,7 @@ function _onAction(payload) {
235235
// if the runtime env doesn't do VoIP, whine.
236236
if (!MatrixClientPeg.get().supportsVoip()) {
237237
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
238-
Modal.createDialog(ErrorDialog, {
238+
Modal.createTrackedDialog('Call Handler', 'VoIP is unsupported', ErrorDialog, {
239239
title: _t('VoIP is unsupported'),
240240
description: _t('You cannot place VoIP calls in this browser.'),
241241
});
@@ -251,7 +251,7 @@ function _onAction(payload) {
251251
var members = room.getJoinedMembers();
252252
if (members.length <= 1) {
253253
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
254-
Modal.createDialog(ErrorDialog, {
254+
Modal.createTrackedDialog('Call Handler', 'Cannot place call with self', ErrorDialog, {
255255
description: _t('You cannot place a call with yourself.'),
256256
});
257257
return;
@@ -277,13 +277,13 @@ function _onAction(payload) {
277277
console.log("Place conference call in %s", payload.room_id);
278278
if (!ConferenceHandler) {
279279
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
280-
Modal.createDialog(ErrorDialog, {
280+
Modal.createTrackedDialog('Call Handler', 'Conference call unsupported client', ErrorDialog, {
281281
description: _t('Conference calls are not supported in this client'),
282282
});
283283
}
284284
else if (!MatrixClientPeg.get().supportsVoip()) {
285285
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
286-
Modal.createDialog(ErrorDialog, {
286+
Modal.createTrackedDialog('Call Handler', 'VoIP is unsupported', ErrorDialog, {
287287
title: _t('VoIP is unsupported'),
288288
description: _t('You cannot place VoIP calls in this browser.'),
289289
});
@@ -296,13 +296,13 @@ function _onAction(payload) {
296296
// participant.
297297
// Therefore we disable conference calling in E2E rooms.
298298
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
299-
Modal.createDialog(ErrorDialog, {
299+
Modal.createTrackedDialog('Call Handler', 'Conference calls unsupported e2e', ErrorDialog, {
300300
description: _t('Conference calls are not supported in encrypted rooms'),
301301
});
302302
}
303303
else {
304304
var QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
305-
Modal.createDialog(QuestionDialog, {
305+
Modal.createTrackedDialog('Call Handler', 'Conference calling in development', QuestionDialog, {
306306
title: _t('Warning!'),
307307
description: _t('Conference calling is in development and may not be reliable.'),
308308
onFinished: confirm=>{
@@ -314,7 +314,7 @@ function _onAction(payload) {
314314
}, function(err) {
315315
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
316316
console.error("Conference call failed: " + err);
317-
Modal.createDialog(ErrorDialog, {
317+
Modal.createTrackedDialog('Call Handler', 'Failed to set up conference call', ErrorDialog, {
318318
title: _t('Failed to set up conference call'),
319319
description: _t('Conference call failed.') + ' ' + ((err && err.message) ? err.message : ''),
320320
});

src/ContentMessages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ class ContentMessages {
360360
desc = _t('The file \'%(fileName)s\' exceeds this home server\'s size limit for uploads', {fileName: upload.fileName});
361361
}
362362
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
363-
Modal.createDialog(ErrorDialog, {
363+
Modal.createTrackedDialog('Upload failed', '', ErrorDialog, {
364364
title: _t('Upload Failed'),
365365
description: desc,
366366
});

src/KeyRequestHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export default class KeyRequestHandler {
125125
};
126126

127127
const KeyShareDialog = sdk.getComponent("dialogs.KeyShareDialog");
128-
Modal.createDialog(KeyShareDialog, {
128+
Modal.createTrackedDialog('Key Share', 'Process Next Request', KeyShareDialog, {
129129
matrixClient: this._matrixClient,
130130
userId: userId,
131131
deviceId: deviceId,

src/Lifecycle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ function _handleRestoreFailure(e) {
240240
const SessionRestoreErrorDialog =
241241
sdk.getComponent('views.dialogs.SessionRestoreErrorDialog');
242242

243-
Modal.createDialog(SessionRestoreErrorDialog, {
243+
Modal.createTrackedDialog('Session Restore Error', '', SessionRestoreErrorDialog, {
244244
error: e.message,
245245
onFinished: (success) => {
246246
def.resolve(success);
@@ -318,7 +318,7 @@ async function _doSetLoggedIn(credentials, clearStorage) {
318318
await _clearStorage();
319319
}
320320

321-
Analytics.setGuest(credentials.guest);
321+
Analytics.setLoggedIn(credentials.guest, credentials.homeserverUrl, credentials.identityServerUrl);
322322

323323
// Resolves by default
324324
let teamPromise = Promise.resolve(null);

src/Modal.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,20 @@ class ModalManager {
103103
return container;
104104
}
105105

106+
createTrackedDialog(analyticsAction, analyticsInfo, Element, props, className) {
107+
Analytics.trackEvent('Modal', analyticsAction, analyticsInfo);
108+
return this.createDialog(Element, props, className);
109+
}
110+
106111
createDialog(Element, props, className) {
107-
if (props && props.title) {
108-
Analytics.trackEvent('Modal', props.title, 'createDialog');
109-
}
110112
return this.createDialogAsync((cb) => {cb(Element);}, props, className);
111113
}
112114

115+
createTrackedDialogAsync(analyticsId, loader, props, className) {
116+
Analytics.trackEvent('Modal', analyticsId);
117+
return this.createDialogAsync(loader, props, className);
118+
}
119+
113120
/**
114121
* Open a modal view.
115122
*

src/Notifier.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const Notifier = {
142142
? _t('Riot does not have permission to send you notifications - please check your browser settings')
143143
: _t('Riot was not given permission to send notifications - please try again');
144144
const ErrorDialog = sdk.getComponent('dialogs.ErrorDialog');
145-
Modal.createDialog(ErrorDialog, {
145+
Modal.createTrackedDialog('Unable to enable Notifications', result, ErrorDialog, {
146146
title: _t('Unable to enable Notifications'),
147147
description,
148148
});

src/SlashCommands.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const commands = {
6868
ddg: new Command("ddg", "<query>", function(roomId, args) {
6969
const ErrorDialog = sdk.getComponent('dialogs.ErrorDialog');
7070
// TODO Don't explain this away, actually show a search UI here.
71-
Modal.createDialog(ErrorDialog, {
71+
Modal.createTrackedDialog('Slash Commands', '/ddg is not a command', ErrorDialog, {
7272
title: _t('/ddg is not a command'),
7373
description: _t('To use it, just wait for autocomplete results to load and tab through them.'),
7474
});
@@ -326,13 +326,11 @@ const commands = {
326326
{deviceId: deviceId, fprint: fprint, userId: userId, fingerprint: fingerprint}));
327327
}
328328

329-
return MatrixClientPeg.get().setDeviceVerified(
330-
userId, deviceId, true,
331-
);
329+
return MatrixClientPeg.get().setDeviceVerified(userId, deviceId, true);
332330
}).then(() => {
333331
// Tell the user we verified everything
334332
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
335-
Modal.createDialog(QuestionDialog, {
333+
Modal.createTrackedDialog('Slash Commands', 'Verified key', QuestionDialog, {
336334
title: _t("Verified key"),
337335
description: (
338336
<div>

src/UnknownDeviceErrorHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const onAction = function(payload) {
2424
if (payload.action === 'unknown_device_error' && !isDialogOpen) {
2525
const UnknownDeviceDialog = sdk.getComponent('dialogs.UnknownDeviceDialog');
2626
isDialogOpen = true;
27-
Modal.createDialog(UnknownDeviceDialog, {
27+
Modal.createTrackedDialog('Unknown Device Error', '', UnknownDeviceDialog, {
2828
devices: payload.err.devices,
2929
room: payload.room,
3030
onFinished: (r) => {

src/components/structures/GroupView.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export default React.createClass({
266266
this.setState({uploadingAvatar: false});
267267
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
268268
console.error("Failed to upload avatar image", e);
269-
Modal.createDialog(ErrorDialog, {
269+
Modal.createTrackedDialog('Failed to upload image', '', ErrorDialog, {
270270
title: _t('Error'),
271271
description: _t('Failed to upload image'),
272272
});
@@ -288,7 +288,7 @@ export default React.createClass({
288288
});
289289
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
290290
console.error("Failed to save group profile", e);
291-
Modal.createDialog(ErrorDialog, {
291+
Modal.createTrackedDialog('Failed to update group', '', ErrorDialog, {
292292
title: _t('Error'),
293293
description: _t('Failed to update group'),
294294
});

0 commit comments

Comments
 (0)