UNPKG

ngx-hotjar

Version:

A simple ng-6 wrapper to load hotjar dependency by angular way

363 lines (350 loc) 13.4 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) : typeof define === 'function' && define.amd ? define('ngx-hotjar', ['exports', '@angular/core'], factory) : (factory((global['ngx-hotjar'] = {}),global.ng.core)); }(this, (function (exports,i0) { '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 __awaiter(thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function () { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /** @type {?} */ var NGX_HOTJAR_SETTINGS_TOKEN = new i0.InjectionToken('ngx-hotjar-settings', { factory: function () { return ({ trackingCode: '', version: 6 }); } }); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /** @type {?} */ var NGX_HOTJAR_INITIALIZER_PROVIDER = { provide: i0.APP_INITIALIZER, multi: true, useFactory: HotjarInitializer, deps: [ NGX_HOTJAR_SETTINGS_TOKEN ] }; /** * @param {?} $settings * @return {?} */ function HotjarInitializer($settings) { var _this = this; return function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { if (!$settings.trackingCode) { if (!i0.isDevMode()) { console.error('Empty tracking code for Hotjar. Make sure to provide one when initializing NgxHotjarModule.'); } return [2 /*return*/]; } (function (h, o, t, j, a, r) { h.hj = h.hj || function () { (h.hj.q = h.hj.q || []).push(arguments); }; h._hjSettings = { hjid: $settings.trackingCode, hjsv: $settings.version || 6 }; a = o.getElementsByTagName('head')[0]; r = o.createElement('script'); r.async = 1; r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv; a.appendChild(r); })(window, document, 'https://static.hotjar.com/c/hotjar-', '.js?sv='); return [2 /*return*/]; }); }); }; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ var NgxHotjarService = /** @class */ (function () { function NgxHotjarService() { } /** * Fires an PageView event to an virtual url path * * @param path virtual url */ /** * Fires an PageView event to an virtual url path * * @param {?} path virtual url * @return {?} */ NgxHotjarService.prototype.virtualPageView = /** * Fires an PageView event to an virtual url path * * @param {?} path virtual url * @return {?} */ function (path) { try { hj('vpv', path); } catch (err) { this.error(err); } }; /** * Fires an event on Hotjar. Use this method to trigger events on forms and start video recordings. * * @param path url */ /** * Fires an event on Hotjar. Use this method to trigger events on forms and start video recordings. * * @param {?} path url * @return {?} */ NgxHotjarService.prototype.trigger = /** * Fires an event on Hotjar. Use this method to trigger events on forms and start video recordings. * * @param {?} path url * @return {?} */ function (path) { try { hj('trigger', path); } catch (err) { this.error(err); } }; /** * Allows you to tag recordings on Hotjar of all visitors passing through a page. * * @param path tags */ /** * Allows you to tag recordings on Hotjar of all visitors passing through a page. * * @param {?} path tags * @return {?} */ NgxHotjarService.prototype.tagRecording = /** * Allows you to tag recordings on Hotjar of all visitors passing through a page. * * @param {?} path tags * @return {?} */ function (path) { try { hj('tagRecording', path); } catch (err) { this.error(err); } }; /** * This option is available in case you need to set up page change tracking manually * within your app's router. * * @param path Path */ /** * This option is available in case you need to set up page change tracking manually * within your app's router. * * @param {?} path Path * @return {?} */ NgxHotjarService.prototype.stateChange = /** * This option is available in case you need to set up page change tracking manually * within your app's router. * * @param {?} path Path * @return {?} */ function (path) { try { hj('stateChange', path); } catch (err) { this.error(err); } }; /** * @param {?} err * @return {?} */ NgxHotjarService.prototype.error = /** * @param {?} err * @return {?} */ function (err) { // window.hj=window.hj||function(){(hj.q=hj.q||[]).push(arguments)}; /** @todo Check typef for Hotjar */ throw new Error('Hotjar is not loaded'); }; NgxHotjarService.decorators = [ { type: i0.Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ NgxHotjarService.ctorParameters = function () { return []; }; /** @nocollapse */ NgxHotjarService.ngInjectableDef = i0.defineInjectable({ factory: function NgxHotjarService_Factory() { return new NgxHotjarService(); }, token: NgxHotjarService, providedIn: "root" }); return NgxHotjarService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ var NgxHotjarModule = /** @class */ (function () { function NgxHotjarModule() { } /** * @param {?} trackingCode * @param {?=} version * @return {?} */ NgxHotjarModule.forRoot = /** * @param {?} trackingCode * @param {?=} version * @return {?} */ function (trackingCode, version) { if (version === void 0) { version = 6; } return { ngModule: NgxHotjarModule, providers: [ { provide: NGX_HOTJAR_SETTINGS_TOKEN, useValue: { trackingCode: trackingCode, version: version } }, NGX_HOTJAR_INITIALIZER_PROVIDER, ] }; }; NgxHotjarModule.decorators = [ { type: i0.NgModule, args: [{ imports: [], declarations: [], exports: [], providers: [] },] } ]; return NgxHotjarModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ exports.HotjarInitializer = HotjarInitializer; exports.NGX_HOTJAR_INITIALIZER_PROVIDER = NGX_HOTJAR_INITIALIZER_PROVIDER; exports.NgxHotjarService = NgxHotjarService; exports.NGX_HOTJAR_SETTINGS_TOKEN = NGX_HOTJAR_SETTINGS_TOKEN; exports.NgxHotjarModule = NgxHotjarModule; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=ngx-hotjar.umd.js.map