【埋点】前端埋点打点库数据统计库


前言

为什么要埋点?现在的互联网公司越来越关注转化、新增、留存,而不是简单的统计PV、UV。而完整的数据采集是一切的前提。

埋点包括在IOS、Android、H5、小程序等前端埋点,也包括后端业务埋点。这里仅仅讲讲这些年和产品经理、运营撕逼上百个回合的前端埋点内容。

一、buried-point-sdk是什么?

是一款开箱即用的前端页面埋点JSSDK,可以对指定元素行为、js报错、页面展示、hash变更、history变更等行为进行数据打点上报,支持自定义上报接口地址

官网:https://www.npmjs.com/package/mingle-track-sdk

二、使用和例子

1.如何使用

(一)、第一种:umd方式

(1)、引入文件
 <script src="http://luckycola.com.cn/public/sources/tracker/dist/index.js"></script>
(2)、使用
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./dist/index.js"></script>
</head>
<body>
    <button id="mybtn">提交</button>
    <button id="mybtn">提交22</button>
    <button id="mybtn" target-key="buttom">提交33</button>

    <script>
        window.onload = function () {
         // 自动上报
            let instance = new tracker({
            // 合法验证的唯一key标识,必填,如果您还没有,请前往官网(http://luckycola.com.cn)获取
                colaKey: 'NaTu16773439832446NZH6',
                // 当前网站是否为https
                isHttps: false,
                // 用户标识
                uuid: '111',
                // 数据上报接口
                requestUrl: 'http://localhost:8080',
                // 是否进行history行为(history-pv)进行打点统计,包括pushState、replaceState、popstate行为
                historyTracker: true,
                // 是否进行hash行为(hash-pv)进行打点统计,包括hashchange行为
                hashTracker: true,
                // 对具有target-key属性的dom进行行为打点,行为包括(['click', 'dblclick', 'contextmenu', 'mousedown', 'mouseup', 'mouseenter', 'mouseout', 'mouseover'])
                domTracker: true,
                // 自定义参数
                extra: {
                    name: 'zhoumingle'
                },
                // 是否进行对报错进行捕获打点,分为两类: 1、捕获js报错,targetKey=message,event=error; 2、捕获promise 错误, targetKey=reject,event=promise
                jsError: true
            });
   			// 主动上报
            document.getElementById('mybtn').onclick = function() {
                instance.setUserId('99999');
                instance.setExtra({
                    tesh: 'heo!!!'
                });
                instance.sendTracker({
                    targetKey: '提交',
                    event: 'click'
                });
                 throw new Error('error');
            }
        }
    </script>
</body>
</html>

(一)、第二种:npm方式

(1)、下载包
npm i buried-point-sdk
(2)、使用
import tracker from 'mingle-track-sdk';
 // 自动上报
let instance = new tracker({
// 合法验证的唯一key标识,必填,如果您还没有,请前往官网(http://luckycola.com.cn)获取
                colaKey: 'NaTu16773439832446NZkH6',
                // 当前网站是否为https
                isHttps: false,
                // 用户标识
                uuid: '111',
                // 数据上报接口
                requestUrl: 'http://localhost:8080',
                // 是否进行history行为(history-pv)进行打点统计,包括pushState、replaceState、popstate行为
                historyTracker: true,
                // 是否进行hash行为(hash-pv)进行打点统计,包括hashchange行为
                hashTracker: true,
                // 对具有target-key属性的dom进行行为打点,行为包括(['click', 'dblclick', 'contextmenu', 'mousedown', 'mouseup', 'mouseenter', 'mouseout', 'mouseover'])
                domTracker: true,
                // 自定义参数
                extra: {
                    name: 'zhoumingle'
                },
                // 是否进行对报错进行捕获打点,分为两类: 1、捕获js报错,targetKey=message,event=error; 2、捕获promise 错误, targetKey=reject,event=promise
                jsError: true
            });
			// 主动上报
            document.getElementById('mybtn').onclick = function() {
                instance.setUserId('99999');
                instance.setExtra({
                    tesh: 'heo!!!'
                });
                instance.sendTracker({
                    targetKey: '提交',
                    event: 'click'
                });
                 throw new Error('error');
            }

注意:如果您还没有colaKey请前往官网获取:
官网地址:http://luckycola.com.cn

2.使用例子

在线demos:点击查看>>>

如下(示例):

(1)、主动按钮行为的上报

在这里插入图片描述

(2)、自动按钮行为的上报

在这里插入图片描述

(3)、hash行为的上报

在这里插入图片描述

(4)、history行为的上报

在这里插入图片描述

(5)、前端报错行为的上报

在这里插入图片描述


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LuckyCola2023

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值