From 541cea020e4c3480849d61b6b851e5df50fe9862 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 29 May 2017 19:04:37 +0100 Subject: [PATCH] use 4/5 of the default custom vars for useful things :D Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/Analytics.js | 29 +++++++++++++++++++++++++++++ src/Lifecycle.js | 2 ++ 2 files changed, 31 insertions(+) diff --git a/src/Analytics.js b/src/Analytics.js index 9c60bd6491..a4442c266b 100644 --- a/src/Analytics.js +++ b/src/Analytics.js @@ -14,13 +14,23 @@ limitations under the License. */ +import { getCurrentLanguage } from './languageHandler'; import MatrixClientPeg from './MatrixClientPeg'; +import PlatformPeg from './PlatformPeg'; import SdkConfig from './SdkConfig'; function redact(str) { return str.replace(/#\/(room|user)\/(.+)/, "#/$1/"); } +const customVariables = { + 'App Platform': 1, + 'App Version': 2, + 'User Type': 3, + 'Chosen Language': 4, +}; + + class Analytics { constructor() { this._paq = null; @@ -58,11 +68,22 @@ class Analytics { this._paq.push(['setTrackerUrl', url+'piwik.php']); this._paq.push(['setSiteId', siteId]); + this._paq.push(['trackAllContentImpressions']); this._paq.push(['discardHashTag', false]); this._paq.push(['enableHeartBeatTimer']); this._paq.push(['enableLinkTracking', true]); + const platform = PlatformPeg.get(); + this._setVisitVariable('App Platform', platform.constructor.name); + platform.getAppVersion().then((version) => { + this._setVisitVariable('App Version', version); + }).catch(() => { + this._setVisitVariable('App Version', 'unknown'); + }); + + this._setVisitVariable('Chosen Language', getCurrentLanguage()); + (function() { const g = document.createElement('script'); const s = document.getElementsByTagName('script')[0]; @@ -108,6 +129,14 @@ class Analytics { this._paq.push(['setUserId', `@${cli.getUserIdLocalpart()}:${cli.getDomain()}`]); } + _setVisitVariable(key, value) { + this._paq.push(['setCustomVariable', customVariables[key], key, value, 'visit']); + } + + setGuest(guest) { + if (this.disabled) return; + this._setVisitVariable('User Type', guest ? 'Guest' : 'Logged In'); + } } if (!global.mxAnalytics) { diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 6a01cfb61d..0bf4c575e5 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -277,6 +277,8 @@ export function initRtsClient(url) { export function setLoggedIn(credentials) { credentials.guest = Boolean(credentials.guest); + Analytics.setGuest(credentials.guest); + console.log( "setLoggedIn: mxid:", credentials.userId, "deviceId:", credentials.deviceId,