@ngx-ext/google-analytics
Version:
Google Analytics for your Angular application
16 lines (14 loc) • 3.74 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("@ngx-ext/google-analytics",["exports","@angular/core","rxjs","rxjs/operators"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self)["ngx-ext"]=e["ngx-ext"]||{},e["ngx-ext"]["google-analytics"]={}),e.ng.core,e.rxjs,e.rxjs.operators)}(this,(function(e,t,o,n){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */Object.create;function r(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var n,r,i=o.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){r={error:e}}finally{try{n&&!n.done&&(o=i.return)&&o.call(i)}finally{if(r)throw r.error}}return a}Object.create;var i=new t.InjectionToken("Google Analytics TrackingId"),a=new t.InjectionToken("Google Analytics Tracking Options"),c=function(){function e(e,n){this.event=new t.EventEmitter,this.pageView=new t.EventEmitter,this.queue=new o.ReplaySubject,e&&this.configure(e,n)}return e.prototype.configure=function(e,t){var i=this;void 0===t&&(t="auto"),this.ga("create",e,t),this.ga("send","pageview"),this.event.subscribe((function(e){i.onEvent(e)})),this.pageView.subscribe((function(e){i.onPageView(e)}));var a=o.timer(2e4).pipe(n.switchMap((function(){return o.throwError(new Error("Could not load GA"))})));o.interval(50).pipe(n.takeUntil(a),n.filter((function(){return Boolean(window.ga)})),n.first(),n.switchMap((function(){return i.queue})),n.tap((function(e){window.ga.apply(window,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(r(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}();c.decorators=[{type:t.Injectable}],c.ctorParameters=function(){return[{type:String,decorators:[{type:t.Optional},{type:t.Inject,args:[i]}]},{type:void 0,decorators:[{type:t.Optional},{type:t.Inject,args:[a]}]}]};var s=function(){function e(){}return e.forRoot=function(){return{ngModule:e,providers:[c]}},e}();s.decorators=[{type:t.NgModule,args:[{declarations:[],exports:[],imports:[]}]}],e.GA_OPTIONS=a,e.GA_TOKEN=i,e.GoogleAnalyticsModule=s,e.GoogleAnalyticsService=c,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ngx-ext-google-analytics.umd.min.js.map