Socket
Book a DemoInstallSign in
Socket

@aics/frontend-insights

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aics/frontend-insights

Light abstraction API on top of 3rd party monitoring tool(s).

latest
npmnpm
Version
0.2.3
Version published
Maintainers
3
Created
Source

@aics/frontend-insights

Light abstraction API on top of 3rd party monitoring/metrics/analytics tool(s).

Plugins

This library is useful insofar as 3rd party services are plugged into it; without plugins, it is effectively a noop API. Plugins are given to the default export of this package, the FrontendInsights class, which acts as a dispatcher of messages to its configured plugins.

This library defines an interface that must be implemented for each 3rd party service to be usable as a plugin to FrontendInsights. The interface is intentionally as generalized as possible. That interface is:

interface FrontendInsightsPlugin {
    process(message: FrontendInsightsMessage, context: FrontendInsightsContext): void;
}

External services should be initialized (e.g., given an API key) in a plugin constructor. Thereafter, it is the decision of the plugin whether to process some, all, or no messages distributed by the FrontendInsights class. For example, a plugin that works entirely by monkeypatching the browser's window.onerror event (as some browser-based exception monitoring services do), might choose to not process any messages. An analytics service, on the other hand, might choose to process FrontendInsightsMessageType.UserEvent and FrontendInsightsMessageType.UserTiming messages.

Additional plugins and message types may be added as necessary with no concern to existing usages of the library. If a new message type (FrontendInsightsMessageType) is added, it is recommended to add a specific public method to FrontendInsights for dispatching that type of message, similar to FrontendInsights::dispatchUserEvent.

Usage

import FrontendInsights, { FrontendInsightsContext } from "@aics/frontend-insights";
import AmplitudeNodePlugin from "@aics/frontend-insights-plugin-amplitude-node";

const context: FrontendInsightsContext = {
    application: {
        name: APP_ID,
        version: "4.2.2",
    },
    userInfo: {
        userId: "leaping_kangaroo@example.com",
    },
    session: {
        platform: "Electron"
    }
};
const frontendInsights = new FrontendInsights(context, [
    new AmplitudeNodePlugin({ apiKey: "abc123" }),
    new WhateverPlugin({ ... }),  // e.g., could be others...
]);

frontendInsights.dispatchUserEvent({
    type: "ANY_STRING",
    properties: {
        foo: true,
        bar: "no",
        baz: 123,
    },
});

FAQs

Package last updated on 04 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts