UNPKG

@nent/core

Version:

Functional elements to add routing, data-binding, dynamic HTML, declarative actions, audio, video, and so much more. Supercharge static HTML files into web apps without script or builds.

123 lines (122 loc) 3.12 kB
/*! * NENT 2022 */ import { Component, Event, Prop } from '@stencil/core'; import { actionBus, eventBus } from '../../services/actions'; import { commonState, debugIf, } from '../../services/common'; import { AnalyticsActionListener } from './services/actions'; /** * This element serves as a proxy to delegate event-based * functions to be consumed by various analytics snippets. * * @system app * @extension actions */ export class Analytics { constructor() { /** * Turn on debugging to get helpful messages from the * app, routing, data and action systems. */ this.debug = false; } componentWillLoad() { debugIf(this.debug, `n-app-analytics: loading`); commonState.analyticsEnabled = true; this.listener = new AnalyticsActionListener(actionBus, eventBus, this.debug); this.listener.handleEvent = e => { this.event.emit(e); }; this.listener.handlePageView = (e) => { this.pageView.emit(e); }; this.listener.handleViewTime = (e) => { this.viewTime.emit(e); }; debugIf(this.debug, `n-app-analytics: loaded`); } render() { return null; } disconnectedCallback() { commonState.analyticsEnabled = false; this.listener.destroy(); } static get is() { return "n-app-analytics"; } static get properties() { return { "debug": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Turn on debugging to get helpful messages from the\napp, routing, data and action systems." }, "attribute": "debug", "reflect": false, "defaultValue": "false" } }; } static get events() { return [{ "method": "event", "name": "custom-event", "bubbles": true, "cancelable": false, "composed": false, "docs": { "tags": [], "text": "Raised analytics events." }, "complexType": { "original": "any", "resolved": "any", "references": {} } }, { "method": "pageView", "name": "page-view", "bubbles": true, "cancelable": false, "composed": false, "docs": { "tags": [], "text": "Page views." }, "complexType": { "original": "LocationSegments", "resolved": "LocationSegments", "references": { "LocationSegments": { "location": "import", "path": "../../services/common" } } } }, { "method": "viewTime", "name": "view-time", "bubbles": true, "cancelable": false, "composed": false, "docs": { "tags": [], "text": "View percentage views." }, "complexType": { "original": "ViewTime", "resolved": "ViewTime", "references": { "ViewTime": { "location": "import", "path": "./services" } } } }]; } }