This document explains how the Google Web Vitals library generates metric IDs and how those IDs are reused across metric updates (deltas). This behavior is important when implementing RUM or telemetry instrumentation.
Reference implementation:
https://github.com/GoogleChrome/web-vitals/blob/main/src/lib/generateUniqueID.ts
The web-vitals library generates a unique ID using the following logic:
const generateUniqueID = () =>
`v${version}-${Date.now()}-${Math.floor(Math.random() * 1e13)}`;Source: https://github.com/GoogleChrome/web-vitals/blob/main/src/lib/generateUniqueID.ts
v<libraryVersion>-<timestampMs>-<randomNumber>
Example:
v3-1709328323456-4829384923849
| Component | Example | Purpose |
|---|---|---|
| Version | v3 |
Version of the web-vitals library |
| Timestamp | 1709328323456 |
Date.now() ensures temporal uniqueness |
| Random number | 4829384923849 |
Prevents collisions when multiple metrics occur in the same millisecond |
This combination guarantees that the ID is globally unique for the metric instance.
When a Web Vital metric (for example LCP or CLS) is first detected, the library creates a metric object with a generated ID.
Simplified internal structure:
const metric = {
name: 'LCP',
value: 0,
delta: 0,
id: generateUniqueID()
};Example metric:
{
"name": "LCP",
"value": 2100,
"delta": 2100,
}This document explains how the Google Web Vitals library generates metric IDs and how those IDs are reused across metric updates (deltas). This behavior is important when implementing RUM or telemetry instrumentation.
Reference implementation:
https://github.com/GoogleChrome/web-vitals/blob/main/src/lib/generateUniqueID.ts
The web-vitals library generates a unique ID using the following logic:
const generateUniqueID = () =>
`v${version}-${Date.now()}-${Math.floor(Math.random() * 1e13)}`;Source: https://github.com/GoogleChrome/web-vitals/blob/main/src/lib/generateUniqueID.ts
v<libraryVersion>-<timestampMs>-<randomNumber>
Example:
v3-1709328323456-4829384923849
| Component | Example | Purpose |
|---|---|---|
| Version | v3 |
Version of the web-vitals library |
| Timestamp | 1709328323456 |
Date.now() ensures temporal uniqueness |
| Random number | 4829384923849 |
Prevents collisions when multiple metrics occur in the same millisecond |
This combination guarantees that the ID is globally unique for the metric instance.
When a Web Vital metric (for example LCP or CLS) is first detected, the library creates a metric object with a generated ID.
Simplified internal structure:
const metric = {
name: 'LCP',
value: 0,
delta: 0,
id: generateUniqueID()
};Example metric:
{
"name": "LCP",
"value": 2100,
"delta": 2100,
"id": "v3-1709328323456-4829384923849"
}The ID is generated once when the metric instance is created.
Many Web Vitals metrics can update multiple times during the page lifecycle.
Example: Largest Contentful Paint (LCP) may change as larger elements render.
Instead of creating new IDs, the library updates the same metric object.
{
"name": "LCP",
"value": 2100,
"delta": 2100,
"id": "v3-1709328323456-4829384923849"
}{
"name": "LCP",
"value": 2450,
"delta": 350,
"id": "v3-1709328323456-4829384923849"
}Notice that:
id remains the same
Only the value and delta change.
The ID represents a single metric instance for a page lifecycle.
This enables downstream systems to:
- correlate updates belonging to the same metric
- reconstruct the final metric value
- deduplicate telemetry events
- understand metric progression over time
Example progression for CLS:
| Event | Value | Delta | ID |
|---|---|---|---|
| Layout shift 1 | 0.04 | 0.04 | same ID |
| Layout shift 2 | 0.07 | 0.03 | same ID |
| Layout shift 3 | 0.11 | 0.04 | same ID |
All updates share the same metric ID.
If a new ID were generated for every update:
Example:
| Event | Value | Delta | ID |
|---|---|---|---|
| Event 1 | 2100 | 2100 | ID1 |
| Event 2 | 2450 | 350 | ID2 |
Problems caused:
Telemetry systems cannot determine that these events belong to the same metric instance.
Systems may interpret them as two separate LCP measurements instead of updates.
Delta represents change from the previous value, but without a shared ID, the relationship is lost.
Observability systems rely on consistent identifiers to group metric updates.
A new metric ID is generated only when a new metric instance begins.
This typically happens when:
- a new page navigation occurs
- a new page lifecycle starts
Example:
| Page Load | Metric | ID |
|---|---|---|
| Page A | LCP | ID1 |
| Page B | LCP | ID2 |
Each navigation creates a fresh metric instance.
One metric instance → one ID → multiple delta updates
The ID uniquely represents a single Web Vital metric during a page lifecycle.
{
"id": "v3-1709328323456-4829384923849"
}
The ID is generated once when the metric instance is created.
Many Web Vitals metrics can update multiple times during the page lifecycle.
Example: Largest Contentful Paint (LCP) may change as larger elements render.
Instead of creating new IDs, the library updates the same metric object.
{
"name": "LCP",
"value": 2100,
"delta": 2100,
"id": "v3-1709328323456-4829384923849"
}{
"name": "LCP",
"value": 2450,
"delta": 350,
"id": "v3-1709328323456-4829384923849"
}Notice that:
id remains the same
Only the value and delta change.
The ID represents a single metric instance for a page lifecycle.
This enables downstream systems to:
- correlate updates belonging to the same metric
- reconstruct the final metric value
- deduplicate telemetry events
- understand metric progression over time
Example progression for CLS:
| Event | Value | Delta | ID |
|---|---|---|---|
| Layout shift 1 | 0.04 | 0.04 | same ID |
| Layout shift 2 | 0.07 | 0.03 | same ID |
| Layout shift 3 | 0.11 | 0.04 | same ID |
All updates share the same metric ID.
If a new ID were generated for every update:
Example:
| Event | Value | Delta | ID |
|---|---|---|---|
| Event 1 | 2100 | 2100 | ID1 |
| Event 2 | 2450 | 350 | ID2 |
Problems caused:
Telemetry systems cannot determine that these events belong to the same metric instance.
Systems may interpret them as two separate LCP measurements instead of updates.
Delta represents change from the previous value, but without a shared ID, the relationship is lost.
Observability systems rely on consistent identifiers to group metric updates.
A new metric ID is generated only when a new metric instance begins.
This typically happens when:
- a new page navigation occurs
- a new page lifecycle starts
Example:
| Page Load | Metric | ID |
|---|---|---|
| Page A | LCP | ID1 |
| Page B | LCP | ID2 |
Each navigation creates a fresh metric instance.
One metric instance → one ID → multiple delta updates
The ID uniquely represents a single Web Vital metric during a page lifecycle.