summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2015-06-15 10:01:11 -0800
committerCorey Hulen <corey@hulen.com>2015-06-15 10:01:11 -0800
commit06a10ab27911d58032c2cd023fb576d221c7fb68 (patch)
treee679ea57e9283a7461469d4144f4afc865f4b727
parentc94883e0dfc0c7cbcf86a78f9134d1e3283a07cd (diff)
parentf9dcbd7ebb293b1b9968d5bc03004628a4642a15 (diff)
downloadchat-06a10ab27911d58032c2cd023fb576d221c7fb68.tar.gz
chat-06a10ab27911d58032c2cd023fb576d221c7fb68.tar.bz2
chat-06a10ab27911d58032c2cd023fb576d221c7fb68.zip
Merge pull request #1 from mattermost/mm-1223
fixes mm-1223 gracefully handle missing analytics configs
-rw-r--r--web/react/utils/client.jsx4
-rw-r--r--web/templates/head.html33
2 files changed, 23 insertions, 14 deletions
diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx
index b83ee22e7..786e6dcea 100644
--- a/web/react/utils/client.jsx
+++ b/web/react/utils/client.jsx
@@ -4,12 +4,12 @@
module.exports.track = function(category, action, label, prop, val) {
global.window.snowplow('trackStructEvent', category, action, label, prop, val);
- if (global.window.analytics != null) global.window.analytics.track(action, {category: category, label: label, property: prop, value: val});
+ global.window.analytics.track(action, {category: category, label: label, property: prop, value: val});
};
module.exports.trackPage = function() {
global.window.snowplow('trackPageView');
- if (global.window.analytics != null) global.window.analytics.page();
+ global.window.analytics.page();
};
function handleError(method_name, xhr, status, err) {
diff --git a/web/templates/head.html b/web/templates/head.html
index 5fd3ee104..5eb7a7333 100644
--- a/web/templates/head.html
+++ b/web/templates/head.html
@@ -36,6 +36,7 @@
window._LTracker = _LTracker;
_LTracker.push({'logglyKey': config.LogglyWriteKey, 'sendConsoleErrors' : config.LogglyConsoleErrors });
} else {
+ window._LTracker = [];
console.warn("config.js missing LogglyWriteKey, Loggly analytics is not reporting");
}
</script>
@@ -58,26 +59,34 @@
analytics.page();
}}();
} else {
+ analytics = {};
+ analytics.page = function(){};
+ analytics.track = function(){};
console.warn("config.js missing SegmentWriteKey, SegmentIO analytics is not tracking");
}
</script>
<!-- Snowplow starts plowing -->
<script type="text/javascript">
- ;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
- p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
- };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
- n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","//d1fc8wv8zag5ca.cloudfront.net/2.4.2/sp.js","snowplow"));
+ if ('{{ .Props.AnalyticsUrl }}'.trim() !== '') {
+ ;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
+ p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
+ };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
+ n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","//d1fc8wv8zag5ca.cloudfront.net/2.4.2/sp.js","snowplow"));
- window.snowplow('newTracker', 'cf', '{{ .Props.AnalyticsUrl }}', {
- appId: '{{ .SiteName }}'
- });
+ window.snowplow('newTracker', 'cf', '{{ .Props.AnalyticsUrl }}', {
+ appId: '{{ .SiteName }}'
+ });
- var user = window.UserStore.getCurrentUser(true);
- if (user) {
- window.snowplow('setUserId', user.id);
- }
+ var user = window.UserStore.getCurrentUser(true);
+ if (user) {
+ window.snowplow('setUserId', user.id);
+ }
- window.snowplow('trackPageView');
+ window.snowplow('trackPageView');
+ } else {
+ window.snowplow = function(){};
+ console.warn("config.json missing AnalyticsUrl, Snowplow analytics is not tracking");
+ }
</script>
<!-- Snowplow stops plowing -->
</head>