sd-metrics.js Installation Guide
This guide details how to integrate the ScaleDynamics client-side speedpower script into your codebase. Once deployed, you will be able to catch BDP and AIR events in your frontend code, allowing you to build dynamic, hardware-aware applications with just a few lines of code. You can also use it to extend your current analytics (GA4, amplitude, ...) with BDP and AIR new dimensions.
Get your private data stream endpoint url
Before digging into the integration of the script
you need to get your private endpoint
url. Ask your
dedicated ScaleDynamics account team to get one.
This URL is referred to as <PRIVATE_URL>
in the following documentation.
Note that this url has been generated only for you and you must treat it as confidential and do not share it publicly.
Add the script to your web application
The first step is to integrate our agent in your code base using a Javascript integration as this:
import { SdMetrics } from 'https://cdn.scaledynamics.com/1/sd-metrics.js';
const sd = new SdMetrics({
// Replace <PRIVATE_URL> with your endpoint URL
endpoint: '<PRIVATE_URL>',
});Catch BDP at runtime
In order to get the bdp at runtime, use bdp.once event handler of the script.
The bdp.once callback fires asynchronously. Your application must continue its initialization sequence and should run without waiting for this event to resolve.
For example, to configure your UI:
sd.bdp.once((bdp) => {
if (bdp <= 2) {
switchToLiteUX();
}
if (bdp === 4) {
switchToAdvancedUX();
}
});You can also use the same way to push the BDP as a new dimension in your Analytics tool (GA4, amplitude...).
Catch AIR at runtime
In order to get the bdp at runtime, use air.once event handler of the script.
The bdp.air callback fires asynchronously. Your application must continue its initialization sequence and should run without waiting for this event to resolve.
For example, to congigure your UI:
sd.air.once((bdp) => {
if (air === 4) {
useEdgeAIModel();
}
});You can also use the same way to push the AIR as a new dimension in your Analytics tool (GA4, amplitude...).