Allow usage of analytics adapter (#2327)

* Allow usage of analytics adapter

* Use promises in controller
This commit is contained in:
Marek Mikołajczyk
2016-07-20 15:27:15 +02:00
committed by Florent Vilmart
parent 02edf27f05
commit d1a6caeee3
5 changed files with 57 additions and 8 deletions

View File

@@ -1,17 +1,20 @@
// AnalyticsRouter.js
import PromiseRouter from '../PromiseRouter';
// Returns a promise that resolves to an empty object response
function ignoreAndSucceed(req) {
return Promise.resolve({
response: {}
});
function appOpened(req) {
const analyticsController = req.config.analyticsController;
return analyticsController.appOpened(req);
}
function trackEvent(req) {
const analyticsController = req.config.analyticsController;
return analyticsController.trackEvent(req);
}
export class AnalyticsRouter extends PromiseRouter {
mountRoutes() {
this.route('POST','/events/AppOpened', ignoreAndSucceed);
this.route('POST','/events/:eventName', ignoreAndSucceed);
this.route('POST','/events/AppOpened', appOpened);
this.route('POST','/events/:eventName', trackEvent);
}
}