From 61a67c52c555faddccef50f9a38ba451aac43541 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 27 May 2017 20:39:52 +0100 Subject: [PATCH] initial piwik stuff Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/RightPanel.js | 11 ++++++---- src/vector/index.js | 28 +++++++++++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/components/structures/RightPanel.js b/src/components/structures/RightPanel.js index c7f5394b..8d5fc36e 100644 --- a/src/components/structures/RightPanel.js +++ b/src/components/structures/RightPanel.js @@ -22,6 +22,7 @@ import sdk from 'matrix-react-sdk'; import Matrix from "matrix-js-sdk"; import dis from 'matrix-react-sdk/lib/dispatcher'; import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg'; +import Analytics from 'matrix-react-sdk/lib/Analytics'; import rate_limited_func from 'matrix-react-sdk/lib/ratelimitedfunc'; import Modal from 'matrix-react-sdk/lib/Modal'; import AccessibleButton from 'matrix-react-sdk/lib/components/views/elements/AccessibleButton'; @@ -61,24 +62,26 @@ module.exports = React.createClass({ return { phase: this.Phase.MemberInfo, member: member, - } - } - else { + }; + } else { return { phase: this.Phase.MemberList - } + }; } }, onMemberListButtonClick: function() { + Analytics.trackEvent('RightPanel', 'memberListButtonClick'); this.setState({ phase: this.Phase.MemberList }); }, onFileListButtonClick: function() { + Analytics.trackEvent('RightPanel', 'fileListButtonClick'); this.setState({ phase: this.Phase.FilePanel }); }, onNotificationListButtonClick: function() { + Analytics.trackEvent('RightPanel', 'notificationListButtonClick'); this.setState({ phase: this.Phase.NotificationPanel }); }, diff --git a/src/vector/index.js b/src/vector/index.js index 14f8bb4b..d1752356 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -56,7 +56,8 @@ if (process.env.NODE_ENV !== 'production') { var RunModernizrTests = require("./modernizr"); // this side-effects a global var ReactDOM = require("react-dom"); var sdk = require("matrix-react-sdk"); -var PlatformPeg = require("matrix-react-sdk/lib/PlatformPeg"); +const PlatformPeg = require("matrix-react-sdk/lib/PlatformPeg"); +const Analytics = require("matrix-react-sdk/lib/Analytics"); sdk.loadSkin(require('../component-index')); var VectorConferenceHandler = require('../VectorConferenceHandler'); var UpdateChecker = require("./updater"); @@ -143,7 +144,7 @@ var onNewScreen = function(screen) { var hash = '#/' + screen; lastLocationHashSet = hash; window.location.hash = hash; -} +}; // We use this to work out what URL the SDK should // pass through when registering to allow the user to @@ -279,6 +280,26 @@ async function loadApp() { } else if (validBrowser) { UpdateChecker.start(); + let doNotTrack = navigator.doNotTrack; + if (typeof navigator.doNotTrack === 'string') { + doNotTrack = navigator.doNotTrack === 'yes'; + } + if (!doNotTrack && configJson.piwik && configJson.piwik.url && configJson.piwik.siteId) { + (function() { + const g = document.createElement('script'); + const s = document.getElementsByTagName('script')[0]; + g.type='text/javascript'; g.async=true; g.defer=true; g.src=configJson.piwik.url+'piwik.js'; + + g.onload = function() { + const tracker = window.Piwik.getTracker(configJson.piwik.url+'piwik.php', configJson.piwik.siteId); + console.log('Initialised anonymous analytics'); + Analytics.set(tracker); + }; + + s.parentNode.insertBefore(g, s); + })(); + } + const MatrixChat = sdk.getComponent('structures.MatrixChat'); window.matrixChat = ReactDOM.render( , document.getElementById('matrixchat') ); - } - else { + } else { console.error("Browser is missing required features."); // take to a different landing page to AWOOOOOGA at the user var CompatibilityPage = sdk.getComponent("structures.CompatibilityPage");