UNPKG

@kurkov87/ngx-analytics

Version:

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

86 lines (81 loc) 3.66 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('ngx-analytics')) : typeof define === 'function' && define.amd ? define(['exports', '@angular/common', '@angular/core', 'ngx-analytics'], factory) : (factory((global['ngx-analytics'] = global['ngx-analytics'] || {}, global['ngx-analytics'].adobeanalytics = {}),global.ng.common,global.ng.core,global['ngx-analytics'])); }(this, (function (exports,common,core,ngxAnalytics) { 'use strict'; 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: core.Injectable }, ]; NgxAnalyticsAdobeAnalytics.ctorParameters = function () { return [ { type: ngxAnalytics.NgxAnalytics, }, { type: common.Location, }, ]; }; return NgxAnalyticsAdobeAnalytics; }()); exports.NgxAnalyticsAdobeAnalytics = NgxAnalyticsAdobeAnalytics; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=adobeanalytics.umd.js.map