UNPKG

@kurkov87/ngx-analytics

Version:

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

54 lines (49 loc) 2.54 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/platform-browser'), require('ngx-analytics')) : typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@angular/platform-browser', 'ngx-analytics'], factory) : (factory((global['ngx-analytics'] = global['ngx-analytics'] || {}, global['ngx-analytics'].clicky = {}),global.ng.core,global.ng.platformBrowser,global['ngx-analytics'])); }(this, (function (exports,core,platformBrowser,ngxAnalytics) { 'use strict'; var NgxAnalyticsClicky = (function () { function NgxAnalyticsClicky(ngxAnalytics$$1, titleService) { var _this = this; this.ngxAnalytics = ngxAnalytics$$1; this.titleService = titleService; if (typeof clicky === 'undefined') { console.warn('Angulartics 2 Clicky Plugin: clicky global not found'); } this.ngxAnalytics.pageTrack.subscribe(function (x) { return _this.pageTrack(x.path); }); this.ngxAnalytics.eventTrack.subscribe(function (x) { return _this.eventOrGoalTrack(x.action, x.properties); }); } NgxAnalyticsClicky.prototype.pageTrack = function (path) { var title = this.titleService.getTitle(); clicky.log(path, title, 'pageview'); }; NgxAnalyticsClicky.prototype.eventOrGoalTrack = function (action, properties) { if (typeof properties.goal === 'undefined') { var title = properties.title || null; var type = properties.type != null ? this.validateType(properties.type) : null; clicky.log(action, title, type); } else { var goalId = properties.goal; var revenue = properties.revenue; clicky.goal(goalId, revenue, !!properties.noQueue); } }; NgxAnalyticsClicky.prototype.validateType = function (type) { var EventType = ['pageview', 'click', 'download', 'outbound']; return EventType.indexOf(type) > -1 ? type : 'pageview'; }; NgxAnalyticsClicky.decorators = [ { type: core.Injectable }, ]; NgxAnalyticsClicky.ctorParameters = function () { return [ { type: ngxAnalytics.NgxAnalytics, }, { type: platformBrowser.Title, }, ]; }; return NgxAnalyticsClicky; }()); exports.NgxAnalyticsClicky = NgxAnalyticsClicky; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=clicky.umd.js.map