mirror of https://github.com/vector-im/riot-web
use 4/5 of the default custom vars for useful things :D
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>pull/21833/head
parent
b65e4960a5
commit
541cea020e
|
@ -14,13 +14,23 @@
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { getCurrentLanguage } from './languageHandler';
|
||||||
import MatrixClientPeg from './MatrixClientPeg';
|
import MatrixClientPeg from './MatrixClientPeg';
|
||||||
|
import PlatformPeg from './PlatformPeg';
|
||||||
import SdkConfig from './SdkConfig';
|
import SdkConfig from './SdkConfig';
|
||||||
|
|
||||||
function redact(str) {
|
function redact(str) {
|
||||||
return str.replace(/#\/(room|user)\/(.+)/, "#/$1/<redacted>");
|
return str.replace(/#\/(room|user)\/(.+)/, "#/$1/<redacted>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const customVariables = {
|
||||||
|
'App Platform': 1,
|
||||||
|
'App Version': 2,
|
||||||
|
'User Type': 3,
|
||||||
|
'Chosen Language': 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class Analytics {
|
class Analytics {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._paq = null;
|
this._paq = null;
|
||||||
|
@ -58,11 +68,22 @@ class Analytics {
|
||||||
|
|
||||||
this._paq.push(['setTrackerUrl', url+'piwik.php']);
|
this._paq.push(['setTrackerUrl', url+'piwik.php']);
|
||||||
this._paq.push(['setSiteId', siteId]);
|
this._paq.push(['setSiteId', siteId]);
|
||||||
|
|
||||||
this._paq.push(['trackAllContentImpressions']);
|
this._paq.push(['trackAllContentImpressions']);
|
||||||
this._paq.push(['discardHashTag', false]);
|
this._paq.push(['discardHashTag', false]);
|
||||||
this._paq.push(['enableHeartBeatTimer']);
|
this._paq.push(['enableHeartBeatTimer']);
|
||||||
this._paq.push(['enableLinkTracking', true]);
|
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() {
|
(function() {
|
||||||
const g = document.createElement('script');
|
const g = document.createElement('script');
|
||||||
const s = document.getElementsByTagName('script')[0];
|
const s = document.getElementsByTagName('script')[0];
|
||||||
|
@ -108,6 +129,14 @@ class Analytics {
|
||||||
this._paq.push(['setUserId', `@${cli.getUserIdLocalpart()}:${cli.getDomain()}`]);
|
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) {
|
if (!global.mxAnalytics) {
|
||||||
|
|
|
@ -277,6 +277,8 @@ export function initRtsClient(url) {
|
||||||
export function setLoggedIn(credentials) {
|
export function setLoggedIn(credentials) {
|
||||||
credentials.guest = Boolean(credentials.guest);
|
credentials.guest = Boolean(credentials.guest);
|
||||||
|
|
||||||
|
Analytics.setGuest(credentials.guest);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
"setLoggedIn: mxid:", credentials.userId,
|
"setLoggedIn: mxid:", credentials.userId,
|
||||||
"deviceId:", credentials.deviceId,
|
"deviceId:", credentials.deviceId,
|
||||||
|
|
Loading…
Reference in New Issue