angular-ga
Version:
Google Analytics for your Angular application
16 lines (14 loc) • 4 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("angular-ga",["exports","@angular/core","rxjs","rxjs/operators"],t):t((e=e||self)["angular-ga"]={},e.ng.core,e.rxjs,e.rxjs.operators)}(this,(function(e,t,n,r){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */function o(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function i(e,t){return function(n,r){t(n,r,e)}}function a(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a}var c=new t.InjectionToken("angular-ga TrackingId"),u=new t.InjectionToken("angular-ga Tracking Options"),f=function(){function e(e,r){this.event=new t.EventEmitter,this.pageview=new t.EventEmitter,this.queue=new n.ReplaySubject,e&&this.configure(e,r)}return e.prototype.configure=function(e,t){var o=this;void 0===t&&(t="auto"),this.ga("create",e,t),this.ga("send","pageview"),this.event.subscribe((function(e){o.onEvent(e)})),this.pageview.subscribe((function(e){o.onPageView(e)}));var i=n.timer(2e4).pipe(r.switchMap((function(){return n.throwError(new Error("Could not load GA"))})));n.interval(50).pipe(r.takeUntil(i),r.filter((function(){return Boolean(window.ga)})),r.first(),r.switchMap((function(){return o.queue})),r.tap((function(e){var t;(t=window).ga.apply(t,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(a(arguments[t]));return e}(e))}))).subscribe()},e.prototype.set=function(e,t){if("string"!=typeof e&&"object"!=typeof e)throw new TypeError("Expected `fieldName` to be of type `string` or `object`, got `"+typeof e+"`");if("string"==typeof e&&void 0===t)throw new TypeError("Expected `fieldValue` to not be `undefined`");"object"==typeof e?this.ga("set",e):this.ga("set",e,t)},e.prototype.onEvent=function(e){this.ga("send","event",e.category,e.action,e.label,e.value)},e.prototype.onPageView=function(e){var t={};e.title&&(t.title=e.title),this.ga("send","pageview",e.page,t)},e.prototype.ga=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.queue.next(e)},e.ctorParameters=function(){return[{type:String,decorators:[{type:t.Optional},{type:t.Inject,args:[c]}]},{type:void 0,decorators:[{type:t.Optional},{type:t.Inject,args:[u]}]}]},e=o([t.Injectable(),i(0,t.Optional()),i(0,t.Inject(c)),i(1,t.Optional()),i(1,t.Inject(u))],e)}(),p=function(){function e(){}var n;return n=e,e.forRoot=function(){return{ngModule:n,providers:[f]}},e=n=o([t.NgModule({imports:[],declarations:[],exports:[]})],e)}();e.GA_OPTIONS=u,e.GA_TOKEN=c,e.GoogleAnalyticsModule=p,e.GoogleAnalyticsService=f,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=angular-ga.umd.min.js.map