@kurkov87/ngx-analytics
Version:
Vendor-agnostic web analytics for Angular2 applications, based on angulartics2
48 lines (45 loc) • 1.97 kB
JavaScript
import { Injectable } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { NgxAnalytics } from 'ngx-analytics';
var NgxAnalyticsClicky = (function () {
function NgxAnalyticsClicky(ngxAnalytics$$1, titleService) {
var _this = this;
this.ngxAnalytics = ngxAnalytics$$1;
this.titleService = titleService;
if (typeof clicky === 'undefined') {
console.warn('Angulartics 2 Clicky Plugin: clicky global not found');
}
this.ngxAnalytics.pageTrack.subscribe(function (x) { return _this.pageTrack(x.path); });
this.ngxAnalytics.eventTrack.subscribe(function (x) { return _this.eventOrGoalTrack(x.action, x.properties); });
}
NgxAnalyticsClicky.prototype.pageTrack = function (path) {
var title = this.titleService.getTitle();
clicky.log(path, title, 'pageview');
};
NgxAnalyticsClicky.prototype.eventOrGoalTrack = function (action, properties) {
if (typeof properties.goal === 'undefined') {
var title = properties.title || null;
var type = properties.type != null ? this.validateType(properties.type) : null;
clicky.log(action, title, type);
}
else {
var goalId = properties.goal;
var revenue = properties.revenue;
clicky.goal(goalId, revenue, !!properties.noQueue);
}
};
NgxAnalyticsClicky.prototype.validateType = function (type) {
var EventType = ['pageview', 'click', 'download', 'outbound'];
return EventType.indexOf(type) > -1 ? type : 'pageview';
};
NgxAnalyticsClicky.decorators = [
{ type: Injectable },
];
NgxAnalyticsClicky.ctorParameters = function () { return [
{ type: NgxAnalytics, },
{ type: Title, },
]; };
return NgxAnalyticsClicky;
}());
export { NgxAnalyticsClicky };
//# sourceMappingURL=clicky.es2015.js.map