Zizzamia / perfume.js

Web performance library for measuring all performance vitals metrics
https://zizzamia.github.io/perfume/
MIT License
3.13k stars 112 forks source link

analyticsTracker as promise #268

Open peterpeterparker opened 2 months ago

peterpeterparker commented 2 months ago

Motivation

I noticed that the analyticsTracker option of initPerfume is expected to be a void callback. It would be useful if it could accept a promise, WDYT?

Example

In my use case, I'm collecting data in IndexedDB using idb-keyval, which is a fully promisified library. It would be helpful if I could use await within the callback.

import {set} from "idb-keyval";
import {initPerfume} from "perfume.js";

const startMonitoring = () => {
  const analyticsTracker = async ({
    metricName,
    data
  }: IAnalyticsTrackerOptions): Promise<void> => {
      await set(crypto.randomUUID(), {metricName, data});
  };

  initPerfume({analyticsTracker});
};