From 03fc711e81eb1e0bce0082d02b58c9ef6a561171 Mon Sep 17 00:00:00 2001 From: Boris Grozev Date: Mon, 12 Feb 2018 13:36:10 -0600 Subject: [PATCH] feat: Makes the google analytics tracking id configurable. --- analytics-ga.js | 13 ++++++++++--- config.js | 3 +++ react/features/analytics/functions.js | 4 +++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/analytics-ga.js b/analytics-ga.js index c8a53f8aa..4b4186468 100644 --- a/analytics-ga.js +++ b/analytics-ga.js @@ -4,16 +4,23 @@ /** * */ - function Analytics() { + function Analytics(options) { /* eslint-disable */ + if (!options.googleAnalyticsTrackingId) { + console.log( + 'Failed to initialize Google Analytics handler, no tracking ID'); + return; + } + /** * Google Analytics + * TODO: Keep this local, there's no need to add it to window. */ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (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) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); - ga('create', 'UA-319188-14', 'jit.si'); + ga('create', options.googleAnalyticsTrackingId, 'jit.si'); ga('send', 'pageview'); /* eslint-enable */ @@ -114,7 +121,7 @@ * lib-jitsi-meet. */ Analytics.prototype.sendEvent = function(event) { - if (!event) { + if (!event || !ga) { return; } diff --git a/config.js b/config.js index 5191f3b3a..6f29d0efd 100644 --- a/config.js +++ b/config.js @@ -313,6 +313,9 @@ var config = { // "https://example.com/my-custom-analytics.js" // ], + // The Google Analytics Tracking ID + // googleAnalyticsTrackingId = 'your-tracking-id-here-UA-123456-1', + // Information about the jitsi-meet instance we are connecting to, including // the user region as seen by the server. deploymentInfo: { diff --git a/react/features/analytics/functions.js b/react/features/analytics/functions.js index 634a347a9..0fdd03c36 100644 --- a/react/features/analytics/functions.js +++ b/react/features/analytics/functions.js @@ -43,10 +43,12 @@ export function initAnalytics({ getState }: { getState: Function }) { const state = getState(); const config = state['features/base/config']; - const { analyticsScriptUrls, deploymentInfo } = config; + const { analyticsScriptUrls, deploymentInfo, googleAnalyticsTrackingId } + = config; const { group, server, user } = state['features/base/jwt']; const handlerConstructorOptions = { envType: (deploymentInfo && deploymentInfo.envType) || 'dev', + googleAnalyticsTrackingId, group, product: deploymentInfo && deploymentInfo.product, subproduct: deploymentInfo && deploymentInfo.environment,