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.
➡️ Have a look to our Hardware Intelligence core concepts to understand what are BDP and AIR indices.
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/libs/1/sd-metrics.js';
const sd = new SdMetrics({
// Replace <PRIVATE_URL> with your endpoint URL
endpoint: '<PRIVATE_URL>',
});Get BDP and AIR
The BDP adnd AIR are computed at the start of the session taking into account the real load of the device (other applications running concurrently with the browser, background tasks, number of tabs, state of the battery and the power saving mode).
Thus, we provide several ways to get the BDP and AIR according to your use case.
Catch BDP and AIR during loading time
In order to get the BDP or AIR during the loadtime of the application use that code that you have to run in an asynchronous function.
- For BDP
const bdp = await sd.bdp.get()- For AIR
const air = await sd.air.get()By default, the await for BDP or AIR is blocking. To prevent a network issue you can add to the get
call a timeout and a default parameter. If BDP or AIR is not available before the timeout value time,
the default value is used.
For example, for BDP:
const bdp = await sd.bdp.get({ timeout: 100, default 1 })Get BDP and AIR value at runtime
In order to get the BDP or AIR value at runtime, use bdp.once or air.once event handler.
this handlers will be called only once.
- For example for BDP
sd.bdp.once((bdp) => {
// use bdp
});- For example for AIR
sd.air.once((air) => {
// use air
});