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

@d1m-atom/universal-tracker

v1.0.18

Published

- [x] [腾讯有数](#youshu) - [x] [神策](#sensors) - [ ] Talking Data - [ ] GA/GTM

Downloads

8

Readme

@d1m-atom/universal-tracker 小程序 官网H5 通用打点API

需要内网NPM点击进入

因为H5未测试打点,可能在初始化传参会少一些参数,其他api无改变

目前支持情况

有数小程序使用方法  

import {Youshu} from '@d1m-atom/universal-tracker';

const sr = new Youshu({
    sdk: require('./youshu.min.js'),
    isDev: true,
    token: 'bi72fccc7184ef4xxx',
    appid: 'wx195745e8e342bxxx',
    encrypt: false,
    autoProxy: true,
    autoProxyOptions: {},
    platform: 'weapp',
    chan: {},
    scene: 1004
    isOldTrackUp: true
});

App({
    sr,
    onLaunch : function( options ){},
    onShow : function( options ){},
    onHide : function(){}
});

传参方式

| 字段名 | 字段内容 | isRequire | | ----- | --- | --- | | sdk | 神策SDK引用包可以去有数官网下载 sr-sdk-wxapp-1.8.6.min.js | 必传 | | isDev | 是否为DEV环境 主要用于打log dev会自动把log打在控制台 | 必传 | | token | 有数Token | 必传 | | appid | 小程序AppId | 必传 | | platform | weapp jd alipay h5 tt qq | 必传 | | encrypt | 开启后数据传输加密,默认为false | 可不传 | | autoProxy | 开启自动代理,此功能为有数SDK核心功能,建议开启 默认 true | 可不传 | | autoProxyOptions | 代理设置详细参数见下方 | 可不传 | | chan | 渠道参数 参数见下方 | 可不传 | | scene | 场景值 会自动覆盖 chan 下的场景值 | 可不传 | | isOldTrackUp | 是否上报未初始化之前的打点 默认 false | 可不传 |

autoProxyOptions

| 字段名 | 字段内容 | | ----- | --- | | app_launch | 开启后代理采集启动应用事件,默认为true | | app_show | 开启后代理采集显示应用事件,默认为true | | app_exit | 开启后代理采集隐藏应用事件,默认为true | | browse_page | 开启后代理采集浏览页面事件,默认为true | | leave_page | 开启后代理采集离开页面事件,默认为true | | autoTrack | 开启后代理采集元素事件,默认为true | | page_pull_down_refresh | 开启后代理采集下拉刷新页面事件,默认为true | | page_reach_bottom | 开启后代理采集上拉触底页面事件,默认为true | | page_share_app_message | 开启后代理采集分享页面事件,默认为true |

chan

| 字段名 | 字段内容 | | ----- | --- | | scene | 小程序场景值,必填 例1037 | | chan_id | 引流渠道的标识符 | | chan_refer_app_id | 来源小程序或公众号appid | | chan_shop_id | 微信用门店ID,若需要计算门店业务则必填 | | chan_shop_name | 用户在有数的门店名称,展示字段,若chan_shop_id存在则必填 | | chan_custom | 自定义渠道参数 |

chan_custom 自定义渠道参数

| 字段名 | 字段内容 | | ----- | --- | | chan_custom_id | 4级自定义渠道的标识符,是自定义渠道的最小粒度 例mp-article-12375,若填写了chan_custom相关任一字段需必填 | | chan_custom_id_desc | 4级自定义渠道的描述 例公众号文章(id=12375),若填写了chan_custom相关任一字段需必填 | | chan_custom_cat_3 | 3级自定义渠道的标识符,3级是针对4级的分类,要求4级数据必须存在 例mp-article,若填写了chan_custom相关任一字段需必填 | | chan_custom_cat_3_desc | 3级自定义渠道的描述,若chan_custom_cat_3存在则必须存在 例公众号文章,若填写了chan_custom相关任一字段需必填 | | chan_custom_cat_2 | 2级自定义渠道的标识符,2级是针对3级的分类,要求34级数据必须存在 例media,若填写了chan_custom相关任一字段需必填 | | chan_custom_cat_2_desc | 2级自定义渠道的描述,若chan_custom_cat_2存在则必须存在 例媒体,若填写了chan_custom相关任一字段需必填 | | chan_custom_cat_1 | 1级自定义渠道的标识符,1级是针对2级的分类,要求234级数据必须存在 例wechat,若填写了chan_custom相关任一字段需必填 | | chan_custom_cat_1_desc | 1级自定义渠道的描述,若chan_custom_cat_1存在则必须存在 例微信,若填写了chan_custom相关任一字段需必填 |

方法

// true 开启打点 false 关闭打点
getApp().sr.trackStart(true | false);
// 写入 scene 值
getApp().sr.setChan({
    scene: 123
})
getApp().sr.setUser({
    open_id: '123',
    app_id: '1111111',
    user_id: 'asdfda',
    union_id: "123333",
    tag: [{ tag_id: false ? 'member' : 'guest', tag_name: false ? '会员用户' : '游客用户' }]
});
// track 参数为 object时,key为要打点的名,value为内容
getApp().sr.track(
    {
        click: {
            name: '点击'
        },
        click1: {
            name: '点击1'
        },
    }
);

// track 参数为 Array时 每一个数组为一个要打的点
getApp().sensors.track(
    ['click', {name: '点击'}],
    ['click1', {name: '点击1'}]
);

关于webview与小程序打点点击进入有数文档

// 使用在 webview 内嵌页的小程序之中,可以联通会话状态。
getApp().sr.getInfo(
    {
       url: 'pages/xxx',
        params: {
            canshu1: 111,
        },
    }
);

神策使用方法  

import {Sensors} from '@d1m-atom/universal-tracker';

const sensors = new Sensors({
    serverUrl: "htttps://xxx.com"
    sdk: require('./sensorsdata.min.js'),
    isDev: true,
    autoTrack: {
        appLaunch: true,
        appShow: true,
        appHide: true,
        pageShow: true,
        pageShare: true,
        mpClick: false,
        mpFavorite: true,
        pageLeave: false,
    },
    sourceChanne: ["custom_param"],
    allowAmendSharePath: true
    platform: 'weapp',
    devicePlatform: 'mobile phone',
    isOldTrackUp: true
});

App({
    sensors,
    onLaunch : function( options ){},
    onShow : function( options ){},
    onHide : function(){}
});

传参方式

| 字段名 | 字段内容 | isRequire | | ----- | --- | --- | | serverUrl | 神策服务器URL | 必传 | | sdk | 神策SDK引用包可以去神策官网下载 sensorsdata.min.js | 必传 | | isDev | 是否为DEV环境 主要用于打log dev会自动把log打在控制台 | 必传 | | autoTrack | 自动采集,下文详解 | 可不传 | | sourceChannel | 自定义渠道追踪参数,如 sourceChannel: ["custom_param"] | 可不传 | | allowAmendSharePath | 是否允许修改 onShareAppMessage 里 return 的 path,用来增加(登录 ID,分享层级,当前的 path),在 app onShow 中自动获取这些参数来查看具体分享来源、层级等 | 可不传 | | platform | weapp swan alipay h5 rn tt | 必传 | | devicePlatform | mobile phone 根据神策要求传入 | 可不传 | | isOldTrackUp | 是否上报未初始化之前的打点 默认 false | 可不传 |

autoTrack

| 字段名 | 字段内容 | | ----- | --- | | appLaunch | 默认为 true,false 则关闭 $MPLaunch 事件采集 | | appShow | 默认为 true,false 则关闭 $MPShow 事件采集 | | appHide | 默认为 true,false 则关闭 $MPHide 事件采集 | | pageShow | 默认为 true,false 则关闭 $MPViewScreen 事件采集 | | pageShare | 默认为 true,false 则关闭 $MPShare 事件采集 | | mpClick | 默认为 false,true 则开启 $MPClick 事件采集 | | mpFavorite | 默认为 true,false 则关闭 $MPAddFavorites 事件采集 | | pageLeave | 默认为 false, true 则开启 $MPPageLeave事件采集 |

方法

// true 开启打点 false 关闭打点
getApp().sensors.trackStart(true | false); 
// 对于所有事件都需要添加的属性,可在初始化 SDK 前,调用 registerApp() 将属性注册为公共属性:
getApp().sensors.registerApp({
    userLever: 'VIP3',
    userSex: '男'
});
getApp().sensors.login({
    userId: 'xxx'
});
getApp().sensors.setProfile({
    // 只会覆盖一次  可以设定用户属性,同一个 key 多次设置时,value 值会进行覆盖替换:
    onceParams: {
        email:'xxx@xx',
        favoriteFruits: ['苹果', '油桃'],
        subscribers: 7277
    },
    // 多次覆盖  可以设定用户属性,同一个 key 多次设置时,value 值会进行覆盖替换:
    params: {
        email:'xxx@xx',
        favoriteFruits: ['苹果', '油桃'],
        subscribers: 7277
    }
});
// track 参数为 object时,key为要打点的名,value为内容
getApp().sensors.track(
    {
        click: {
            name: '点击'
        },
        click1: {
            name: '点击1'
        },
    }
);

// track 参数为 Array时 每一个数组为一个要打的点
getApp().sensors.track(
    ['click', {name: '点击'}],
    ['click1', {name: '点击1'}]
);