ngx-hotjar
Version:
A simple ng-6 wrapper to load hotjar dependency by angular way
246 lines (238 loc) • 7.1 kB
JavaScript
import { __awaiter, __generator } from 'tslib';
import { InjectionToken, APP_INITIALIZER, isDevMode, Injectable, NgModule, defineInjectable } from '@angular/core';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/** @type {?} */
var NGX_HOTJAR_SETTINGS_TOKEN = new 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: 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 (!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: Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
NgxHotjarService.ctorParameters = function () { return []; };
/** @nocollapse */ NgxHotjarService.ngInjectableDef = 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: 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
*/
export { HotjarInitializer, NGX_HOTJAR_INITIALIZER_PROVIDER, NgxHotjarService, NGX_HOTJAR_SETTINGS_TOKEN, NgxHotjarModule };
//# sourceMappingURL=ngx-hotjar.js.map