
Product
Introducing Socket Scanning for OpenVSX Extensions
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.
@benshi.ai/impressions-detector
Advanced tools
Framework agnostic library to detect viewable impressions
This library tracks viewable impressions. According to the Interactive Advertising Bureau (IAB) and Media Rating Council (MRC), an screen element is counted as viewable when at least 50% of its area is visible on the screen for at least one second.
The implementation is based in latest web APIs, like MutationObserver and IntersectionObserver. It trigger an event for those elements that are detected as viewable impression, with next constraints:
start and restart/close), elements are only reported once. If the user scrolls the view and then come back to the original position, the elements won't be triggered again.viewable, it won't trigger an event even if the sum of times is higher)The library triggers an event whenever an item is detected as viewable impression.
Given an HTML structure like this:
<div class="container">
<div
class="item-element"
data-log-id='unique-element-id'
data-key1="value11"
data-key2="value21">
</div>
<div
class="item-element"
data-log-id='unique-element-id'
data-key1="value12"
data-key2="value22">
</div>
</div>
import ImpressionsDetector, { ImpressionEventType } from "@benshi.ai/impressions-detector";
const impressionsDetector = new ImpressionsDetector()
const yourData = {
anyKey: "anyValue"
}
impressionsDetector.start("container", "item-element", yourData)
impressionsDetector.on(ImpressionEventType.Impression, (dataset, yourData) => { /* ... */}
Note the callbacks parameters dataset and appData:
dataset contains all the elements within the HTML element dataset. For example, for the first div it will contain:
{
"id": "unique-element-id"
"key1": "value11"
"key2": "value21"
}
yourData is an arbitrary object. Depending on the application use case it may be interesting to share information between the code that initializes the impressionDetector and the code that receives the eventsnote that the key
log-idis mandatory
Some parameters may be adapted to the application needs. The configuration options accepted by ImpressionsDetector are:
const options = {
triggerInterval: 2000,
keepVisibleTimeout: 1000,
intersectionThreshold: 0.9
}
}
const impressionsDetector = new ImpressionsDetector(options)
where:
triggerInterval [_default: 2000] The library triggers events each triggerInterval milliseconds.keepVisibleTimeout [_default: 1000] Time that an item must remain visible to trigger an event. TimeintersectionThreshold [_default:0.9] Porcentage of visible area to be considered an impression.start(containerClassname, itemClassname, applicationData). The container defined by containerClassname must exist at the time of calling this function. itemClassname refers to any child element, regardless it exists or not at the moment of calling this function.restart(applicationData). The session is restarted, that is, items that have been already triggered will be triggered again if they remain the needed time in the screen. You can pass the same applicationData or other.close. Close the session. No events will be triggered from this moment.FAQs
Framework agnostic library to detect viewable impressions
We found that @benshi.ai/impressions-detector demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.

Product
Bringing supply chain security to the next generation of JavaScript package managers

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies