Direct HTML Snippet
Before beginning the integration for either phase, 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. Insert the following HTML snippet directly into the <head> of your pages.
Core Agent Snippet
<script
type="module"
async
src="https://cdn.scaledynamics.com/libs/2/sd-agent.js">
</script>
<script>
window.sdAgent = window.sdAgent || {
_q: [],
send: function() {
window.sdAgent._q.push([Date.now(), window.location.href, arguments])
},
config: function () { window.sdAgent._c = arguments },
};
sdAgent.config({
// Replace <PRIVATE_URL> with your actual agent URL.
endpoint: '<PRIVATE_URL>',
});
</script>Optional: Conversion Detection & Domain Filtering
To correlate hardware performance (like the BDP score) with your actual business outcomes, or to restrict monitoring to specific environments (like Production only), you can configure conversion detection and domain filtering.
Method 1: Client-Side Conversion Events If you prefer to trigger conversions programmatically (e.g., inside a React component or button click handler) rather than relying on URL patterns, you can execute the following method anywhere in your code after the agent has initialized:
sdAgent.send('conversion_done');Have a look to sd-agent.js API Reference to get a description of all available APIs.
Method 2: Server-Side JSON Configuration You can define a JSON configuration file and provide it to your ScaleDynamics account representative to enable it on your endpoint server. This allows you to match conversions via URL patterns and filter domains without changing your frontend code.
{
"conversion": {
"regexps": [ ".*\\/checkout\\/success.*" ]
},
"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 3: Environment Control via CI/CD
To dynamically control when the agent is active based on your build environment, pass your <PRIVATE_URL> via a CI/CD environment variable. If the variable is passed as an empty string "" or undefined (e.g., during local development), the agent disables itself automatically.
Phase 2: Production Integration (sd-metrics.js)
Once your 24-hour audit is complete, replace the passive Phase 1 HTML snippet with the active Phase 2 execution engine. This script evaluates the hardware and exposes the metrics to your browser environment.
Insert the following module script as high as possible in your <head>, ideally before your Ad Server or heavy JS frameworks initialize.
<script type="module">
import { SdMetrics } from 'https://cdn.scaledynamics.com/libs/1/sd-metrics.js';
window.sd = new SdMetrics({
// Replace <PRIVATE_URL> with your actual agent URL.
endpoint: '<PRIVATE_URL>',
});
// use sd-metrics API
...
</script>Have a look to sd-metrics.js API Reference to get a description of all available APIs.