UNPKG

@kurkov87/ngx-analytics

Version:

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

80 lines (77 loc) 3.12 kB
import { Location } from '@angular/common'; import { Injectable } from '@angular/core'; import { NgxAnalytics } from 'ngx-analytics'; var NgxAnalyticsAdobeAnalytics = (function () { function NgxAnalyticsAdobeAnalytics(ngxAnalytics$$1, location) { var _this = this; this.ngxAnalytics = ngxAnalytics$$1; this.location = location; 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); }); } NgxAnalyticsAdobeAnalytics.prototype.pageTrack = function (path) { if (typeof s !== 'undefined' && s) { s.clearVars(); s.t({ pageName: path }); } }; NgxAnalyticsAdobeAnalytics.prototype.eventTrack = function (action, properties) { if (!properties) { properties = properties || {}; } if (typeof s !== 'undefined' && s) { if (typeof properties === 'object') { this.setUserProperties(properties); } if (action) { var linkName = (properties['linkName']) ? properties['linkName'] : action; var disableDelay = !!properties['disableDelay'] ? true : this; if (properties['action']) { action = properties['action']; } this.setPageName(); if (action.toUpperCase() === 'DOWNLOAD') { s.tl(disableDelay, 'd', linkName); } else if (action.toUpperCase() === 'EXIT') { s.tl(disableDelay, 'e', linkName); } else { s.tl(disableDelay, 'o', linkName); } } } }; NgxAnalyticsAdobeAnalytics.prototype.setPageName = function () { var path = this.location.path(true); var hashNdx = path.indexOf('#'); if (hashNdx > 0 && hashNdx < path.length) { s.pageName = path.substring(hashNdx + 1); } else { s.pageName = path; } }; NgxAnalyticsAdobeAnalytics.prototype.setUserProperties = function (properties) { if (typeof s !== 'undefined' && s) { if (typeof properties === 'object') { for (var key in properties) { if (properties.hasOwnProperty(key)) { s[key] = properties[key]; } } } } }; NgxAnalyticsAdobeAnalytics.decorators = [ { type: Injectable }, ]; NgxAnalyticsAdobeAnalytics.ctorParameters = function () { return [ { type: NgxAnalytics, }, { type: Location, }, ]; }; return NgxAnalyticsAdobeAnalytics; }()); export { NgxAnalyticsAdobeAnalytics }; //# sourceMappingURL=adobeanalytics.es2015.js.map