API Reference: sd-metrics
The sd-metrics script evaluates the physical hardware and exposes the results via an asynchronous JavaScript API.
Because modern Single Page Applications (SPAs) and ad scripts often load concurrently with third-party libraries, the Impulse Engine provides robust listener methods (.on, .once, .get) to guarantee you never encounter a race condition or an undefined variable.
Metric names
- AdTech Variables:
ìnventory_tier,ìnventory_tier. Have a look to AdTech metrics references for more details. - Engineering Metrics:
bdp,mdc,air. Have a look to Engineering metrics references for more details.
Metric Methods
Each metric object exposes three methods to handle data retrieval based on your application's architecture.
1. .get()
Returns a standard JavaScript Promise that resolves with the metric's value as soon as the hardware evaluation is complete. Ideal for async/await workflows.
Example:
async function initializeApp() {
try {
const bdpScore = await window.sd.bdp.get();
if (bdpScore > 4.0) {
await loadHeavy3dModel();
}
} catch (error) {
console.warn('Hardware profiling timeout, falling back to safe UI.');
}
}2. .once(callback)
Fires the provided callback function exactly one time when the metric is resolved. This is highly recommended for triggering initial load logic (like setting Google Ad Manager targeting).
Example:
window.sd.inventory_tier.once((tier) => {
// Push to Ad Server immediately upon resolution
googletag.cmd.push(function() {
googletag.pubads().setTargeting('sd_inventory_tier', tier.toString());
});
});3. .on(callback)
Subscribes a listener to the metric. While hardware limits rarely change during a single page view, this method is useful for frameworks like React or Vue where you may want to bind the metric to a reactive state variable that persists across client-side navigations.
Example:
// React useEffect hook
useEffect(() => {
if (window.sd) {
window.sd.mdc.on((threads) => {
setWorkerCount(threads);
});
}
}, []);