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

peeping-tom

v0.0.6

Published

Event delegate for user journey and interaction tracking.

Downloads

50

Readme

peeping-tom

Event delegate for user journey and interaction tracking. Provides performant and configurable event capture via an easy to maintain object format.

See examples for demonstration.

Attribute

<button data-peeping-tom="signup"></button>

data-peeping-tom: String

Unique key corresponding to a target object that should be defined using the properties described below.

Methods

watch()

The peepingTom.watch() method instantiates the library using provided parameters.

Syntax

peepingTom.watch(targets[, config]);

Parameters

  • targets: Object

    • key: String

      Object key used to map functionality to element(s) containing a corresponding data-peeping-tom HTML attribute. Supports regular expression anchors to target element collections using affixes ^prefix-, -suffix$.

    • value: Object

      • events: String | String[]

        Event(s) to track: 'click', 'view'.

      • data: Interface | Function | peepingTom.Deferred

        • Interface any data type to be provided as an argument to fn.
        • Function definition that is invoked upon event occurrence. Provided event String and node Element arguments.
        • peepingTom.Deferred class can be used to create an asynchronous, mutual dependency between event occurrence and invocation of the resolve method.
      • fn: Function

        Function definition to be invoked.

      • visible: Number |Optional

        Floating point number representing a specific visibility threshold at which to invoke the 'view' event. Expects positive value between 0.0 and 1.0, where 1.0 equals entire element visibility.

  • config: Object |Optional

    • dataset: String

      Dataset name to override the default data-peeping-tom HTML attribute. Each to their own!

    • root: Element

      Top-level element on which to capture events. Defaults to document.body.

    • visible: Number

      Global element visibility threshold. Floating point number representing a specific visibility threshold at which to invoke the 'view' event. Expects positive value between 0.0 and 1.0, where 1.0 equals entire element visibility. Defaults to 0.8.

resolve()

Sets data property value asynchronously.

Requires: Asynchronous data declaration using — data: new peepingTom.Deferred.

Syntax

peepingTom.resolve(key, data);

Parameters

  • key: String

    String matching a targets property key that was declared with a Deferred data value.

  • data: Interface | Function

    Any data value that you wish to provide to the given fn. If a value of type Function is provided, it will be invoked and the returned value passed to fn.

disconnect()

Removes event listeners and observers.

Syntax

peepingTom.disconnect();

Examples

targets: Object

const targets = {
    'signup': {
        events: 'click',
        data: {
            'event': 'signup-click',
            'pageCategory': 'signup',
            'visitorType': 'high-value',
        },
        fn: (data) => dataLayer.push(data),
    },
    '^recommended-product-': {
        events: ['click', 'view'],
        data: new peepingTom.Deferred,
        fn: (data) => dataLayer.push(data),
        visible: 0.6,
    }
};

watch: Function

peepingTom.watch(targets);

resolve: Function

peepingTom.resolve('^recommended-product-', { type: 'previously-viewed' });

Compatibility

Troubleshooting

  • Click event capture: If click events are being blocked other elements. Try applying the CSS rule pointer-events: none; to the overlapping elements. This will allow pointer events to pass through to the desired target.