Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

Add pluggable analytics framework

Issac Gerges92a6b765a2c6
diff --git a/analytics.js b/analytics.js
index 07ea7184f2..54c7ee1ae7 100644
--- a/analytics.js
+++ b/analytics.js
@@ -1,8 +1,18 @@
-/**
- * Google Analytics
- */
-(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('send', 'pageview');
\ No newline at end of file
+(function (ctx) {
+ function Analytics() {
+ /**
+ * Google Analytics
+ */
+ (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('send', 'pageview');
+ }
+
+ Analytics.prototype.sendEvent = function (action, data) {
+ ga('send', 'event', 'jit.si', action);
+ };
+
+ ctx.Analytics = Analytics;
+}(window));
\ No newline at end of file
diff --git a/modules/statistics/AnalyticsAdapter.js b/modules/statistics/AnalyticsAdapter.js
new file mode 100644
index 0000000000..8492c11237
--- /dev/null
+++ b/modules/statistics/AnalyticsAdapter.js
@@ -0,0 +1,15 @@
+function NoopAnalytics() {}
+NoopAnalytics.prototype.sendEvent = function () {};
+
+function AnalyticsAdapter() {
+ var AnalyticsImpl = window.Analytics || NoopAnalytics;
+ this.analytics = new AnalyticsImpl();
+}
+
+AnalyticsAdapter.prototype.sendEvent = function (action, data) {
+ try {
+ this.analytics.sendEvent.apply(this.analytics, arguments);
+ } catch (ignored) {}
+};
+
+module.exports = new AnalyticsAdapter();
\ No newline at end of file