UNPKG

ngx-tag-commander-lib

Version:

This service lets you integrate Tag Commander in your AngularX (2+) applications easily. - [Official website](https://www.commandersact.com/fr/produits/tagcommander/)

2 lines 5.3 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/common"),require("@angular/router"),require("@angular/core"),require("ngx-logger")):"function"==typeof define&&define.amd?define("ngx-tag-commander",["exports","@angular/common","@angular/router","@angular/core","ngx-logger"],t):t(e["ngx-tag-commander"]={},e.ng.common,e.ng.router,e.ng.core,e.i2)}(this,function(e,t,o,r,i){"use strict";var n=function(){function e(){}return Object.defineProperty(e.prototype,"nativeWindow",{get:function(){return function e(){return window}()},enumerable:!0,configurable:!0}),e.decorators=[{type:r.Injectable}],e}(),c=function(){function e(e,t,r){var n=this;this.winRef=e,this.customLogger=t,this.router=r,this._tcContainers=[],this._trackRoutes=!1,this.logger=t.create({level:i.NgxLoggerLevel.DEBUG}),this.router.events.subscribe(function(e){e instanceof o.RoutesRecognized&&n._trackRoutes&&(e.state.root.firstChild.data.tcInclude===undefined&&e.state.root.firstChild.data.tcInclude.forEach(function(e){n.reloadContainer(e.ids,e.idc,e.options)}))})}return e.prototype.addContainer=function(e,t,r){this._tcContainers.push({id:e,uri:t});var n=document.createElement("script");n.setAttribute("type","text/javascript"),n.setAttribute("src",t),n.setAttribute("id",e),"string"!=typeof r?(this.logger.warn("you didn't specify where you wanted to place the script, it will be placed in the head by default"),document.querySelector("head").appendChild(n)):"head"===r.toLowerCase()||"body"===r.toLowerCase()?document.querySelector(r.toLowerCase()).appendChild(n):(this.logger.warn("you didn't correctily specify where you wanted to place the script, it will be placed in the head by default"),document.querySelector("head").appendChild(n))},e.prototype.removeContainer=function(e){var t=document.getElementById(e),r=this._tcContainers.slice(0);document.querySelector("head").removeChild(t);for(var n=0;n<r.length;n++)r[n].id===e&&this._tcContainers.splice(n,1)},e.prototype.setDebug=function(e){(this.debug=e)?this.logger.updateConfig({level:i.NgxLoggerLevel.DEBUG}):this.logger.updateConfig({level:i.NgxLoggerLevel.OFF})},e.prototype.trackRoutes=function(e){this._trackRoutes=!!e},e.prototype.setTcVar=function(e,t){"undefined"!=typeof this.winRef.nativeWindow.tc_vars&&(this.winRef.nativeWindow.tc_vars[e]=t)},e.prototype.setTcVars=function(e){this.logger.debug("setTcVars",e);for(var t=Object.keys(e),r=0;r<t.length;r++)this.setTcVar(t[r],e[t[r]])},e.prototype.getTcVar=function(e){return this.logger.debug("getTcVars",e),null===this.winRef.nativeWindow.tc_vars[e]&&this.winRef.nativeWindow.tc_vars[e]},e.prototype.removeTcVar=function(e){this.logger.debug("removeTcVars",e),delete this.winRef.nativeWindow.tc_vars[e]},e.prototype.reloadAllContainers=function(e){this.logger.debug("reloadAllContainers",e),e=e||{},this.logger.debug("Reload all containers ","object"==typeof e?"with options "+e:""),this.winRef.nativeWindow.container.reload(e)},e.prototype.reloadContainer=function(e,t,r){r=r||{};this.logger.debug("Reload container ids: "+e+" idc: "+t,"object"==typeof r?"with options: "+r:""),this.winRef.nativeWindow["container_"+e+"_"+t].reload(r)},e.prototype.captureEvent=function(e,t,r){this.logger.debug("captureEvent",e,t,r),"undefined"!=typeof this.winRef.nativeWindow.tC&&(e in Object.keys(this.winRef.nativeWindow.tC.event)?this.winRef.nativeWindow.tC.event[e](t,r):this.logger.error("the key "+e+" you specified in the catpure event does not existe"))},e.decorators=[{type:r.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:n},{type:i.CustomNGXLoggerService},{type:o.Router}]},e.ngInjectableDef=r.defineInjectable({factory:function(){return new e(r.inject(n),r.inject(i.CustomNGXLoggerService),r.inject(o.Router))},token:e,providedIn:"root"}),e}(),a=function(){function e(e,t){this.el=e,this.tcService=t}return e.prototype.ngAfterViewInit=function(){this.tcService.setTcVars(this.tcSetVars)},e.decorators=[{type:r.Directive,args:[{selector:"[tcSetVars]"}]}],e.ctorParameters=function(){return[{type:r.ElementRef},{type:c}]},e.propDecorators={tcSetVars:[{type:r.Input,args:["tcSetVars"]}]},e}(),s=function(){function e(e,t){this.el=e,this.tcService=t}return e.prototype.ngAfterViewInit=function(){if("object"!=typeof this.tcEvent||this.tcEventLabel!==undefined&&this.tcEventObj!==undefined)this.tcService.captureEvent(this.tcEventLabel,this.el,this.tcEventObj);else try{this.tcService.captureEvent(this.tcEvent.eventLabel,this.el,this.tcEvent.data)}catch(e){console.error(e)}},e.decorators=[{type:r.Directive,args:[{selector:"[tcEvent]"}]}],e.ctorParameters=function(){return[{type:r.ElementRef},{type:c}]},e.propDecorators={tcEvent:[{type:r.Input,args:["tcEvent"]}],tcEventLabel:[{type:r.Input,args:["tcEventLabel"]}],tcEventObj:[{type:r.Input,args:["tcEventObj"]}]},e}(),u=function(){function e(){}return e.decorators=[{type:r.NgModule,args:[{declarations:[a,s],imports:[t.CommonModule,i.LoggerModule.forRoot({level:i.NgxLoggerLevel.DEBUG,serverLogLevel:i.NgxLoggerLevel.ERROR})],exports:[a,s],providers:[c]}]}],e}();e.NgxTagCommanderModule=u,e.TagCommanderService=c,e.TcEventDirective=s,e.TcSetVarsDirective=a,e.WindowRef=n,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=ngx-tag-commander.umd.min.js.map