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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@footprintjs/sdk-vue2

v1.1.0

Published

footprint 埋点 SDK Vue2 适配:路由 mixin + v-log 指令

Readme

使用

下面展示了在vue2vue-router@3的项目中使用埋点sdk的方式

定义路由

import Router from 'vue-router'
import { injectLogMixin } from "@footprintjs/sdk-vue2";

const createLogParams = (name: string = '', pv = true, duration = false, async = false) => ({
  name,
  pv,
  duration,
  async
})

const routes = [
  {
    path: '/',
    name: 'index',
    component: injectLogMixin(() => import('../views/index.vue')),
    meta: {
      log: createLogParams('index')
    }
  },
  {
    path: '/list',
    name: 'list',
    component: injectLogMixin(() => import('../views/list.vue')),
    meta: {
      log: createLogParams('list')
    }
  },
  {
    path: '/detail/:id',
    name: 'detailPage',
    component: injectLogMixin(() => import('../views/detail.vue')),
    meta: {
      log: createLogParams('detailPage')
    }
  },
]

export default new Router({
  routes
})

渲染路由

new Vue({
  el: "#app",
  // @ts-ignore
  router,
  render: (h) => h(App)
}).$mount()

初始化埋点sdk

import { init } from "../../src/index";
import router from './router'

export async function initLog() {

  // const host = 'http://localhost:1546'
  // const reportPostApi = `${host}/log/report`

  const getCurrentRoute = () => {
    return router.currentRoute
  }

  const sendLog = (data: any) => {
    data = {
      ...data,
      eventTime: +new Date()
    }
    data.extra = JSON.stringify(data.extra)

    console.log('send log', data)
    // return sendBeacon(reportPostApi, data)
  }

  await init({
    sendLog,
    getCurrentRoute,
  })
}

简单场景:自动上报pv和停留

通过injectLogMixin注入的路由组件会根据meta.log配置自动上报

复杂场景:设置公共参数、同一路由组件参数变化、点击事件


<script>
import { getCurrentTrackTask } from "@footprintjs/sdk-vue2";

export default {
  name: "detail",
  computed: {
    id() {
      return this.$route.params.id
    }
  },
  created() {
    const trackTask = getCurrentTrackTask()
    trackTask.setCommonExtra({ id: this.id })
  },
}
</script>

此外还定义了一些自定义指令

  • v-log.exposure.once曝光事件,当节点出现在屏幕内时上报
  • v-log.click点击事件,点击某个节点时上报
<h2>scroll exposure event</h2>
<div class='scroll'>
<div class='scroll-item' v-for='item in 10' v-log.exposure.once="{key:'some-img', extra:{no:item}}"></div>
</div>
<h2>click event</h2>
<button v-log.click="{key:'btn'}">click me</button>