ngx-analytics
Version:
Vendor-agnostic web analytics for Angular2 applications, based on angulartics2
65 lines (60 loc) • 2.77 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('ngx-analytics')) :
typeof define === 'function' && define.amd ? define(['exports', '@angular/core', 'ngx-analytics'], factory) :
(factory((global['ngx-analytics'] = global['ngx-analytics'] || {}, global['ngx-analytics'].baidu = {}),global.ng.core,global['ngx-analytics']));
}(this, (function (exports,core,ngxAnalytics) { 'use strict';
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: core.Injectable },
];
NgxAnalyticsBaiduAnalytics.ctorParameters = function () { return [
{ type: ngxAnalytics.NgxAnalytics, },
]; };
return NgxAnalyticsBaiduAnalytics;
}());
exports.NgxAnalyticsBaiduAnalytics = NgxAnalyticsBaiduAnalytics;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=baidu.umd.js.map