我们正在开发一个全新的移动版本的我们的网站,它是一个HTML5网站,使用Sencha 2 (Ext,JavaScript)编写。
我们正在使用谷歌分析在我们的主要网站,我们希望在移动网站上使用GA以及。然而,我们想要的用例有点特殊:我们希望将对移动站点上文章的点击作为对主站点上相应文章的点击进行跟踪,背后的理由是希望聚合统计数据,而不是单独跟踪数据。
域和URL结构对于这两个站点是不同的,尽管站点层次结构有点相似(它们都从Sharepoint后端获取内容),这是一个挑战。我们不能只使用“setDomainName”之类的内容来更改域。
在移动版本的每一页上,我们都可以获得主站点上原始页面/文章的完整URL。我们想要做的是告诉谷歌跟踪视图作为对该URL的一个点击,而不是我们实际的一个。
我见过一些关于‘here’的线程(f ex TrackPageView),它可能足以满足我们的需要,但是我并不完全确定。这听起来有点太简单了,但也可能是因为我在这里没有看到明显的解决办法。我们能为这个方法提供所需的点击URL吗?那么,在标题中使用这个URL检查一个set变量的脚本是否有效?如果它存在,则调用'trackPageView‘作为参数,如果不只是跟踪一个常规命中,那么会起作用吗?任何有关此方法语法的帮助都是受欢迎的。
所有的帮助和建议在这里感谢!我已经搜索了GA文档,没有多少关于这个特殊情况的帮助信息。
发布于 2012-12-22 05:13:46
是的,简单地使用track页面视图事件并传递相应的URL参数。在sencha中,所有视图都将存在于同一个HTML页面中,因此需要以编程方式调用它。
包含相同的跟踪代码,与您在现场使用的ID相同.这应该能如你所料..。很好的question...Hope它有帮助..。
发布于 2014-03-01 06:53:39
下面是GA跟踪,为ST2+拼出并简化。我已经介绍了如何初始化、设置基本导航跟踪,以及包括自定义变量和事件跟踪在内的几种选择。
/*
Standard method to init GA tracking.
These can be fired from launch.
*/
initialiseGoogleAnalytics : function() {
//Add Google Analytics Key
window._gaq = window._gaq || [];
window._gaq.push(['_setAccount', MyApp.config.googleAnalytics.code]);
window._gaq.push(['_setDomainName', MyApp.config.googleAnalytics.domain]);
window._gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
},
/*
This method can be set to a globally accessable reference.
For instance:
MyApp.Util = {}; // reference for common utility functions
MyApp.Util.gaTrackEvent = function(data) {};
Thus allowing MyApp.Util.gaTrackEvent(data) from anywhere in app.
Alternatively, add as function to Application for
this.getApplication().gaTrackEvent(data);
*/
gaTrackEvent : function(data) {
//Push data to Google Analytics
// optional prefix for mobile devices - unnecessary for your interest
var prefix = 'mobile/';
// don't track homepage/default hits
if (data == 'home') {
//Ignore Home
return;
}
// basic tracking
_gaq.push(['_trackPageview', prefix + data]);
// OPTIONAL ALTERNATIVES FOR DETAILED TRACKING
// detailed tracking - condensed
_gaq.push(['_setCustomVar',
1, // custom variable slot
'customEventName', // custom variable name
'value1|value2|value3', // multiple values using 1 slot
2 // sets scope to session-level
]);
_gaq.push(['_trackEvent',
'ParentEventName',
'SomeValue'
]);
// detailed tracking - each variable using own slot
_gaq.push(['_setCustomVar',
1,
'stage1',
'value1',
2
]);
_gaq.push(['_setCustomVar',
2,
'stage2',
'value2',
2
]);
_gaq.push(['_setCustomVar',
3,
'stage3',
'value3',
2
]);
_gaq.push(['_trackEvent',
'ParentEventName',
'SomeValue'
]);
}
/*
Set up a controller to handle GA tracking.
This way you can keep the unique events you wish to track central,
while also handling default tracking and SEO.
For example, a controller for Registration might want tracking on success.
this.getRegistration().fireEvent('registrationsuccess');
*/
config: {
control: {
"navigationview": {
activeitemchange: 'generalSEOhandler'
},
"#registration": {
registrationsuccess: 'onRegistrationSuccess'
},
...
},
},
generalSEOhandler: function(container, value, oldValue, eOpts) {
if (value === 0) {
return false;
}
// ignoreDefaultSeo - boolean custom config that can be applied to views.
var ignoreDefaultSeo = value.getInitialConfig('ignoreDefaultSeo');
if (Ext.isDefined(ignoreDefaultSeo) && ignoreDefaultSeo == 1) {
// optional handler for special cases...
} else {
// Use default
var itemId = value.getItemId();
itemId = itemId.replace(/^ext-/,''); // Remove the prefix ext-
itemId = itemId.replace(/-[0-9]?$/,''); // Remove the suffix -1,-2...
// Alternatively use xtype of the view (my preference)
// This will require the xtypes of your views to match the main site pages.
var itemId = value.config.xtype;
this.trackEvent(itemId);
//console.log('USE DEFAULT', value.getId(), value.getItemId(), value);
}
},
onRegistrationSuccess: function(eventOptions) {
var app = this.getApplication(),
trackUrl;
trackUrl = 'new-member';
if (Ext.isDefined(app.accountReactivated) && app.accountReactivated == 1) {
trackUrl = 'reactivated-member';
}
if (Ext.isDefined(app.registeredUsingFacebook) && app.registeredUsingFacebook == 1) {
trackUrl += '/facebook';
} else {
trackUrl += '/non-facebook';
}
// console.log('onRegistrationSuccess', trackUrl);
this.trackEvent(trackUrl);
},
trackEvent: function(data) {
// if using MyApp.Util.gaTrackEvent() technique
MyApp.Util.gaTrackEvent(data);
// if gaTrackEvent() an application method
this.getApplication().gaTrackEvent(data);
}
}
发布于 2013-03-22 06:30:21
我发现这篇文章谈论的是Google分析和Sencha Touch
http://wtcindia.wordpress.com/2013/03/21/using-google-analytics-in-sencha-touch-based-mobile-website/
https://stackoverflow.com/questions/12261809
复制相似问题