UNPKG

@kurkov87/ngx-analytics

Version:

Vendor-agnostic web analytics for Angular2 applications, based on angulartics2

70 lines (67 loc) 2.34 kB
import { Injectable } from '@angular/core'; import { NgxAnalytics } from 'ngx-analytics'; var NgxAnalyticsSegment = (function () { function NgxAnalyticsSegment(ngxAnalytics$$1) { var _this = this; this.ngxAnalytics = ngxAnalytics$$1; 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.setUserProperties.subscribe(function (x) { return _this.setUserProperties(x); }); this.ngxAnalytics.setUserPropertiesOnce.subscribe(function (x) { return _this.setUserProperties(x); }); this.ngxAnalytics.setAlias.subscribe(function (x) { return _this.setAlias(x); }); } NgxAnalyticsSegment.prototype.pageTrack = function (path) { try { analytics.page(path); } catch (e) { if (!(e instanceof ReferenceError)) { throw e; } } }; NgxAnalyticsSegment.prototype.eventTrack = function (action, properties) { try { analytics.track(action, properties); } catch (e) { if (!(e instanceof ReferenceError)) { throw e; } } }; NgxAnalyticsSegment.prototype.setUserProperties = function (properties) { try { if (properties.userId) { analytics.identify(properties.userId, properties); } else { analytics.identify(properties); } } catch (e) { if (!(e instanceof ReferenceError)) { throw e; } } }; NgxAnalyticsSegment.prototype.setAlias = function (alias) { try { analytics.alias(alias); } catch (e) { if (!(e instanceof ReferenceError)) { throw e; } } }; NgxAnalyticsSegment.decorators = [ { type: Injectable }, ]; NgxAnalyticsSegment.ctorParameters = function () { return [ { type: NgxAnalytics, }, ]; }; return NgxAnalyticsSegment; }()); export { NgxAnalyticsSegment }; //# sourceMappingURL=segment.es5.js.map