AppSuite:Metrics-Adapters: Difference between revisions
Line 3: | Line 3: | ||
Adapters can be registered or extended by using the well established technology of [[AppSuite:Extension_points|extension points]]. | Adapters can be registered or extended by using the well established technology of [[AppSuite:Extension_points|extension points]]. | ||
Here is an basic example how the PIWIK adapter is registered. The metrics module will call/invoke the defined functions for all registered adapters. | |||
=== Check preconditions === | |||
Please add at first a line into the code that checks for the user settings. In case the current adapter is disabled we should prevent registering the adapter; | |||
<code javascript> | |||
if (!settings.get('tracking/[add-your-id-here]/enabled', false)) return; | |||
</code> | |||
=== Register Adapter === | |||
<code javascript> | <code javascript> | ||
ext.point('io.ox/metrics/adapter').extend({ | ext.point('io.ox/metrics/adapter').extend({ | ||
Line 25: | Line 35: | ||
}); | }); | ||
</code> | </code> | ||
For more details the source code of the PIWIK adapter is A very good starting point. | |||
=== PIWIK === | === PIWIK === | ||
Line 41: | Line 54: | ||
==== consider settings ==== | ==== consider settings ==== | ||
=== Console === | === Console === |
Revision as of 07:49, 22 September 2015
Adapters
Adapters can be registered or extended by using the well established technology of extension points.
Here is an basic example how the PIWIK adapter is registered. The metrics module will call/invoke the defined functions for all registered adapters.
Check preconditions
Please add at first a line into the code that checks for the user settings. In case the current adapter is disabled we should prevent registering the adapter;
if (!settings.get('tracking/[add-your-id-here]/enabled', false)) return;
Register Adapter
ext.point('io.ox/metrics/adapter').extend({
id: 'piwik',
setup: function () {
// called once
},
trackVisit: function () {
// called for each tracked visit (usually called once)
},
trackEvent: function (baton) {
// called for each tracked event
},
trackPage: function (baton) {
// called for each opened application/module
},
trackVariable: function (baton) {
// usually called once
}
});
For more details the source code of the PIWIK adapter is A very good starting point.
PIWIK
Adapter for the open-source analytics platform.
source
io.ox/metrics/adapters/default.js
hint
Be aware to not use a name for your javascript files that matching common patterns of adblockers. For example in case we would name default.js PIWIK.js the adblocker would block the request and an error ocurred in the the browser.
consider settings
Console
A special debugging adapter that simply writes events to console.
source
io.ox/metrics/adapters/console.js
hint
You can activate this special adapter that writes events to console and tracks all events in browsers localstorage. To activate/deactivate simply paste this code into your console when you are logged in at appsuite:
// enable
require('settings!io.ox/core').set('tracking/console/enabled', true).save();
// disable
require('settings!io.ox/core').set('tracking/console/enabled', false).save();
You can see all tracked events by using the browers console again:
//directly accessing to the data
metrics.hash
// please use the following only in chrome cause it is using console.table
metrics.show()