Our real user monitoring (RUM) library allows real-time tracking of your website’s Core Web Vitals for Chromium-based browsers and Firefox.
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.
Why use Edgio to track Core Web Vitals?
The benefits of using Edgio instead of Google Search Console to track Core Web Vitals are that it allows you to:
- 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.
Installing Real User Monitoring (RUM)
Tracking Core Web Vitals on Edgio requires adding the
@edgio/rum
client library to your application. The Edgio Console provides information on how to install this library using an edge function, a script tag, Google tag manager, npm, and yarn.To view @edgio/rum installation instructions
-
Load the Real User Monitoring page.
- From the Edgio Console, select the desired private space or organization.
- Select the desired property.
- From the left-hand pane, select the desired environment from under the Environments section.
- From the left-hand pane, select Analytics | Real User Monitoring.
-
Click on the tab for the desired installation method.The Edgio Console provides installation instructions that contain a token that is specific to your property.
Edge Functions
Edge Functions requires activation. Contact your account manager or our sales department at 1 (866) 200 - 5463 to upgrade your account.
An edge function can automatically inject Core Web Vitals tracking to all of your web pages. The method for generating this edge function varies according to whether you are using CDN-as-code or the Edgio Console to deploy changes.
Edgio Console: To inject Core Web Vitals tracking within your requests
-
Click Create Edge Function from the Edge Function tab of the Real User Monitoring page.Edgio will automatically generate an edge function that adds Core Web Vitals tracking to a request and a rule that invokes that edge function.
-
Review your rules.
-
Deploy your changes to this environment.
CDN-as-Code: To inject Core Web Vitals tracking within your requests
-
In the Edgio router, use the
edge_function
feature to specify the path to the edge function that will add Core Web Vitals tracking.JavaScriptroutes.js1// This file was added by edgio init.2// You should commit this file to source control.3import {Router, edgioRoutes} from '@edgio/core';45export default new Router()6 // Built-in Edgio routes7 .use(edgioRoutes)89 // Specifies the edge function for all paths. Modify the path as needed.10 .match({}, {11 edge_function: './edge-functions/main.js',12 }); -
Add the following edge function:JavaScriptedge-functions/main.js1export async function handleHttpRequest(request, context) {2 const originResponse = await fetch(request.url, {3 headers: request.headers,4 method: request.method,5 body: request.body,6 edgio: {7 origin: context.requestVars.matched_origin_name8 }9 })1011 // Return origin response if not HTML12 if(!originResponse.headers.get("content-type").startsWith('text/html')){13 return originResponse;14 }1516 let html = await originResponse.text()17 html = html.replace(18 '</body>', `19 <script defer>20 function initEdgioRum() {21 new Edgio.Metrics({22 token: '<TOKEN>'23 }).collect()24 }25 </script>26 <script src="https://rum.edgio.net/latest.js" defer onload="initEdgioRum()"></script>27 </body>`28 )29 return new Response(html, originResponse)30}
-
Replace
<TOKEN>
with your RUM token.You can find this token on the Script tag tab.JavaScriptedge-functions/main.js1...2 function initEdgioRum() {3 new Edgio.Metrics({4 token: 'ab1234c7-fe39-4a0e-8b3c-1ddf837a5c90'5 }).collect()6 }7... -
Optional. If you are also injecting Predictive Prefetching, then you should insert a script tag that installs it as shown below.JavaScriptedge-functions/main.js1...2 html = html.replace(3 '</body>', `4 <script defer>5 function initEdgioRum() {6 new Edgio.Metrics({7 token: '<TOKEN>'8 }).collect()9 }10 </script>11 <script src="https://rum.edgio.net/latest.js" defer onload="initEdgioRum()"></script>12 <script src="/__edgio__/prefetch/install.js" defer></script>13 </body>`14 )15 return new Response(html, originResponse)16}Predictive Prefetching also requires a rule that applies the Set Max Age (max_age) and Set Service Worker Max Age (service_worker_max_age) features to the pages that will be prefetched.
-
Deploy your changes to this environment by running the following command from your property’s root directory:Bash1edgio deploy
Script Tag and Google Tag Manager
Add Core Web Vitals tracking by adding the following code to each page in your application:
Script
1<script defer>2 function initEdgioRum() {3 new Edgio.Metrics({4 token: '<TOKEN>' // Get your token from the Edgio Console5 }).collect()6 }7</script>8<script src="https://rum.edgio.net/latest.js" defer onload="initEdgioRum()"></script>
NPM or Yarn
Install the Core Web Vitals library by running the following npm or yarn command:
Bash
1npm install --save @edgio/rum
Add the following code to your application’s browser bundle:
JavaScript
1import {Metrics} from '@edgio/rum';23new Metrics({4 token: '<TOKEN>', // Get your token from the Edgio Console5}).collect();
Tie URLs to Page Templates
Tie URLs to page templates by passing an optional
router
parameter to Metrics
.Define page labels by adding a route for each page template:
Bash
1<script defer>2 function initEdgioRum() {3 new Edgio.Metrics({4 token: '<TOKEN>', // Get your token from the Edgio Console56 // assign a page label for each route7 router: new Edgio.Router()8 .match('/', ({ setPageLabel }) => setPageLabel('home'))9 .match('/p/:id', ({ setPageLabel }) => setPageLabel('product'))10 .match('/c/:id', ({ setPageLabel }) => setPageLabel('category'))11 }).collect()12 }13</script>14<script src="https://rum.edgio.net/latest.js" defer onload="initEdgioRum()"></script>
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
:JavaScript
1<script>2 function initEdgioRum() {3 new Edgio.Metrics({4 token: '<TOKEN>', // Get your token from the Edgio Console5 pageLabel: document.title ? document.title : "(No title)",6 }).collect()7 }8 var rumScriptTag = document.createElement('script')9 rumScriptTag.src = 'https://rum.edgio.net/latest.js'10 rumScriptTag.setAttribute('defer', '')11 rumScriptTag.type = 'text/javascript'12 rumScriptTag.onload = initEdgioRum13 document.body.appendChild(rumScriptTag)14</script>
Track Additional Data
You can tie the following data to Core Web Vitals:
JavaScript
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 individually4 // rather than adding it to the main application template.5 pageLabel: 'home',67 // The version of your application that is running.8 appVersion: 'v1.0.0',910 // Whether or not the page was served from the CDN cache, if this is known.11 // This is automatically set for sites that are deployed on Edgio.12 cacheHit: true | false,1314 // The country code in which the browser is running. This is often provided by CDNs15 // as a request header that can be embedded in your script tab by your application code.16 // This is automatically set for sites that are deployed on Edgio.17 country: 'US',18})