@temps-sdk/react-analytics 0.0.1-beta.29 → 0.0.1-beta.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"useSpeedAnalytics.d.ts","sourceRoot":"","sources":["../src/useSpeedAnalytics.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,wBAAwB;IACvC,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,QAwEvE"}
1
+ {"version":3,"file":"useSpeedAnalytics.d.ts","sourceRoot":"","sources":["../src/useSpeedAnalytics.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,wBAAwB;IACxC,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,iEAAiE;IACjE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,QA0EvE"}
@@ -1,31 +1,32 @@
1
- "use client";
2
- import { useEffect } from "react";
3
- import { onCLS, onFID, onLCP, onTTFB, onFCP, onINP } from "web-vitals";
4
- import { sendAnalytics } from "./utils";
1
+ 'use client';
2
+ import { useEffect } from 'react';
3
+ import { onCLS, onFID, onLCP, onTTFB, onFCP, onINP } from 'web-vitals';
4
+ import { sendAnalytics } from './utils';
5
5
  export function useSpeedAnalytics(options = {}) {
6
- const { basePath = "/_temps", disabled = false } = options;
6
+ const { basePath = '/_temps', disabled = false } = options;
7
7
  useEffect(() => {
8
- if (disabled || typeof window === "undefined")
8
+ if (disabled || typeof window === 'undefined')
9
9
  return;
10
10
  const initialMetrics = {};
11
11
  const lateMetrics = {};
12
12
  const sendInitialMetrics = () => {
13
13
  if (Object.keys(initialMetrics).length === 4) {
14
14
  const metricsPayload = {
15
- event_name: "web_vitals",
15
+ event_name: 'web_vitals',
16
16
  ttfb: initialMetrics.TTFB?.value ?? null,
17
17
  lcp: initialMetrics.LCP?.value ?? null,
18
18
  fid: initialMetrics.FID?.value ?? null,
19
19
  fcp: initialMetrics.FCP?.value ?? null,
20
20
  request_path: window.location.pathname,
21
21
  request_query: window.location.search,
22
+ event_data: {},
22
23
  };
23
- sendAnalytics("event", metricsPayload, "POST", basePath);
24
+ sendAnalytics('event', metricsPayload, 'POST', basePath);
24
25
  }
25
26
  };
26
27
  const sendLateMetric = (metricName, value) => {
27
28
  const payload = {
28
- event_name: "web_vitals_update",
29
+ event_name: 'web_vitals_update',
29
30
  ttfb: initialMetrics.TTFB?.value ?? null,
30
31
  lcp: initialMetrics.LCP?.value ?? null,
31
32
  fid: initialMetrics.FID?.value ?? null,
@@ -35,8 +36,9 @@ export function useSpeedAnalytics(options = {}) {
35
36
  [metricName.toLowerCase()]: value,
36
37
  request_path: window.location.pathname,
37
38
  request_query: window.location.search,
39
+ event_data: {},
38
40
  };
39
- sendAnalytics("event", payload, "POST", basePath);
41
+ sendAnalytics('event', payload, 'POST', basePath);
40
42
  };
41
43
  // Track metrics that can be gathered quickly
42
44
  onTTFB((metric) => {
@@ -58,11 +60,11 @@ export function useSpeedAnalytics(options = {}) {
58
60
  // Track metrics that take longer to stabilize
59
61
  onCLS((metric) => {
60
62
  lateMetrics.CLS = { value: metric.value, rating: metric.rating };
61
- sendLateMetric("cls", metric.value);
63
+ sendLateMetric('cls', metric.value);
62
64
  });
63
65
  onINP((metric) => {
64
66
  lateMetrics.INP = { value: metric.value, rating: metric.rating };
65
- sendLateMetric("inp", metric.value);
67
+ sendLateMetric('inp', metric.value);
66
68
  });
67
69
  }, [basePath, disabled]);
68
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temps-sdk/react-analytics",
3
- "version": "0.0.1-beta.29",
3
+ "version": "0.0.1-beta.30",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",