lighthouse-plugin-publisher-ads/audits/cumulative-ad-shift.js
/**
   * Computes the ad shift score for the page.
   * @param {LH.TraceEvent[]} shiftEvents
   * @param {LH.TraceEvent[]} scriptEvents
   * @param {Artifacts['IFrameElement'][]} ads
   * @param {number} tagLoadTs
   */
Computes the ad shift score for the page.
Computes the ad shift score for the page .
static compute(shiftEvents, scriptEvents, ads, tagLoadTs) {
    let cumulativeShift = 0;
    let numShifts = 0;
    let cumulativeAdShift = 0;
    let numAdShifts = 0;
    let cumulativePreImplTagAdShift = 0;
    let numPreImplTagAdShifts = 0;
    for (const event of shiftEvents) {
      if (!event.args || !event.args.data || !event.args.data.is_main_frame) {
        continue;
      }
      cumulativeShift += event.args.data.score;
      numShifts++;
      if (this.isAdExpansion(event, ads) ||
          this.isAttributableToTask(event, scriptEvents)) {
        cumulativeAdShift += event.args.data.score;
        numAdShifts++;
        if (event.ts < tagLoadTs) {
          cumulativePreImplTagAdShift += event.args.data.score;
          numPreImplTagAdShifts++;
        }
      }
    }
    return {
      cumulativeShift,
      numShifts,
      cumulativeAdShift,
      numAdShifts,
      cumulativePreImplTagAdShift,
      numPreImplTagAdShifts,
    };
  }
static compute ( shiftEvents , scriptEvents , ads , tagLoadTs ) { let cumulativeShift = 0 ; let numShifts = 0 ; let cumulativeAdShift = 0 ; let numAdShifts = 0 ; let cumulativePreImplTagAdShift = 0 ; let numPreImplTagAdShifts = 0 ; for ( const event of shiftEvents ) { if ( ! event . args || ! event . args . data || ! event . args . data . is_main_frame ) { continue ; } cumulativeShift += event . args . data . score ; numShifts ++ ; if ( this . isAdExpansion ( event , ads ) || this . isAttributableToTask ( event , scriptEvents ) ) { cumulativeAdShift += event . args . data . score ; numAdShifts ++ ; if ( event . ts < tagLoadTs ) { cumulativePreImplTagAdShift += event . args . data . score ; numPreImplTagAdShifts ++ ; } } } return { cumulativeShift , numShifts , cumulativeAdShift , numAdShifts , cumulativePreImplTagAdShift , numPreImplTagAdShifts , } ; }
Computes the ad shift score for the page.
Computes the ad shift score for the page .
// @ts-ignore // @ts-ignore // @ts-ignore