Scores

Fetch scores from Google Page Speed API


When to use it?

This asynchronous function retrieves page speed scores for a specified URL via the Lighthouse API, providing a valuable tool for marketing teams and developers to monitor page performance.

How To use it?

bstf.scores({
    url: 'https://google.com',
    apiKey: 'YOUR-GOOGLE-API-KEY',
    showOnPage: true
})

Configuration options

  • URL string - URL of the page for which the speed scores are to be fetched.

  • apiKey: string - An API key required to authenticate requests to the page speed scores service.

  • showOnPage: boolean - A boolean indicating whether the fetched scores should be displayed on the page.

💡

apiKey can be generated here

Having showOnPage enabled through a query parameter setup like this is useful.

function getQueryParamValue(param) {
    const urlSearchParams = new URLSearchParams(window.location.search);
    return urlSearchParams.get(param);
}
const showOnPage = getQueryParamValue('bstfscore') === 'true';
bstf.scores({
    url: 'https://google.com',
    apiKey: 'YOUR-GOOGLE-API-KEY',
    showOnPage: showOnPage
})

Using this setup, you can navigate to yourwebsite.com?bstfscore=true to activate the GPS feature, which will be displayed in the bottom left corner of your website. It uses a color scheme similar to that of the Lighthouse Report.