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

ua-trace

v1.0.14

Published

A resolution of collect dom data-attr and merge with config report(multi),Works in web browsers.

Downloads

29

Readme

ua-trace

A resolution of collect dom attribute and merge with config then report(multi),monitor appears in viewport and click event, Works in web browsers.

GET前端上报,主要解决滚动曝光及多个上报问题。

feature

  • auto encodeURIComponent value
  • auto detect elm in view
  • one set multi use

demo

Install

you can get it on npm

npm install ua-trace --save

Setup

Node(Browserify)

let UAtrace = require('ua-trace')

Browserumd

<script src="dist/ua-trace.js"></script>

Usage

The ua-trace lib do one thing, that if a element has data-ua-trace , when it appear in window or click,it value will be parse to json and merge with the config you identified

ua-trace只做一件事情,在曝光或点击的时候,把DOM里data-ua-trace的JSON配置与预定义的基础配置合并发送到订阅函数里

Class UATrace(option[object],config[object])

  • *option.url[requried] to report 上报地址
  • option.method default [get] with image,if [post] will use sendBeacon 上报方式
  • config the base config to report 基础配置

HTML

//Element must has attrbute data-ua-trace
<div data-ua-trace='{"key1":"once","a":1,"b":2}'></div>

//or js react
<div data-ua-trace={JSON.stringify({"key1":"once","a":1,"b":2})}'></div>

JS

UATrace.debug()
let imageGif = '/report.gif'
let boss6014 = new UATrace({url:imageGif,method:'post'},{id:6014})
// pick your data
boss6014.subscribe((data,type)=>{
    //one key shortcut: data-ua-trace='value'
    if(typeof(data) === 'string'){
            return {yourKey:data}
    }
    // expose or click
    if(type==='expose'){
        data.expose = 'expose'
    }

    return data
    //if return false will do nothing
})
boss6014.report({name:'tangentguo'})
//when subscribed click or inview will Request URL: http://report.com?a=1&b=2&expose=expose&id=6014

static UATrace.debug()

equal localStorage.setItem('debug', 'ua-trace')

  • default close
  • 'close' close

UATrace.update(config)

update your config

UATrace.subscribe([Function(data,type)])

  • data is the data-ua-trace parse to json
  • type is [click or expose],expose only fire once
  • you can pick your data by UATrace.subscribe, when return false do nothing

UATrace.report(object,[type])

report with js will go throw UATrace.subscribe

UATrace.reportDirect(object,[type])

report with js direct

UATrace.update(config)

UATrace.trigger()

when DOMContentLoaded scroll resize will be trigger detect elm inview, also you can trigger with this method yourself

priority config

配置的优先级 subscribe return > data-ua-trace > config

Browser Support

| | | | | | | |:---:|:---:|:---:|:---:|:---:|:---:| | Latest ✔ | Latest ✔ | Latest ✔ | 9+ ✔ | Latest ✔ | Latest ✔ |

License

MIT License