npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nisyaban/impression

v0.2.0

Published

Easy to use impression event.

Downloads

6

Readme

build-test

Impression is a gallery of easy to use scripts to have HTML DOM element 'impression' event on your web pages.

Usage

Pick one that you need, add CSS class 'impression' (overridable default) to elements you want to track, and then add listeners for the event just as you use click event or any other events.

One Time Impression

(92+/impression.min.js -> 0.5KB)

To fire impression event one time when an element becomes visible, use one of the following CDNs.

One Time Impression + Off

(92+/impression+off.min.js -> 0.8KB)

To fire impression event one time when an element becomes visible and impressioff event one time when an element is no longer visible, use one of the following CDNs.

CDNs

<script src='https://cdn.jsdelivr.net/npm/@setyadi/impression/dist/92+/impression.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/@setyadi/impression/dist/92+/impression+off.min.js'></script>
<script src='https://unpkg.com/@setyadi/impression/dist/92+/impression.min.js'></script>
<script src='https://unpkg.com/@setyadi/impression/dist/92+/impression+off.min.js'></script>

Configuration

By default, the script would just work provided that you agree with the default values. But if you want to use something different, you can override the defaults by adding the following attributes on the script tag.

| Attributes | Description | Default Value | |--------------------|--------------------------------------------------------------------------------------------------------|---------------| |elements-selector | CSS selector that would match the elements. | '.impression' | |visible-fraction | Visible fraction of elements that would trigger impression event. | 0.5 | |visible-fractioff | Visible fraction of elements that would trigger impressioff event after impression event is triggered. | 0.0 |

Example of Overriding Defaults

<script
  src='https://cdn.jsdelivr.net/npm/@setyadi/impression/dist/92+/impression+off.min.js'
  elements-selector='[data-track="MyImpression"]'
  visible-fraction=0.8
  visible-fractioff=0.1>
</script>

Demo

To run the demo, clone this repo, cd to it, yarn install and then pick the demo page you want to see.

Vanilla JS

yarn demo

Svelte

yarn demo:svelte

They basically demo the same thing, but you can look at the source code to see how they use impression.

Disclaimer

Based on CanIUse, the above scripts should work for 92.x% or more of users worldwide. For the other times when it's not working, it doesn't break the page.

Roadmap

  • Reocurring impressions (just like one time impression but every time).
  • Impression events for elements created dynamically.
  • Support old browsers.

License