Skip to content

Commit

Permalink
FORMS-17007 modifying cwv audit worker to add extra info about forms
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul Kumar Singh authored and Rahul Kumar Singh committed Nov 8, 2024
1 parent eb62c22 commit d48de70
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/cwv/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import { wwwUrlResolver } from '../common/audit.js';

const DAILY_THRESHOLD = 1000;
const INTERVAL = 7; // days
const CWV_QUERIES = [
'cwv',
'formVitals',
];

export async function CWVRunner(auditUrl, context, site) {
const rumAPIClient = RUMAPIClient.createFrom(context);
Expand All @@ -27,9 +31,19 @@ export async function CWVRunner(auditUrl, context, site) {
interval: INTERVAL,
granularity: 'hourly',
};
const cwvData = await rumAPIClient.query('cwv', options);
const cwvData = await rumAPIClient.queryMulti(CWV_QUERIES, options);
const auditResult = {
cwv: cwvData.filter((data) => data.pageviews >= DAILY_THRESHOLD * INTERVAL),
cwv: cwvData.cwv.filter((data) => data.pageviews >= DAILY_THRESHOLD * INTERVAL)
.map((cwvItem) => {
// Find a matching formVital by URL
const matchingFormVital = cwvData.formVitals.find(
(formVital) => formVital.url === cwvItem.url,
);

// eslint-disable-next-line max-len
const hasForm = matchingFormVital ? (matchingFormVital.isFormViewPresent || matchingFormVital.isFormSubmitPresent) : false;
return { ...cwvItem, hasForm };
}),
auditContext: {
interval: INTERVAL,
},
Expand Down

0 comments on commit d48de70

Please sign in to comment.