Skip to content

Commit

Permalink
Add analystics backend to the agent
Browse files Browse the repository at this point in the history
There's one simple "start" event now that ships the main version.

On every new event, we'll include the origin and session_id so we can
track events. A lot of this is still new, so i'm not sure which events
we'll want to gather and how we'll do analytics and what not.
  • Loading branch information
jasonLaster committed Mar 10, 2015
1 parent 340c527 commit 8e19180
Show file tree
Hide file tree
Showing 8 changed files with 9,445 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ if (window.__agent) {
#### Frequently Asked Questions
If you have any additional questions, check out our [FAQ](https://github.com/marionettejs/marionette.inspector/blob/master/docs/faq.md).


#### Usage Analytics
The Inspector gathers usage analytics to better report on inspector statistics such as average weekly users and popular features as well as to report on marionette patterns such as library versions in usage and architectural / api patterns. If you would prefer to disable analytics it is easy to do so:

```js
if (window.__agent) {
window.__agent.disableAnalytics = true;
}
```

---

### Play with it locally
Expand Down
36 changes: 36 additions & 0 deletions extension/js/agent/actions/analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
;(function(Agent) {

var Parse = Agent.Parse;
var session_id = Agent.randomString(10);


var saveRecord = function(object, data) {
object.save(data, {
success: function(object) {
},
error: function(model, error) {
}
});
}

Agent.markEvent = function(eventName, data) {
if (Agent.disableAnalytics) {
return;
}

var Event = Parse.Object.extend("Event");
var event = new Event();

var eventData = _.extend({
event_name: eventName,
session_id: session_id,
url: window.location.origin
}, data);

saveRecord(event, eventData);
}

Agent.startAnalytics = function() {
Parse.initialize("ZMtYo1w9R7U8FcTX4NPSlCCTTYl41PRhEz19yREC", "fjfnW6iqB9KwtRh6yBwuQrLlYPYgwR3reEC4KkNH");
}
}(Agent));
4 changes: 4 additions & 0 deletions extension/js/agent/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
Agent.patchMarionette(Backbone, Marionette);
};


Agent.disableAnalytics = false;

Agent.startAnalytics();
Agent.lazyWorker = new Agent.LazyWorker();

}(Agent));
Expand Down
8 changes: 7 additions & 1 deletion extension/js/agent/build/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ var $ = this.$;
var Backbone = this.Backbone;
var Marionette = this.Marionette;


// @include ../../lib/parse.1.3.5.js


var Agent = this;

/*
Expand Down Expand Up @@ -55,6 +59,8 @@ var Agent = this;
// @include ../utils/printProperty.js
// @include ../utils/lazyWorker.js
// @include ../utils/stackFrame.js
// @include ../utils/randomString.js




Expand Down Expand Up @@ -131,6 +137,7 @@ var Agent = this;

// @include ../actions/highlightEl.js
// @include ../actions/search.js
// @include ../actions/analytics.js

/*
* MARIONETTE
Expand All @@ -150,4 +157,3 @@ var Agent = this;
// @include ../actions/regionInspector.js

// @include ../actions/appObserver.js

8 changes: 8 additions & 0 deletions extension/js/agent/patches/patchMarionette.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@

Agent.patchBackboneTrigger
);


Agent.markEvent('start', {
marionette_version: Marionette.VERSION,
backbone_version: Backbone.VERSION,
jquery_version: Backbone.$.fn.jquery,
// underscore_version is tough to get because it's inside the backbone and marionette closure and not exposed
})
};

return patchMarionette;
Expand Down
11 changes: 11 additions & 0 deletions extension/js/agent/utils/randomString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
;(function(Agent) {

Agent.randomString = function(length) {
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var result = '';
for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
return result;
}


}(Agent));
Loading

0 comments on commit 8e19180

Please sign in to comment.