微信小程序【小程序码传参,自定义埋点】

小程序码传参&小程序URL Scheme

获取小程序码,适用于需要的码数量极多的业务场景
获取小程序 scheme 码,适用于短信、邮件、外部网页、微信内等拉起小程序的业务场景。

token接口:传送门

https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=##&secret=##

生成小程序码接口:传送门

https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=##
// Headers 设置
Content-Type: application/json
// 参数
{
    "path": "pages/index/index",
    "scene": "a=2",
    "env_version": "develop"
}

生成URL Scheme: 传送门

https://api.weixin.qq.com/wxa/generatescheme?access_token=ACCESS_TOKEN
// Headers 设置
Content-Type: application/json
// 参数
{
    "jump_wxa": {
        "path": "pages/index/index",
        "query": "a=2",
        "env_version": "develop"
    }
}
// 返回示例
{
    "errcode": 0,
    "errmsg": "ok",
    "openlink": "weixin://URL"
}

开发者工具演示

/**
  * 生命周期函数--监听页面加载
  */
 onLoad: function (options) {
 	 // option 小程序码,URL Scheme,获取传参参数
     // scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
     const scene = decodeURIComponent(options)
     console.log(options,scene)
     // 上报自定义埋点
     wx.reportEvent("source", {
       "source_type": options.scene
     })
 },

利用发开着工具调试
开发者工具演示
设置进入场景模式
设置进入场景模式

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值