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-browser

v0.3.8

Published

## 背景信息

Downloads

4,210

Readme

SLS WebTracking JavaScript SDK

背景信息

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

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

适用平台

@aliyun-sls/web-track-browser 只支持浏览器端。

小程序参见 @aliyun-sls/web-track-mini

注意事项

  • 使用 Web Tracking 则表示该 Logstore 打开互联网匿名写入权限,没有经过有效鉴权,可能产生脏数据。
  • POST 请求每次写入的日志数量上限为 3MB 或者 4096 条,详情请参见PutLogs

数据采集

控制台配置

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

通过 SDK 采集数据

1.安装依赖包

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

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

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

3.使用CDN包(注意修改版本号)

<script src="https://g.alicdn.com/sls/sls-js-sdk/${version}/web-track-browser.js"></script>

window.SLS_Tracker &&
  new SLS_Tracker({
    project: 'xxx',
    logstore: 'xxx',
    host: 'xxx',
  })

4.配置参数 opts。

| 参数 | 说明 | 是否填写 | | :----------: | :---------------------------------------------------------------------------------------------------------------------------------: | :------------------------------: | | host | 日志服务所在地域的 Endpoint,详情请参见服务入口。支持自定义域名,此时 host 格式为 https://自定义域名 或者 http://自定义域名 | 必填 | | 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',
  },
}

5.创建 SlsTracker 对象。

const tracker = new SlsTracker(opts)

6.上传日志。

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,
  },
])