JavaScript & Frameworks
This guide is designed for developers integrating ScaleDynamics directly into modern JavaScript applications (such as React, Vue, Angular, or Vanilla JS modules).
Before beginning the integration, you must obtain your private data stream endpoint URL from your dedicated ScaleDynamics account team. This URL is unique to your report and must remain confidential. In the code snippets below, replace <PRIVATE_URL> with this exact endpoint.
Phase 1: The 24-Hour Audit (sd-agent.js)
Deploy the passive telemetry agent to gather hardware insights across your traffic without altering your user experience or application state.
1. Import and Setup the Agent
Add the following code to your application's entry point (e.g., main.js, index.js, or App.jsx). The agent is loaded asynchronously, so your application never waits for it: sdAgent is a promise that resolves to the configured agent once it is loaded.
const sdAgent = import('https://cdn.scaledynamics.com/libs/2/sd-agent.js')
.then(({ sdAgent: agent }) => {
agent.config({
// Replace <PRIVATE_URL> with your private data stream endpoint URL
endpoint: '<PRIVATE_URL>',
});
return agent;
})
.catch((error) => {
// If the agent cannot be loaded, use a no-op agent so that later calls do nothing
console.warn('sd-agent could not be loaded:', error);
return { config() {}, send() {} };
});Have a look to sd-agent.js API Reference to get a description of all available APIs.
2. Optional: Domain Filtering & Environment Control
To restrict monitoring to specific environments, you can configure domain filtering.
Method 1: Server-Side JSON Configuration You can provide a JSON configuration file to your ScaleDynamics account representative to filter domains server-side, without cluttering your application logic.
{
"domain": {
"includes": [ ".*production-domain\\.com.*" ],
"excludes": [ ".*staging-domain\\.com.*" ]
}
}Note: A domain is monitored if and only if it matches at least one regular expression in includes AND does not match any regular expression in excludes. Exclusion rules always take precedence.
Method 2: Environment Control via CI/CD
To control when the agent is active based on your build environment, pass your <PRIVATE_URL> via a CI/CD environment variable (e.g., process.env.VITE_SD_ENDPOINT). If the variable is empty "" or undefined (like in local development or staging), the agent disables itself automatically.
Phase 2: Production Integration (sd-metrics.js)
Once your 24-hour audit is complete, replace the passive Phase 1 agent with the active Phase 2 execution engine. This allows your JavaScript application to consume the hardware scores dynamically.
Load the Metrics Engine
Add the following code to your application's entry point. The module is loaded asynchronously, so your application never waits for it: sd is a promise that resolves to your SdMetrics instance once it is loaded. If the module cannot be loaded, the promise rejects.
const sd = import('https://cdn.scaledynamics.com/libs/1/sd-metrics.js')
.then(({ SdMetrics }) => new SdMetrics({
// Replace <PRIVATE_URL> with your private data stream endpoint URL
endpoint: '<PRIVATE_URL>',
}));
// use sd-metrics API, e.g. const bdp = await sd.then((metrics) => metrics.bdp.get());
// ...Have a look to sd-metrics.js API Reference to get a description of all available APIs.