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/)

559 lines (548 loc) 22.2 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/router'), require('@angular/core'), require('ngx-logger')) : typeof define === 'function' && define.amd ? define('ngx-tag-commander', ['exports', '@angular/common', '@angular/router', '@angular/core', 'ngx-logger'], factory) : (factory((global['ngx-tag-commander'] = {}),global.ng.common,global.ng.router,global.ng.core,global.i2)); }(this, (function (exports,common,i3,i0,i2) { 'use strict'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @return {?} */ function _window() { return window; } var WindowRef = /** @class */ (function () { function WindowRef() { } Object.defineProperty(WindowRef.prototype, "nativeWindow", { get: /** * @return {?} */ function () { return _window(); }, enumerable: true, configurable: true }); WindowRef.decorators = [ { type: i0.Injectable } ]; return WindowRef; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var TagCommanderService = /** @class */ (function () { function TagCommanderService(winRef, customLogger, router) { var _this = this; this.winRef = winRef; this.customLogger = customLogger; this.router = router; this._tcContainers = []; this._trackRoutes = false; this.logger = customLogger.create({ level: i2.NgxLoggerLevel.DEBUG }); this.router.events.subscribe(function (_data) { if (_data instanceof i3.RoutesRecognized && _this._trackRoutes) { if (_data.state.root.firstChild.data.tcInclude === undefined) { /** @type {?} */ var data = _data.state.root.firstChild.data.tcInclude; data.forEach(function (container) { _this.reloadContainer(container['ids'], container['idc'], container['options']); }); } } }); } // /** // * the script URI correspond to the tag-commander script URL, it can either be a CDN URL or the path of your script // * @param {string} id the id the script node will have // * @param {string} uri the source of the script // * @param {string} node the node on witch the script will be placed, it can either be head or body // */ // /** // * the script URI correspond to the tag-commander script URL, it can either be a CDN URL or the path of your script // * @param {string} id the id the script node will have // * @param {string} uri the source of the script // * @param {string} node the node on witch the script will be placed, it can either be head or body // */ /** * @param {?} id * @param {?} uri * @param {?} node * @return {?} */ TagCommanderService.prototype.addContainer = // /** // * the script URI correspond to the tag-commander script URL, it can either be a CDN URL or the path of your script // * @param {string} id the id the script node will have // * @param {string} uri the source of the script // * @param {string} node the node on witch the script will be placed, it can either be head or body // */ /** * @param {?} id * @param {?} uri * @param {?} node * @return {?} */ function (id, uri, node) { this._tcContainers.push({ 'id': id, 'uri': uri }); /** @type {?} */ var tagContainer = document.createElement('script'); tagContainer.setAttribute('type', 'text/javascript'); tagContainer.setAttribute('src', uri); tagContainer.setAttribute('id', id); if (typeof node !== 'string') { 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(tagContainer); } else if (node.toLowerCase() === 'head' || node.toLowerCase() === 'body') { document.querySelector(node.toLowerCase()).appendChild(tagContainer); } else { 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(tagContainer); } }; // /** // * The script URI correspond to the tag-commander script URL, it can either be a CDN URL or the path of your script // * @param {string} id // */ // /** // * The script URI correspond to the tag-commander script URL, it can either be a CDN URL or the path of your script // * @param {string} id // */ /** * @param {?} id * @return {?} */ TagCommanderService.prototype.removeContainer = // /** // * The script URI correspond to the tag-commander script URL, it can either be a CDN URL or the path of your script // * @param {string} id // */ /** * @param {?} id * @return {?} */ function (id) { /** @type {?} */ var container = document.getElementById(id); /** @type {?} */ var containers = this._tcContainers.slice(0); document.querySelector('head').removeChild(container); for (var i = 0; i < containers.length; i++) { if (containers[i].id === id) { this._tcContainers.splice(i, 1); } } }; // /** // * will display the debug messages if true // * @param {boolean} debug if set to true it will activate the debug msg default is false // */ // /** // * will display the debug messages if true // * @param {boolean} debug if set to true it will activate the debug msg default is false // */ /** * @param {?} debug * @return {?} */ TagCommanderService.prototype.setDebug = // /** // * will display the debug messages if true // * @param {boolean} debug if set to true it will activate the debug msg default is false // */ /** * @param {?} debug * @return {?} */ function (debug) { this.debug = debug; if (debug) { this.logger.updateConfig({ level: i2.NgxLoggerLevel.DEBUG }); } else { this.logger.updateConfig({ level: i2.NgxLoggerLevel.OFF }); } }; // /** // * allows the router to be tracked // * @param {boolean} b will read routes if set to true // */ // /** // * allows the router to be tracked // * @param {boolean} b will read routes if set to true // */ /** * @param {?} b * @return {?} */ TagCommanderService.prototype.trackRoutes = // /** // * allows the router to be tracked // * @param {boolean} b will read routes if set to true // */ /** * @param {?} b * @return {?} */ function (b) { this._trackRoutes = !!b; }; // /** // * set or update the value of the var // * @param {string} tcKey // * @param {*} tcVar // */ // /** // * set or update the value of the var // * @param {string} tcKey // * @param {*} tcVar // */ /** * @param {?} tcKey * @param {?} tcVar * @return {?} */ TagCommanderService.prototype.setTcVar = // /** // * set or update the value of the var // * @param {string} tcKey // * @param {*} tcVar // */ /** * @param {?} tcKey * @param {?} tcVar * @return {?} */ function (tcKey, tcVar) { if (typeof this.winRef.nativeWindow.tc_vars !== 'undefined') { this.winRef.nativeWindow.tc_vars[tcKey] = tcVar; } }; // /** // * set your varibles for the different providers, when called the first time it // * instantiate the external varible // * @param {object} vars // */ // /** // * set your varibles for the different providers, when called the first time it // * instantiate the external varible // * @param {object} vars // */ /** * @param {?} vars * @return {?} */ TagCommanderService.prototype.setTcVars = // /** // * set your varibles for the different providers, when called the first time it // * instantiate the external varible // * @param {object} vars // */ /** * @param {?} vars * @return {?} */ function (vars) { this.logger.debug('setTcVars', vars); /** @type {?} */ var listOfVars = Object.keys(vars); for (var i = 0; i < listOfVars.length; i++) { this.setTcVar(listOfVars[i], vars[listOfVars[i]]); } }; // /** // * get the value of the var // * @param {string} tcKey // */ // /** // * get the value of the var // * @param {string} tcKey // */ /** * @param {?} tcKey * @return {?} */ TagCommanderService.prototype.getTcVar = // /** // * get the value of the var // * @param {string} tcKey // */ /** * @param {?} tcKey * @return {?} */ function (tcKey) { this.logger.debug('getTcVars', tcKey); return this.winRef.nativeWindow.tc_vars[tcKey] === null ? this.winRef.nativeWindow.tc_vars[tcKey] : false; }; // /** // * removes the var by specifying the key // * @param {string} varKey // */ // /** // * removes the var by specifying the key // * @param {string} varKey // */ /** * @param {?} varKey * @return {?} */ TagCommanderService.prototype.removeTcVar = // /** // * removes the var by specifying the key // * @param {string} varKey // */ /** * @param {?} varKey * @return {?} */ function (varKey) { this.logger.debug('removeTcVars', varKey); delete this.winRef.nativeWindow.tc_vars[varKey]; }; // /** // * will reload all the containers // * @param {object} options can contain some options in a form of an object // */ // /** // * will reload all the containers // * @param {object} options can contain some options in a form of an object // */ /** * @param {?} options * @return {?} */ TagCommanderService.prototype.reloadAllContainers = // /** // * will reload all the containers // * @param {object} options can contain some options in a form of an object // */ /** * @param {?} options * @return {?} */ function (options) { this.logger.debug('reloadAllContainers', options); options = options || {}; this.logger.debug('Reload all containers ', typeof options === 'object' ? 'with options ' + options : ''); this.winRef.nativeWindow.container.reload(options); }; // /** // * will reload a specifique container // * @param {number} ids // * @param {number} idc // * @param {object} options can contain some options in a form of an object // */ // /** // * will reload a specifique container // * @param {number} ids // * @param {number} idc // * @param {object} options can contain some options in a form of an object // */ /** * @param {?} ids * @param {?} idc * @param {?} options * @return {?} */ TagCommanderService.prototype.reloadContainer = // /** // * will reload a specifique container // * @param {number} ids // * @param {number} idc // * @param {object} options can contain some options in a form of an object // */ /** * @param {?} ids * @param {?} idc * @param {?} options * @return {?} */ function (ids, idc, options) { /** @type {?} */ var options = options || {}; this.logger.debug('Reload container ids: ' + ids + ' idc: ' + idc, typeof options === 'object' ? 'with options: ' + options : ''); this.winRef.nativeWindow['container_' + ids + '_' + idc].reload(options); }; // /** // * will set an TagCommander event // * @param {string} eventLabel the name of your event // * @param {HTMLElement} element the HTMLelement on witch the event is attached // * @param {object} data the data you want to transmit // */ // /** // * will set an TagCommander event // * @param {string} eventLabel the name of your event // * @param {HTMLElement} element the HTMLelement on witch the event is attached // * @param {object} data the data you want to transmit // */ /** * @param {?} eventLabel * @param {?} element * @param {?} data * @return {?} */ TagCommanderService.prototype.captureEvent = // /** // * will set an TagCommander event // * @param {string} eventLabel the name of your event // * @param {HTMLElement} element the HTMLelement on witch the event is attached // * @param {object} data the data you want to transmit // */ /** * @param {?} eventLabel * @param {?} element * @param {?} data * @return {?} */ function (eventLabel, element, data) { this.logger.debug('captureEvent', eventLabel, element, data); if (typeof this.winRef.nativeWindow.tC !== 'undefined') { if (eventLabel in Object.keys(this.winRef.nativeWindow.tC.event)) { this.winRef.nativeWindow.tC.event[eventLabel](element, data); } else { this.logger.error('the key ' + eventLabel + ' you specified in the catpure event does not existe'); } } }; TagCommanderService.decorators = [ { type: i0.Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ TagCommanderService.ctorParameters = function () { return [ { type: WindowRef }, { type: i2.CustomNGXLoggerService }, { type: i3.Router } ]; }; /** @nocollapse */ TagCommanderService.ngInjectableDef = i0.defineInjectable({ factory: function TagCommanderService_Factory() { return new TagCommanderService(i0.inject(WindowRef), i0.inject(i2.CustomNGXLoggerService), i0.inject(i3.Router)); }, token: TagCommanderService, providedIn: "root" }); return TagCommanderService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var TcSetVarsDirective = /** @class */ (function () { function TcSetVarsDirective(el, tcService) { this.el = el; this.tcService = tcService; } /** * @return {?} */ TcSetVarsDirective.prototype.ngAfterViewInit = /** * @return {?} */ function () { this.tcService.setTcVars(this.tcSetVars); }; TcSetVarsDirective.decorators = [ { type: i0.Directive, args: [{ selector: '[tcSetVars]' },] } ]; /** @nocollapse */ TcSetVarsDirective.ctorParameters = function () { return [ { type: i0.ElementRef }, { type: TagCommanderService } ]; }; TcSetVarsDirective.propDecorators = { tcSetVars: [{ type: i0.Input, args: ['tcSetVars',] }] }; return TcSetVarsDirective; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ // usage [tcEvent] var TcEventDirective = /** @class */ (function () { function TcEventDirective(el, tcService) { this.el = el; this.tcService = tcService; } /** * @return {?} */ TcEventDirective.prototype.ngAfterViewInit = /** * @return {?} */ function () { if (typeof this.tcEvent === 'object' && (this.tcEventLabel === undefined || this.tcEventObj === undefined)) { try { this.tcService.captureEvent(this.tcEvent.eventLabel, this.el, this.tcEvent.data); } catch (e) { console.error(e); } } else { this.tcService.captureEvent(this.tcEventLabel, this.el, this.tcEventObj); } }; TcEventDirective.decorators = [ { type: i0.Directive, args: [{ selector: '[tcEvent]' },] } ]; /** @nocollapse */ TcEventDirective.ctorParameters = function () { return [ { type: i0.ElementRef }, { type: TagCommanderService } ]; }; TcEventDirective.propDecorators = { tcEvent: [{ type: i0.Input, args: ['tcEvent',] }], tcEventLabel: [{ type: i0.Input, args: ['tcEventLabel',] }], tcEventObj: [{ type: i0.Input, args: ['tcEventObj',] }] }; return TcEventDirective; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgxTagCommanderModule = /** @class */ (function () { function NgxTagCommanderModule() { } NgxTagCommanderModule.decorators = [ { type: i0.NgModule, args: [{ declarations: [TcSetVarsDirective, TcEventDirective], imports: [ common.CommonModule, i2.LoggerModule.forRoot({ level: i2.NgxLoggerLevel.DEBUG, serverLogLevel: i2.NgxLoggerLevel.ERROR }) ], exports: [TcSetVarsDirective, TcEventDirective], providers: [TagCommanderService] },] } ]; return NgxTagCommanderModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ exports.NgxTagCommanderModule = NgxTagCommanderModule; exports.TagCommanderService = TagCommanderService; exports.TcEventDirective = TcEventDirective; exports.TcSetVarsDirective = TcSetVarsDirective; exports.WindowRef = WindowRef; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=ngx-tag-commander.umd.js.map