跳到主要内容

引流渠道


来源类型

商家自己生成引流渠道 chan_id

有数中的引流渠道分为功能、活动、导购、地推、物料、触达、广告、公众号图文、直播 9 大类。

chan_id 的来源有两种:

  • 来源一:从跳转链接中获得参数;
  • 来源二:从小程序码/二维码中获得参数。

::: tips

如果小程序码/二维码是通过 getUnlimited 接口生成的,那么开发者需要通过 decodeURIComponent 来获取二维码中的 scene 值。

:::


第三方服务生成引流渠道 chan_id

腾讯惠聚

当用户从腾讯惠聚跳转至商家小程序时,链接中会自动带上腾讯惠聚专属渠道参数chan_id,例:pages/productDetail/productDetail?chan_id=8_ac3e76c2e5721f5f&productId=561440,其中的8_ac3e76c2e5721f5f是腾讯惠聚专属渠道参数,包含腾讯惠聚渠道信息。

chan_refer_app_id:对于腾讯惠聚来说,该字段总是wx9d4f5f62ea059f08

示例

"chan": {
"chan_id": "8_ac3e76c2e5721f5f",
"chan_refer_app_id": "wx9d4f5f62ea059f08",
"chan_wxapp_scene": 1037
}



上报方式

App.onShow 里收集

  • 总是在 App.onShow 里采集渠道数据,具体采集方法见下表
  • 每次触发 App.onShow 时候,若新的渠道数据非空,则应该覆盖旧的渠道数据
渠道参数类型收集方法
chan_idstring自定义渠道的收集方法较复杂,详见下节
chan_wxapp_sceneint就是小程序场景值,可从 options.scene 获取
chan_refer_app_idstring来源公众号或小程序appID,可从 options.referrerInfo.appId 获取

::: tips

应该在 onShow 函数内收集而不是 onLaunch,因为在小程序周期内用户可能多次进出小程序触发 onShow,用户每次重新进入小程序都可能改变当前会话的渠道信息。 而 onLaunch 在整个小程序生命周期内只触发一次。

:::



收集方法

chan_id 可在多种场景进行标记,下面介绍各个情况下的标记及收集方法。

1. 通过接口A生成小程序码

使用接口 A 生成小程序码时需要将 chan_id=<渠道值> 作为 URL 查询参数填入 path

例如:为了统计 chan_id=shop1357 的门店的流量情况,且扫描小程序码时打开页面/home/index 调用接口 A 生成小程序码时,path 填入 /home/index?chan_id=shop1356

收集方法

App({
onShow({ query }) {
let chan_id = query.chan_id
console.log(`chan_id: ${chan_id}`)
}
})

2. 通过接口B生成小程序码

使用接口 B 生成小程序码时需要将 chan_id=<渠道值> 作为 scene 的一部分填入。

例如:为了统计chan_id=shop1357的门店的流量情况,且扫描小程序码时打开页面/home/index 调用接口 B 生成小程序码时,path 填入 /home/indexscene 填入 chan_id=shop1357

收集方法

App({
onShow({ query }) {
const scene = decodeURIComponent(query.scene)
let match = scene.split('&').map(m => m.match(/^chan_id=(.*)$/)).find(m => !!m)
if (match) {
console.log(`chan_id=${match[1]}`)
} else {
console.log('do not find chan_id')
}
}
})

3. 通过接口C生成二维码

使用接口C生成二维码时需要将 chan_id =<渠道值> 作为 URL 查询参数填入 path。

收集方法同接口A一致,不再赘述。


4. 通过 wx.navigateToMiniProgram 跳转小程序

当其他小程序通过 wx.navigateToMiniProgram 跳转过来时,chan_id 可能会以查询参数的形式附加在 path 参数上。

收集方法同接口 A 一致,不再赘述。


5. 统一收集

用一段代码同时兼容以上 4 种情况:

App({
_getChanID(query) {
let chan_id = query.chan_id
if (chan_id) { return chan_id }

let sceneInQuery = decodeURIComponent(query.scene)
let match = sceneInQuery.split('&').map(m => m.match(/^chan_id=(.*)$/)).find(m => !!m)
if (match) { return match[1] }
},
onShow({ query }) {
let chan_id = this._getChanID(query)
console.log(`chan_id=${chan_id}`)
}
})