Web Performance & Core Web Vitals Analytics Best Practices
LCP, CLS, INP monitoring in production - CrUX data, field-measurement via web-vitals.js, and the performance-to-conversion impact you can actually measure.
By Samarth Analytics · Published · Updated · Analytics Engineering · 10 min read
Summary: A practical guide to monitoring Core Web Vitals and tying performance to business outcomes. Covers LCP/CLS/INP field measurement via web-vitals.js, CrUX dataset analysis, Lighthouse CI for pre-deploy checks, and correlating performance data with conversion metrics in BigQuery.
- Core Web Vitals analytics are critical for understanding user experience and conversion.
- Lab metrics can be misleading; focus on field metrics for accurate insights.
- Use
web-vitals.jsfor real-time monitoring of LCP, CLS, and INP. - Integrate CWV events into GA4 to track performance effectively.
- Correlate performance data with conversion rates to drive actionable insights.
Why lab metrics lie and field metrics are the only truth
Lab metrics, often generated in controlled environments, can provide a snapshot of performance but frequently diverge from real-world user experiences. While tools like Lighthouse deliver quick insights, they can't account for the myriad of variables affecting actual user interactions – such as device type, network conditions, and user behavior.
Field metrics, on the other hand, reflect the actual performance experienced by users on your site. This is where Core Web Vitals (CWV) come into play, measuring essential user-centric metrics like Largest Contentful Paint (LCP), Cumulative Layout Shift (CLS), and Interaction to Next Paint (INP). These metrics give you an accurate view of how users perceive performance, which is crucial for improving engagement and conversion rates.
Warning: A green Lighthouse score in development does not guarantee green performance in production. Lab and field metrics can diverge wildly on real user networks and devices.
Field measurement via web-vitals.js in production
To gain accurate insights into Core Web Vitals in a live environment, we recommend implementing web-vitals.js. This lightweight library allows for the collection of CWV metrics directly from users' browsers. Here's how to get started:
-
Install the Library: Include the
web-vitals.jsscript in your web application. You can easily pull it from a CDN. -
Capture Metrics: Use the library to measure LCP, CLS, and INP, sending these metrics to your analytics platform for further analysis.
Here’s a code snippet showing how to set up web-vitals.js to send data to GA4:
import { getLCP, getCLS, getFID } from 'web-vitals';
function sendToAnalytics(metric) {
const { name, value } = metric;
window.gtag('event', 'web_vitals', {
metric_name: name,
value: Math.round(value), // Round value for easier analysis
navigation_type: performance.getEntriesByType('navigation')[0]?.type
});
}
getLCP(sendToAnalytics);
getCLS(sendToAnalytics);
getFID(sendToAnalytics);
This code tracks LCP, CLS, and INP metrics and sends them to GA4 as web_vitals events. Each event includes the metric name, its value, and the navigation type, providing you with a detailed overview of your site's performance.
Pushing CWV events to GA4 as custom events
After integrating web-vitals.js, it’s crucial to push the gathered CWV metrics to Google Analytics 4 as custom events. This allows for better segmentation and analysis of performance data. Here’s how you can effectively structure these events:
-
Event Naming: Use a consistent naming convention for your custom events. We recommend using
web_vitalsas the base name. -
Parameter Structure: Include parameters like
metric_name,value, andnavigation_typeto provide context for each event. -
Event Triggering: Set up triggers in your GA4 interface to capture these custom events for further analysis.
By implementing CWV metrics as custom events, you can tailor your reporting to focus on performance aspects that matter most to your business.
CrUX dataset for aggregate public-site baselines
The Chrome User Experience Report (CrUX) dataset is invaluable for benchmarking your site's performance against the competition. It aggregates real user data from millions of websites:
-
Public Baselines: Use CrUX data to understand how your performance stacks up against industry standards and competitors.
-
Identify Areas for Improvement: Analyze aggregate data to pinpoint the CWV metrics where your site lags behind the average.
-
Set Targeted Goals: Establish performance targets based on CrUX benchmarks to align your optimization efforts with real user expectations.
Implementing insights from the CrUX dataset can elevate your understanding of user experience and guide your optimization strategies effectively.
Lighthouse CI for pre-deploy gates
Integrating Lighthouse CI into your deployment process helps ensure that performance remains a priority. Here’s how to leverage Lighthouse CI effectively:
-
Set Up Lighthouse CI: Configure Lighthouse CI in your CI/CD pipeline to run performance audits against your site before deploying any changes.
-
Define Thresholds: Establish performance thresholds for LCP, CLS, and INP to prevent regressions. If your site fails to meet these thresholds, block the deployment.
-
Continuous Monitoring: Use Lighthouse CI to continuously monitor performance over time, helping you identify trends and areas needing attention.
Implementing Lighthouse CI can significantly enhance your site’s performance resilience and ensure that every deployment meets your performance standards.
Correlating performance with conversion in BigQuery
To truly understand the impact of performance on conversions, it's essential to analyze your CWV metrics alongside your conversion data in BigQuery. Follow these steps:
-
Data Collection: Ensure that you are capturing CWV metrics and conversion events in GA4.
-
Export to BigQuery: Link your GA4 property to BigQuery for deeper analysis and query capabilities.
-
Create Correlation Queries: Use SQL to correlate CWV metrics with conversion rates. For example:
SELECT
event_date,
AVG(CASE WHEN metric_name = 'LCP' THEN value END) AS avg_lcp,
AVG(CASE WHEN metric_name = 'CLS' THEN value END) AS avg_cls,
COUNT(CASE WHEN event_name = 'conversion' THEN 1 END) AS conversion_count
FROM
`your_project.your_dataset.your_table`
GROUP BY
event_date
ORDER BY
event_date DESC;
This query provides insights into how LCP and CLS influence conversions over time, enabling you to make data-driven decisions.
The realistic performance-to-conversion uplift numbers
While the relationship between performance and conversion is complex, we've seen that improving Core Web Vitals can yield significant results. Realistic uplift numbers often range from 10-20% in conversion rates when CWV metrics improve from poor to satisfactory levels. Here’s what to keep in mind:
-
Measure Baselines: Establish your current conversion rates as a baseline before making any performance improvements.
-
Incremental Improvements: Focus on improving one metric at a time, such as LCP or CLS, to measure the impact effectively.
-
Monitor Changes: Use GA4 and BigQuery to continuously monitor conversion rates post-implementation to validate your performance optimization efforts.
While every site is unique, the evidence strongly supports the case for investing in performance optimization for enhanced conversion rates.
Common mistakes we see
- Not implementing
web-vitals.jsto capture real user metrics effectively. - Relying solely on lab metrics without considering field metrics for decisions.
- Failing to push CWV events to GA4, resulting in missed insights.
- Not setting performance thresholds in Lighthouse CI, allowing for regressions in production.
- Ignoring the correlation between CWV and conversion rates in data analysis.
- Overlooking CrUX data for competitive performance benchmarking.
- Neglecting to monitor P95 performance metrics, which can reveal hidden issues.
Implementation checklist
- Install
web-vitals.jsin your production environment. - Configure the library to send CWV metrics to GA4 as custom events.
- Set up CrUX data monitoring for benchmarking against competitors.
- Integrate Lighthouse CI into your CI/CD pipeline with defined performance thresholds.
- Export GA4 data to BigQuery for correlation analysis with conversion rates.
- Monitor both P75 and P95 metrics to catch performance tail issues.
- Regularly review performance-to-conversion uplift after optimizations.
How Samarth Analytics helps
At Samarth Analytics, we specialize in turning performance data into actionable insights. Our team can help you implement effective Core Web Vitals analytics and optimize your site for better user experience and conversion rates. Interested in improving your web performance? Start with a free audit or contact us to learn how we can support your goals.