Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@perfectum/client

Package Overview
Dependencies
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@perfectum/client

Library for measuring client performance metrics

  • 1.3.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
27
increased by80%
Maintainers
3
Weekly downloads
 
Created
Source

Perfectum Client

Library for measuring client performance metrics :rocket:

Features

  • Using the latest APIs for better performance measurement :dart:
  • Measure only user-centric performance metrics :man:
  • Minimal impact on application performance :zap:
  • Small library size (< 3Kb gzip) :fire:

Built With

  • Beacon API
  • Performance API
  • PerformanceObserver API

Collected Metrics

Installation

yarn add @perfectum/client

Usage

import Perfectum from '@perfectum/client';

Perfectum.init({
  sendMetricsUrl: 'http://example.com/metrics',
  sendMetricsData: {
      app: 'example',
      env: 'production'
  },
  sendMetricsCallback: (metrics) => {
    const data = JSON.stringify(metrics);

    window.navigator.sendBeacon('http://example.com/metrics', data);
  },
  maxPaintTime: 15000
});

By default, before the user closes the page (unload event), the Perfectum will send an object with the collected metrics to the address specified in the sendMetricsUrl property.

If you need to add data to the resulting object with collected metrics, for example, the name of the application or the type of environment, you can specify the object with additional data in the sendMetricsData property.

If you want to implement your own logic for sending the collected metrics, you can specify a callback in the sendMetricsCallback property that will be called before the user closes the page (unload event). When calling a callback, an object with collected metrics will be passed as an argument.

If you want to filter paint performance metrics such as First Paint, First Contentful Paint, Largest Contentful Paint, you can set the maxPaintTime property(in milliseconds). By default, it is set to 60 seconds.

Custom Metrics

Custom metrics are the ability to measure the performance of individual elements on a page or the operations performed in your project. These metrics are necessary to provide the most accurate picture of how users perceive the performance of your application. There are two approaches to measuring custom metrics:

Measurement at the initialization stage of the application

At this stage, we may need to measure the time of appearance of the most important page elements on the user's screen, such as a hero image, cta button, lead form etc. For this type of measurement, you need to add the elementtiming attribute to the HTML element whose performance or time of appearance on the page you would like to measure.

<h1 elementtiming="metric-name">Example App</h1>

Measurement at the stage of interaction with the application

At this stage, we may need to measure the performance of the priority task, the time spent on an important request, or the rendering of specific page components. For this type of measurement, you need to use the special interface provided in the form of two static methods, startMeasure and stopMeasure.

import Perfectum from '@perfectum/client';

Perfectum.startMeasure('metric-name');

someKindOfImportantTask();

Perfectum.stopMeasure('metric-name');

FAQs

Package last updated on 07 Feb 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc