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

um-share-core

v1.2.5

Published

友盟H5端的分享追踪 ## 设计思路 采用核心包+插件方式 - 核心包提供一个方法,该方法按照协议上报到友盟分享统计链路,实现时遵循兼容性优先原则, 能独立运行,并适当对外插件暴露必要的设置方法和生命周期事件。 - 插件可以监听核心包事件,并能够调用核心包的统计链路,能够设置核心包提供的公共属性

Downloads

5

Readme

um-share-core

如需能获取openid,建议设置oid, 其中trackcode和root_track_code,在metinfo设置的都应该是从url地址参数读的,首次可能只有root_track_code,后面的传播可以只设置trackcode(都传的话服务端会取trackcode),getNextTrackCode换取的追踪码是放到下个分享链接中的,不是放到metainfo中的

Usage

const umShareCore = require('um-share-core');

// TODO: DEMONSTRATE API

DEMO

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Webpack App</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
</head>

<body>
    <script>
        function replaceParamVal(oUrl, paramName, replaceWith) {
            var re = new RegExp("(" + paramName + "=)([^&]*)", "gi");
            var nUrl = oUrl.replace(re, replaceWith);
            nUrl = nUrl.replace("&&", '&');
            return nUrl;
        }
        function getQueryVariable(variable){
            let query = window.location.search.substring(1);
            let vars = query.split("&");
            for (let i=0;i<vars.length;i++) {
                    let pair = vars[i].split("=");
                    if(pair[0] == variable){return pair[1];}
            }
            return('');
        }
        // 获取jssdk签名
        fetch(`http://100.88.239.221:8081/`)
        .then(function(response) {
            return response.json();
        })
        .then(function(myJson) {
            wx.config({
                debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
                appId: 'wx43596bfcbff2a514', // 必填,公众号的唯一标识
                ...myJson,
                jsApiList: ['updateAppMessageShareData','updateTimelineShareData','onMenuShareTimeline','onMenuShareAppMessage'] // 必填,需要使用的JS接口列表
            });
        });

        wx.ready(function () {
            var sharelink = location.href;
            // 设置metaInfo
            shareCore.setMetaInfo({appkey:"lttd", oid: 'xxxxxxxxxxxx', nickname: '昵称', avator: '头像', uid: 'unionid', trackkey: '_tk', trackcode: getQueryVariable('_tk'), root_track_key: '_rtk', root_track_code: getQueryVariable('_rtk'), trackurl: location.href });
            // 发送pv事件需要先设置好metainfo
            shareCore.enter({ page_name: document.title, page: location.href }, function () {

            });

            // 获取追踪码
            shareCore.getNextTrackCode(function (data) {
                var metinfo = shareCore.getMetaInfo();
                // 更新下一个链接中的trackcode
                var  newsharelink = sharelink;
                if(!metinfo.trackcode){
                    newsharelink = `${newsharelink}&${metinfo.trackkey}=${data}`;
                }else{
                    newsharelink = replaceParamVal(sharelink, metinfo.trackkey, `${metinfo.trackkey}=${data}`);
                }
                // 如果想把下一个url 中的root_track_code剔除,注意也可以不剔除,后台会按照 trackcode root_track_code url 优先级由高到低来取,服务端记录的trackcode中已经包含root_track_code
                console.log(newsharelink);
                var shareinfo = { title: document.title, imgUrl: 'https://img.alicdn.com/tfs/TB1tmkCctTfau8jSZFwXXX1mVXa-1280-1280.png', desc: '描述', link: newsharelink};
                wx.updateAppMessageShareData({
                    ...shareinfo,
                    success: function () {
                        // 设置成功
                        shareCore.trackShare(Object.assign({},shareinfo,{scene:'wx.updateAppMessageShareData'}));
                        console.log('wx.updateAppMessageShareData')
                    }
                })
                wx.updateTimelineShareData({
                    ...shareinfo,
                    success: function () {
                        shareCore.trackShare(Object.assign({},shareinfo,{scene:'wx.updateTimelineShareData'}));
                        console.log('wx.updateTimelineShareData')
                        // 设置成功
                    }
                })
                wx.onMenuShareTimeline({
                    ...shareinfo,
                    success: function () {
                        // 用户点击了分享后执行的回调函数
                        shareCore.trackShare(Object.assign({},shareinfo,{scene:'wx.onMenuShareTimeline'}));
                        console.log('wx.onMenuShareTimeline')
                    }
                })
                wx.onMenuShareAppMessage({
                    ...shareinfo, 
                    type: '', // 分享类型,music、video或link,不填默认为link
                    dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
                    success: function () {
                        shareCore.trackShare(Object.assign({},shareinfo,{scene:'wx.onMenuShareAppMessage'}));
                        console.log('wx.onMenuShareAppMessage')
                        // 用户点击了分享后执行的回调函数
                    }
                });


            });
            // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
        });
        wx.error(function (res) {
            console.log(res, '错误')
            // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
        });
    </script>
</body>

</html>

types

declare namespace ShareCore {
    export interface MetaInfo {
        /** js版本不需要传递,自动添加 */
        jsver?: string;
        /** appkey,目前用不到,建议吧appId传进来,以区分不同的微信小程序 */
        appkey?: string;
        /** openid 如果想统计到微信的openid,则此处必填*/
        oid: string;
        /** 来源urlkey 可不填 */
        fromkey?: string;
        /** 来源urlvalue 可不填*/
        from?: string;
        /** 追踪码对应的urlkey */
        trackkey?: string;
        /** 来源追踪码 如果是二次传播则为必填参数,开发者通过url地址中有无参数来决定是否传*/
        trackcode: string;
        /** 原始追踪码 首次传播为必填*/
        root_track_code: string;
        /** 原始来源key */
        root_track_key?: string;
        /** 当前页面地址 */
        trackurl?: string;
        /** unionid */
        uid?: string;
        /** 昵称 */
        nickname?: string;
        /** 头像 */
        avator?: string;
    }
    export interface Shareinfo {
        /** 分享标题 */
        title?: string,
        /** 分享描述 */
        desc?: string,
        /** 分享图片 */
        imgUrl?: string,
        /** 分享链接 */
        link: string,
        /** 分享场景 */
        scene: string
    }
    export interface EventPackage {
        
    }
    export interface PageConfig {
        /** 页面地址 */
        page: string,
        /** 页面名称 */ 
        page_name?: string
    }
    /** 设置日志公共字段*/
    export function setMetaInfo(MetaInfo: MetaInfo): MetaInfo;
    /** 获取日志公共字段*/
    export function getMetaInfo(): MetaInfo;
    /** 自定义事件*/
    export function trackEvent(id: string, data: EventPackage, type: number, callback?: any): void;
    /** 发起分享事件 */
    export function trackShare(data: Shareinfo): void;
    /** 进入页面事件 */
    export function enter(config: PageConfig, callback?: Function): void;
    /** 获取分享link的追踪码 */
    export function getNextTrackCode(callback?: Function): void;
}