2012-09-04 68 views
2

我们正在开发一个全新的移动版本的网站,它是一个使用Sencha Touch 2(Ext JS,JavaScript)编写的HTML5网站。Google Analytics(分析):如何跟踪移动网站的点击次数作为主要网站的点击次数

我们在我们的主网站上使用Google Analytics,我们也希望在移动网站上使用Google Analytics。然而,我们期望的使用案例有点特别: 我们希望将移动网站上的文章点击为主要网站上相应文章的点击。 背后的理由是希望汇总统计数据,而不是单独跟踪数据。

尽管站点层次结构有点类似(它们都从Sharepoint后端获取内容),但这两个站点的域和URL结构不同,这里存在挑战。我们不仅可以使用像'setDomainName'这样的东西来改变域名。

在移动版本的每个页面上,我们都提供了主站点上原始页面/文章的完整URL。我们想要做的就是告诉Google将该视图作为该网址的点击来访问,而不是我们实际访问的网址。

我已经看到一些关于'trackPageView'的线程(f ex here),它可能已经足够满足我们的需求,但是我不完全确定。这听起来有些简单,但也可能是我在这里看不到明显的解决方案。 我们能否提供此方法所需的点击网址,就是这样?如果它不工作,那么在头文件中使用一个脚本来检查带有该URL的设置变量,如果它存在,则以它作为参数调用“trackPageView”,如果不是只追踪常规命中? 任何有关此方法语法的帮助都是值得欢迎的。

所有帮助&建议在这里赞赏! 我已经搜索了GA文档,没有太多有关这种特殊情况的帮助信息。

回答

1

是的,就是这么简单的使用跟踪页面视图事件并传递相应的URL参数。在sencha中,所有视图都将存在于同一个HTML页面中,因此您需要以编程方式调用此视图。

包含相同的跟踪代码,您只要在你的网站上使用具有相同的ID ...这应该工作,你期望... 很好的问题...希望它可以帮助...

1

这里的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); 
    } 
} 
相关问题