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

web-logs-sdk

v1.1.4

Published

log sdk for web

Downloads

1

Readme

change log

v1.1.0 无埋点+圈选+热力图

体验

  1. 热力图与圈选埋点
  2. demo 打开控制台即可查看无埋点日志
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>web-log-sdk</title>
    <script src="https://www.readingblog.cn/lib/web-log-sdk-1.1.0.min.js"></script>
  </head>
  <body>
    <div>
      1
      <div id="1">
        2
        <div id="1">3</div>
        <div>4</div>
      </div>
    </div>
    <div>5</div>
    <script>
      new WebLogger.AutoLogger({
        debug: true
      });
    </script>
  </body>
</html>

开发调试

执行

npm run start

浏览器打开 examples 文件夹下 test.html 即可调试

构建

npm run build

配置

export default {
  appID: "",
  // 是否自动收集点击事件
  autoClick: true,
  debug: false,
  // 日志发送地址
  logUrl: "",
  // 热力图数据获取地址
  heatmapUrl: "",
  sdk: {
    // 类型
    type: "js",
    // 版本
    version: SDK_VERSION
  },
  // 平台参数
  platform,
  optParams: {},
  postMsgOpts: []
};
  1. appID 你可以在初始化时注册一个 appID,所以相关的埋点都会带上这个标记,相当于对埋点数据做了一层 app 维度上的管理。
  2. autoClick 默认为 true,开启会自动收集点击事件(即点击无埋点)。
  3. debug 默认不开启,开启会将埋点数据打印到控制台,便于调试。
  4. logUrl 接收日志的后端地址
  5. heatmapUrl 热力图数据获取地址
  6. sdk sdk 自身信息一些说明
  7. platform 默认会自动获取一些平台参数,你也可以通过配置这个字段覆盖它
  8. optParams 自定义数据

圈选模式

配置 postMsgOpts

初始化 sdk 时需要配置 postMsgOpts,一般来说 targetOrigin 和 curOrigin 是埋点系统的域名

const AutoLogger = window.WebLogger.AutoLogger;
const targetOrigin = "track system url";
const curOrigin = "track system url";
const logUrl = "...";
new AutoLogger({
  debug: true,
  logUrl,
  postMsgOpts: [
    {
      targetWindow: window.parent,
      targetOrigin
    },
    {
      targetWindow: window,
      targetOrigin: curOrigin
    }
  ]
});

开启/停止圈选模式

将 sdk 页面通过 iframe 嵌入以后,在埋点系统中发送消息就可以启用/停止 sdk 的圈选模式

const data = {
  mode: "CIRCLE_SELECT",
  status: "on" // 'off'
};
const targetOrigin = "track system url";
const ifrWindow = document.getElementById("ifr").contentWindow;
ifrWindow.postMessage(JSON.stringify(data), targetOrigin);

启用圈选模式后,hover 任意元素都会被红色框圈选出来。

监听 sdk 页面回传的 log 数据

最后,你只需要在埋点系统中监听消息,就可以接受 sdk 页面回传的 log 数据。基于这些数据,就自由地实现圈选分析功能了。

window.addEventListener("message", event => {
  const { heatmapValueFetch } = this.props;
  if (event.data && event.data.logData) {
    const logData = JSON.parse(event.data.logData);
  }
});

热力图模式

配置 postMsgOpts

初始化 sdk 时需要配置 postMsgOpts,一般来说 targetOrigin 和 curOrigin 是埋点系统的域名

const AutoLogger = window.WebLogger.AutoLogger;
const targetOrigin = "track system url";
const curOrigin = "track system url";
const logUrl = "...";
const heatmapUrl = "...";
new AutoLogger({
  debug: true,
  logUrl,
  heatmapUrl,
  postMsgOpts: [
    {
      targetWindow: window.parent,
      targetOrigin
    },
    {
      targetWindow: window,
      targetOrigin: curOrigin
    }
  ]
});

开启/停止热力图模式

将 sdk 页面通过 iframe 嵌入以后,在埋点系统中发送消息就可以启用/停止 sdk 的热力图模式

const data = {
  mode: "HEATMAP",
  status: "on" // 'off'
};
const targetOrigin = "track system url";
const ifrWindow = document.getElementById("ifr").contentWindow;
ifrWindow.postMessage(JSON.stringify(data), targetOrigin);

启用热力模式后,sdk 会向你配置的 heatmapUrl 接口发送请求,所以这个接口的格式需要和 sdk 的预设一致。 request

method: POST
url: config.heatmapUrl
data:
{
  "pageUrl": location.href
}

response

{
  // ...
  "data": {
    "max": 1,
    "data": [
      {
        "x": "41",
        "y": "171",
        "value": 1
      },
      {
        "x": "153",
        "y": "88",
        "value": 1
      }
    ]
  }
}

基于返回的数据 sdk 会帮你绘制当前页面的热力图。