Skip to content

Commit

Permalink
Track size of transferred files using GA
Browse files Browse the repository at this point in the history
  • Loading branch information
szimek committed Apr 14, 2014
1 parent 52370eb commit 6638654
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ FIREBASE_URL=https://your-firebase.firebaseio.com
FIREBASE_SECRET=qwerty
NEW_RELIC_ENABLED=false
NEW_RELIC_LICENSE_KEY=qwerty
GOOGLE_ANALYTICS_ID=UA-XXXX-Y
3 changes: 2 additions & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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-41889586-2', 'sharedrop.io');
ga('create', '<!-- @echo GOOGLE_ANALYTICS_ID -->', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
Expand Down Expand Up @@ -59,6 +59,7 @@
};
</script>
<!-- build:js({.tmp,app}) /scripts/app.js -->
<script src="/scripts/app/lib/analytics.js"></script>
<script src="/scripts/app/lib/room.js"></script>
<script src="/scripts/app/lib/file.js"></script>
<script src="/scripts/app/lib/webrtc.js"></script>
Expand Down
17 changes: 17 additions & 0 deletions app/scripts/app/lib/analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ShareDrop.Analytics = {
hasAnalytics: function () {
return window.ga && typeof window.ga === "function";
},

trackEvent: function (category, action, label, value) {
if (ShareDrop.Analytics.hasAnalytics()) {
window.ga('send', 'event', category, action, label, value);
}
}
};

(function () {
$.subscribe('file_received.p2p.peer', function (event, data) {
ShareDrop.Analytics.trackEvent('file', 'transferred', 'size', data.info.size);
});
})();
1 change: 1 addition & 0 deletions app/scripts/app/lib/webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ ShareDrop.WebRTC.prototype._onBinaryData = function (data, connection) {

$.publish('file_received.p2p.peer', {
blob: file,
info: info,
connection: connection
});
} else {
Expand Down

0 comments on commit 6638654

Please sign in to comment.