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

vue-trackevent

v1.0.1

Published

数据埋点通用指令,支持和第三方 SDK 集成,如百度统计、友盟统计、GA 等

Downloads

10

Readme

vue 数据埋点指令

数据埋点通用指令,支持和第三方 SDK 集成,如百度统计、友盟统计、GA 等

安 装

$ npm install vue-trackevent --save

使 用

// main.js
import Vue from 'vue';
import VTrackevent from 'vue-trackevent';

Vue.use(VTrackevent, {
	callback(data, e) {
		console.log(data, e);
	},
	debug: false,
});
<template>
	<button v-trackevent="['hello','world']">DEBUG</button>
</template>

属 性

| 属性 | 说明 | | :------: | :--------------------------------------------------: | | init | 初始化时调用的函数,只调用一次,主要是配合第三方 SDK | | callback | 元素触发后的回调,data 为绑定的数据,e 为事件源对象 | | debug | 是否处于调试环境,默认 false |

数 据

v-trackevent 支持绑定 可被克隆的 Javascript 对象 ,如 Number、String、Array、Object、Boolean

默认元素触发方式为点击 click,事件绑定方式为追加

如果需要更改触发方式,如mouseover,则需要按下述要求修改传入的值

v-trackevent="{event:'mouseover',data:'hello world'}"

即需要传入{event,data}的 object 数据

点 击 触 发

<template>
	<button v-trackevent="{event:'click',data:['hello','world']}">DEBUG</button>
</template>

等同于

<template>
	<button v-trackevent="['hello','world']">DEBUG</button>
</template>

鼠标进入触发

<template>
	<button v-trackevent="{event:'mouseenter',data:['hello','world']}">DEBUG</button>
</template>

注意 mouseenter 和 mouseover 的区别

文本改变触发

<template>
	<input type="text" v-trackevent="{'event':'change',data:['hello world']}" />
</template>
// callback(data,e) 中,e.target.value可以取到输入框的值

第三方 SDK

百度统计

官网:https://tongji.baidu.com/web/welcome/login

// main.js
import Vue from 'vue';
import VTrackevent from 'vue-trackevent';

Vue.use(VTrackevent, {
	init() {
		window._hmt = window._hmt || []; // 挂载到window上
		const hm = document.createElement('script');
		hm.src = `https://hm.baidu.com/hm.js?xxx`; // 百度统计应用id
		const s = document.getElementsByTagName('script')[0];
		s.parentNode.insertBefore(hm, s);
	},
	callback(data) {
		if (data instanceof Array && '_hmt' in window) {
			window._hmt.push(['_trackEvent'].concat(data)); // 上报信息
		}
	},
});

友盟统计

官网:https://www.umeng.com

// main.js
import Vue from 'vue';
import VTrackevent from 'vue-trackevent';

Vue.use(VTrackevent, {
	init() {
		window._czc = window._czc || []; // 挂载到window上
		const cz = document.createElement('script');
		cz.src = `https://v1.cnzz.com/z_stat.php?id=xxx&web_id=xxx`; // 友盟统计应用id
		const s = document.getElementsByTagName('script')[0];
		s.parentNode.insertBefore(cz, s);
	},
	callback(data) {
		if (data instanceof Array && '_czc' in window) {
			window._czc.push(['_trackEvent'].concat(data)); // 上报信息
		}
	},
});

Google Analytics (GA)

官网:https://analytics.google.com

如 百度统计 和 友盟统计