The perByteTrace() function is an extension of perByte() which allows for certain inputs to be adjusted. This allows for more accurate, scenario specific estimates to be produced using the Sustainable Web Design Model.
The perByteTrace() function accepts the following parameters:
number boolean Optional: if the data being measured is served from a green web host.object Optional - A JavaScript object containing any Sustainable Web Design specific variables to be change.options parameterThe options parameter can contain any of the following keys. These can be used to adjust the values used by the Sustainable Web Design Model's calculation.
greenHostingFactor number representing the portion of hosting services powered by renewable or zero-carbon energy, between 0 and 1. If the green hosting boolean above is set to true then the greenHostingFactor will always be 1.gridIntensity Optional – an object that can contain the following keys:
device Optional – A number representing the carbon intensity for the given segment (in grams per kilowatt-hour). Or, an object, which contains a key of country and a value that is an Alpha-3 ISO country code.dataCenter Optional – A number representing the carbon intensity for the given segment (in grams per kilowatt-hour). Or, an object, which contains a key of country and a value that is an Alpha-3 ISO country code.networks Optional – A number representing the carbon intensity for the given segment (in grams per kilowatt-hour). Or, an object, which contains a key of country and a value that is an Alpha-3 ISO country code.Below is an example which shows both kinds of accepted inputs in use.
const options = {
gridIntensity: {
device: 565.629, // Here we have set the grid intensity at the device location using a number.
dataCenter: { country: "TWN" }, // Here we have set the data center grid intensity using a country code.
networks: 442,
},
};
The perByteTrace() function returns an object with the following keys:
co2 - A number representing the carbon emissions calculated in gramsgreen - A boolean indicating whether the calculation was based on data being hosted in a green data centervariables - An `object`` that details all the other variables used in the calculation. This object will include:
description - A static string explaining what is being shown.bytes - A number showing the bytes that were passed into the function.greenHostingFactor Sustainable Web Design Model v4 only - A number representing the portion of hosting services powered by renewable or zero-carbon energy.gridIntensity – an object that can contain the following keys:
device – A number representing the carbon intensity (in grams per kilowatt-hour) used in the calculation.dataCenter – A number representing the carbon intensity (in grams per kilowatt-hour) used in the calculation.networks – A number representing the carbon intensity (in grams per kilowatt-hour) used in the calculation.