Skip to content
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

无法使用百度统计或者腾讯统计 #7

Closed
ChanJuanMei opened this issue Jun 4, 2018 · 16 comments
Closed

无法使用百度统计或者腾讯统计 #7

ChanJuanMei opened this issue Jun 4, 2018 · 16 comments

Comments

@ChanJuanMei
Copy link

在app\wechat\views_common\hook\baidu.html中添加统计的js, 在app\wechat\views_common\layout.html中引入。代码如下: {% include "hook/baidu.html" %}
可以无论如何都无法在统计后台看到数据,作者大大能帮忙看一下么

@ChanJuanMei
Copy link
Author

最后我把统计的代码放在 /vues/demo/index.vue这种位置居然成功了,作者大大能改进一下么,放在这里不太优雅

@Thunf
Copy link
Owner

Thunf commented Jun 4, 2018

app\wechat\views_common\hook\baidu.html 里的代码检查一下,是不是没包<script>,示例文件里是这样的:

<script>
var _hmt = _hmt || [];
(function() {
    var hm = document.createElement("script");
    hm.src = "//hm.baidu.com/hm.js?1234567890";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();
</script>

@ChanJuanMei
Copy link
Author

包了的

@ChanJuanMei
Copy link
Author

<script type="text/javascript"> var _mtac = {"autoReport":0}; (function() { var mta = document.createElement("script"); mta.src = "http://pingjs.qq.com/xx.js?v2.0.4"; mta.setAttribute("xx", "xx"); mta.setAttribute("xx", "xx"); var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(mta, s); })(); </script>

@Thunf
Copy link
Owner

Thunf commented Jun 4, 2018

看一下页面响应里(控制台 -> Network -> Doc - Response),有没有这段?
我跑了一下最新的服务和模板,没有问题呀...

@ChanJuanMei
Copy link
Author

有这段的。js也是可以请求到的

@ChanJuanMei
Copy link
Author

不过我不是最新的

@ChanJuanMei
Copy link
Author

代码里面我也没看到你引用过baidu.html这个文件呀

@Thunf
Copy link
Owner

Thunf commented Jun 4, 2018

模板里引用顺序是:

  • layout.html 里 {% include "foothook.html" %}
  • foothook.html 里 {% include 'hook/baidu.html' %}

为了方便管理多种第三方脚本的,你跑一下模板看看能不能发出去?
按你说的,有这段,JS也可以请求到(说明hook这段运行了),那可能就是加载的脚本发送的问题了...

@ChanJuanMei
Copy link
Author

你说的这些我都试过了,无论这段js放在view下的哪个html都不行,但是放在vues下面的模块的index.vue就可以。我已经测试很多遍了

@Thunf
Copy link
Owner

Thunf commented Jun 4, 2018

app\wechat\views_common\layout.html 中的 views_common 是你自己建的么?
server运行时,默认访问的是 views 目录下,确认一下:

  • 若在views目录下有文件通过相对地址引用views_common下的内容 ,views_common需要在 build/webpack.base.conf.js 里的 CopyWebpackPlugin 里配置拷贝到server中
  • 若不是以上情况,那么你需要更改的应该是 views 下的文件才对,server运行时,默认访问的是 views 目录

@ChanJuanMei
Copy link
Author

这里不能截图,我的目录是views\ _common\baidu.html,而layout是views\layout.html

@ChanJuanMei
Copy link
Author

layout.html引用的baidu.com在谷歌浏览器中可以看到代码运行了呢

@Thunf
Copy link
Owner

Thunf commented Jun 4, 2018

那就是加载统计脚本的代码运行了,然后腾讯的JS也加载进来了,但是在后台看不到数据对吧。。。
所以你看的数据是PV还是其他一些数据。。。
猜测和 {"autoReport":0} 有关系。。。去掉试试?

参考最新版的MTA文档
H5接入指南 - MTA HTML5接入

// 初始化
MtaH5.init({
  ...
  "autoReport":0,//是否开启自动上报(1:init完成则上报一次,0:使用pgv方法才上报)
  ...
});

@ChanJuanMei
Copy link
Author

貌似还是不行呢。无论后面我能不能成功进来,都很感觉你哦,真是一个very nice的人呢,么么哒

@Thunf Thunf closed this as completed Jun 4, 2018
@ChanJuanMei
Copy link
Author

image
大神,build这个项目的时候出现上面那个错误是因为什么啊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants