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

@aliyun-sls/web-track-mini

v0.3.8

Published

## 背景信息

Downloads

321

Readme

SLS WebTracking JavaScript SDK

背景信息

Web Tracking 可以采集各种浏览器、iOS APP 或 Android APP 的用户信息,例如:

  • 用户使用的浏览器、操作系统、分辨率等信息。
  • 用户浏览行为记录(例如:用户在网站上的单击行为、购买行为等)。
  • 用户在 APP 中的停留时间、是否活跃等。

适用平台

@aliyun-sls/web-track-mini 支持小程序端,包括:

微信小程序、微信小游戏

支付宝小程序

字节跳动小程序

钉钉小程序

QQ 小程序、QQ 小游戏

百度小程序

浏览器参见 @aliyun-sls/web-track-browser

注意事项

  • 使用 Web Tracking 则表示该 Logstore 打开互联网匿名写入权限,没有经过有效鉴权,可能产生脏数据。
  • POST 请求每次写入的日志数量上限为 10MB, 详情请参见PutLogs
  • 小程序平台一般需要配置服务器安全通信域名(或者叫request合法域名),sls webtrack 使用的域名为 https://${project}.${host},host 和 project 含义参见参数配置

数据采集

控制台配置

  1. 登录日志服务控制台
  2. 单击目标 Project。
  3. 找到目标 Logstore,单击pic下的修改
  4. Logstore 属性页面,单击右上方的修改
  5. 打开WebTracking开关,并单击保存

通过 SDK 采集数据

1.安装依赖包

npm install --save @aliyun-sls/web-track-mini

2.import在您的应用程序模块。

import SlsTracker from '@aliyun-sls/web-track-mini'

3.配置参数 opts。

| 参数 | 说明 | 是否填写 | | :----------: | :---------------------------------------------------------------------------------------------------------------------------------: | :------------------------------: | | host | 日志服务所在地域的 Endpoint,详情请参见服务入口 | 必填 | | project | 控制台创建的 project 名称。 | 必填 | | logstore | 控制台创建的 logstore 名称。 | 必填 | | time | 发送消息的时间间隔,数据格式为 Number 的方式,time*1000(毫秒)。 | 选填(默认是 10 秒) | | count | 发送消息的数量大小,数据格式为 Number 的方式。 | 选填(默认是 10 条数据) | | topic | 日志主题。 | 选填, string | | source | 日志来源。 | 选填, string | | tags | 日志标签。 | 选填, Record<string, string> |

const opts = {
  host: '${host}', // 所在区域的host
  project: '${project}', // project名称
  logstore: '${logstore}', // logstore名称
  time: 10, // 定义时间,默认是10秒,number类型,选填
  count: 10, // 定义数据条数,默认是10条,number类型,选填
  topic: 'topic',
  source: 'source',
  tags: {
    tags: 'tags',
  },
}

4.创建 SlsTracker 对象。

const tracker = new SlsTracker(opts)

5.上传日志。

tracker.send({
  customer: 'zhangsan',
  product: 'iphone 12',
  price: 7998,
})

核心功能

send()

说明:  单条数据上传。

参数:Object 类型

示例:

tracker.send({
  customer: 'zhangsan',
  product: 'iphone 12',
  price: 7998,
})

sendImmediate()

说明:  单条数据立即上传,time 和 count 参数此时配置不生效。

参数:Object 类型

示例:

tracker.sendImmediate({
  customer: 'zhangsan',
  product: 'iphone 12',
  price: 7998,
})

sendBatchLogs()

说明:  批量数据上传。

参数:Object 类型

示例:

tracker.sendBatchLogs([
  {
    customer: 'zhangsan',
    product: 'iphone 12',
    price: 7998,
  },
  {
    customer: 'zhangsan',
    product: 'iphone 12',
    price: 7998,
  },
])

sendBatchLogsImmediate()

说明:  批量数据上传,time 和 count 参数此时配置不生效。

参数:Object 类型

示例:

tracker.sendBatchLogsImmediate([
  {
    customer: 'zhangsan',
    product: 'iphone 12',
    price: 7998,
  },
  {
    customer: 'zhangsan',
    product: 'iphone 12',
    price: 7998,
  },
])