New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mip-stats-baidu 使用优化反馈 #961

Closed
xuexb opened this Issue Dec 15, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@xuexb
Contributor

xuexb commented Dec 15, 2017

问题分类

  • MIP 组件使用

问题描述

mip-stats-baidu组件文档 中,强调说明了必须使用 encodeURIComponent 进行转义,但为啥转义的目标值不是“正常”的 JSON 结构呢?如:

<div data-stats-baidu-obj="%7B%22type%22:%22click%22,%22data%22:%22%5B_trackPageview,%20/virtual/login%5D%22%7D">
    我是自动触发
</div>

中的 data-stats-baidu-obj 转义前是:

{
    "type": "click",
    "data": "[_trackPageview, /virtual/login]"
}

这个 data 是个字符串?

因为我要使用 百度统计事件API 来完成自定义需求,但发现这个 data 不是 "data":["_trackPageview", "/virtual/login"] 这样的,这在使用后端往页面输出 JSON.stringify(obj) 时很尴尬。

您的建议方案

{
    "type": "click",
    "data": [
        "_trackEvent",
        "tpl",
        "down",
        "1"
    ]
}
@xuexb

This comment has been minimized.

Contributor

xuexb commented Dec 15, 2017

http://tongji.baidu.com/open/api/more?p=ref_trackEvent 百度统计API里是个数组形式,而到组件就是个字符串了。

@jennyliang220

This comment has been minimized.

Member

jennyliang220 commented Jan 3, 2018

确实很奇怪,使用字符串比较别扭。看了代码blame,chuantao之前增加事件追踪的时候是这么设计的:
image,如果没有特殊原因,我改下代码,兼容数组和字符串吧。

@fengchuantao

This comment has been minimized.

fengchuantao commented Jan 3, 2018

当时的设计没有特殊原因,可修改后兼容数组。 @jennyliang220

@jennyliang220

This comment has been minimized.

Member

jennyliang220 commented Jan 19, 2018

#999 修复这个问题,2018.1.18已上线。上线后支持以下三种统计方法:

<!--语义化最好,推荐-->
<button data-stats-baidu-obj='{"type":"click","data":["_trackPageview", "/virtual/login2"]}'>
    点击直接触发统计 virtual/login2
</button>

<button data-stats-baidu-obj='{"type":"click","data":"[_trackPageview, /virtual/login3]"}'>
    点击直接触发统计 virtual/login3
</button>

<button data-stats-baidu-obj="%7B%22type%22%3A%22click%22%2C%22data%22%3A%22%5B_trackPageview%2C%20%2Fmip-stats%2Fsheji%5D%22%7D">
     点击触发统计 mip-stats%2Fsheji
</button>
@xuexb

This comment has been minimized.

Contributor

xuexb commented Jan 19, 2018

666

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment