ngx-analytics
Version:
Vendor-agnostic web analytics for Angular2 applications, based on angulartics2
58 lines (55 loc) • 2.27 kB
JavaScript
import { Injectable } from '@angular/core';
import { NgxAnalytics } from 'ngx-analytics';
var NgxAnalyticsBaiduAnalytics = (function () {
function NgxAnalyticsBaiduAnalytics(ngxAnalytics$$1) {
var _this = this;
this.ngxAnalytics = ngxAnalytics$$1;
if (typeof _hmt === 'undefined') {
_hmt = [];
}
else {
_hmt.push(['_setAutoPageview', false]);
}
this.ngxAnalytics.pageTrack.subscribe(function (x) { return _this.pageTrack(x.path); });
this.ngxAnalytics.eventTrack.subscribe(function (x) { return _this.eventTrack(x.action, x.properties); });
this.ngxAnalytics.setUsername.subscribe(function (x) { return _this.setUsername(x); });
this.ngxAnalytics.setUserProperties.subscribe(function (x) { return _this.setUserProperties(x); });
}
NgxAnalyticsBaiduAnalytics.prototype.pageTrack = function (path) {
if (typeof _hmt !== 'undefined' && _hmt) {
_hmt.push(['_trackPageview', path]);
}
};
NgxAnalyticsBaiduAnalytics.prototype.eventTrack = function (action, properties) {
if (!properties || !properties.category) {
properties = properties || {};
properties.category = 'Event';
properties.opt_label = 'default';
properties.opt_value = 'default';
}
if (typeof _hmt !== 'undefined' && _hmt) {
_hmt.push([
'_trackEvent',
properties.category,
action,
properties.opt_label,
properties.opt_value,
]);
}
};
NgxAnalyticsBaiduAnalytics.prototype.setUsername = function (userId) {
_hmt.push(['_setCustomVar', 1, 'identity', userId]);
};
NgxAnalyticsBaiduAnalytics.prototype.setUserProperties = function (properties) {
_hmt.push(['_setCustomVar', 2, 'user', JSON.stringify(properties)]);
};
NgxAnalyticsBaiduAnalytics.decorators = [
{ type: Injectable },
];
NgxAnalyticsBaiduAnalytics.ctorParameters = function () { return [
{ type: NgxAnalytics, },
]; };
return NgxAnalyticsBaiduAnalytics;
}());
export { NgxAnalyticsBaiduAnalytics };
//# sourceMappingURL=baidu.es2015.js.map