This guide shows you how to track your website’s Core Web Vitals on Edgio in real time using real user monitoring (RUM).

What are Core Web Vitals?

In May of 2021, Google began ranking websites based on a set of performance metrics called Core Web Vitals. This change effectively made site performance an SEO ranking factor. Websites with good Core Web Vitals may be placed higher in search results, while those with poor Core Web Vitals may be placed lower.
Unlike Lighthouse performance scores which are based on synthetic tests, Core Web Vitals scores are based on measurements from real users of Chrome as reported in the Chrome User Experience Report. Core Web Vitals can be tracked via Google Search Console and PageSpeed Insights. Optimizing Core Web Vitals using the official tools presents a number of challenges:
  • It can take days to weeks to see the effect of changes to your site on Core Web Vitals.
  • It’s hard to diagnose Core Web Vitals by page type or URL.
  • It’s impossible to A/B test the impact of site optimizations on Core Web Vitals. Note that to effectively A/B test performance optimizations you need both a RUM measurement tool and split testing at the edge, both of which Edgio provides.

Why use Edgio to track Core Web Vitals?

Instead of relying solely on Google Search Console, we recommend tracking Core Web Vitals using Edgio so that you can:
  • See how changes to your site impact Core Web Vitals in real time
  • Correlate web vitals to your application’s routes
  • Analyze score across a number of dimensions such as country, device, and connection type
  • Identify which pages are most negatively impacting your search ranking.
  • Use Edgio’s Edge-based split testing to A/B test the impact of performance optimizations on Core Web Vitals.


In order to start tracking Core Web Vitals on Edgio, you need to add the @layer0/rum client library to your application. There are a number of ways to do this:

Script Tag

To add Core Web Vitals tracking via a script tag, add the following to each page in your application:
1<script defer>
2 function initRum() {
3 new Layer0.Metrics({
4 token: 'your-token-here', // get this from https://app.layer0.co
5 }).collect()
6 }
8<script src="https://rum.layer0.co/latest.js" defer onload="initRum()"></script>

Google Tag Manager

2 function initMetrics() {
3 new Layer0.Metrics({
4 token: 'your-token-here', // get this from https://app.layer0.co
5 }).collect()
6 }
7 var rumScriptTag = document.createElement('script')
8 rumScriptTag.src = 'https://rum.layer0.co/latest.js'
9 rumScriptTag.setAttribute('defer', '')
10 rumScriptTag.type = 'text/javascript'
11 rumScriptTag.onload = initMetrics
12 document.body.appendChild(rumScriptTag)

NPM or Yarn

To install the Core Web Vitals library using npm, run:
1npm install --save @layer0/rum
Or, using yarn:
1yarn add @layer0/rum
Then, add the following to your application’s browser bundle:
1import { Metrics } from '@layer0/rum'
3new Metrics({
4 token: 'your-token-here', // get this from https://app.layer0.co

Tie URLs to Page Templates

You can tie URLs to page templates by providing an optional router parameter to Metrics.
When installing @layer0/rum using a script tag, use:
1new Edgio.Metrics({
2 // get this from https://app.layer0.co
3 token: 'your-token-here',
5 // assign a page label for each route:
6 router: new Edgio.Router()
7 .match('/', ({ setPageLabel }) => setPageLabel('home'))
8 .match('/p/:id', ({ setPageLabel }) => setPageLabel('product'))
9 .match('/c/:id', ({ setPageLabel }) => setPageLabel('category')),
When installing @layer0/rum via NPM or Yarn use:
1import { Router } from '@layer0/rum/Router'
2import { Metrics } from '@layer0/rum'
4new Metrics({
5 // get this from https://app.layer0.co
6 token: 'your-token-here',
8 // assign a page label for each route:
9 router: new Router()
10 .match('/', ({ setPageLabel }) => setPageLabel('home'))
11 .match('/p/:id', ({ setPageLabel }) => setPageLabel('product'))
12 .match('/c/:id', ({ setPageLabel }) => setPageLabel('category')),
The router supports the same pattern syntax as Express. Here’s more information on routing syntax.
For non single page applications (e.g. traditional “multi-page apps”), you can also explicitly set the page label by passing a pageLabel property during initialization. An example is shown below where the pageLabel is pulled from document.title:
2 function initMetrics() {
3 new Edgio.Metrics({
4 token: 'your-token-here',
5 pageLabel: document.title ? document.title : "(No title)",
6 }).collect();
7 }
8 var rumScriptTag = document.createElement('script');
9 rumScriptTag.src = "https://rum.layer0.co/latest.js";
10 rumScriptTag.setAttribute("defer", "");
11 rumScriptTag.type = "text/javascript";
12 rumScriptTag.onload = initMetrics;
13 document.body.appendChild(rumScriptTag);

Track Additional Data

You can tie the following data to Core Web Vitals:
1new Edgio.Metrics({
2 // Rather than providing a router, you can also define the page label for each page explicitly.
3 // Use this option if it is more convenient to add the script tag to each page template individually
4 // rather than adding it to the main application template.
5 pageLabel: 'home',
7 // When running a split test, use this field to specify which variant is active.
8 // This is automatically set for sites that are deployed on Edgio.
9 splitTestVariant: 'name-of-variant',
11 // The version of your application that is running.
12 appVersion: 'v1.0.0',
14 // Whether or not the page was served from the CDN cache, if this is known.
15 // This is automatically set for sites that are deployed on Edgio.
16 cacheHit: true | false,
18 // The country code in which the browser is running. This is often provided by CDNs
19 // as a request header that can be embedded in your script tab by your application code.
20 // This is automatically set for sites that are deployed on Edgio.
21 country: 'US',