本文介绍了Google Analytics和Backbone.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一些帮助,我一直在阅读有关将analytics添加到backbone.js的文档,特别是,我想我完全理解它,但我的问题是必须将分析跟踪代码添加到每个页面我想要分析数据,如果不是的话,你可以指出我的方向。



任何帮助都非常感谢。
Thank You。

解决方案

根据,你必须只包含一次代码路由器定义文件。

router.js(定义 Backbone.Router 的文件)将会显示像这样:

  router.js 

//在这里包含google-analytics代码,第一个来自
中代码的片段// This this http://nomethoderror.com/blog/2013/11/19/track-backbone-dot-js-page-views-with-google-analytics/

var router = Backbone.Router.extend({
initialize:function(){
this.bind('route',this._pageView);
//您的自定义代码在这里
},

_pageView:function(){
var path = Ba1ckbone.history.getFragment();
ga('send','pageview' ,{page:/+ path});
},

/ /其他成员定义
});


I am looking for a bit of help, I have been reading documentation on adding Analytics to backbone.js specifically this link and I think I fully understand it, but my issue is do I have to add the analytic tracking code to every page I want analytic's data from, if not can you point me in the right direction.

Any help is much appreciated.Thank You.

解决方案

According to the link in the question, you have to include the code only once probably in the router definition file.

The router.js (the file in which Backbone.Router is defined) will look something like this :

router.js

//Include the google-analytics code here, first snippet from the code in
//this http://nomethoderror.com/blog/2013/11/19/track-backbone-dot-js-page-views-with-google-analytics/

var router=Backbone.Router.extend({
initialize: function() {
  this.bind('route', this._pageView);
  //your custom code goes here
},

_pageView: function() {
  var path = Ba1ckbone.history.getFragment();
  ga('send', 'pageview', {page: "/" + path});
},

//Other member definitions
});

这篇关于Google Analytics和Backbone.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 17:49