谷歌分析:如何跟踪移动网站的点击量作为对主网站的点击



我们正在开发一个全新的移动版网站,它是一个使用Sencha Touch 2(ExtJS,JavaScript)编写的HTML5网站。

我们在我们的主网站上使用谷歌分析,我们也希望在移动网站上使用GA。然而,我们想要的用例有点特殊:我们希望将移动网站上的文章点击量作为主网站上相应文章的点击量进行跟踪这背后的原因是希望汇总统计数据,而不是单独跟踪数据。

这两个网站的域和URL结构不同,尽管网站层次结构有些相似(它们都从Sharepoint后端获取内容),但这就是挑战所在。我们不能只使用类似"setDomainName"的内容来更改域。

在移动版的每个页面上,我们都可以在主网站上获得原始页面/文章的完整URL。我们想做的是告诉谷歌将该视图作为对该URL的点击来跟踪,而不是我们实际所在的URL

我看到了一些关于"trackPageView"的线程(此处为f ex),它可能足以满足我们的需求,但我不完全确定。这听起来有点太简单了,但也可能是我没有看到明显的解决方案。我们能为这个方法提供所需的点击URL吗?那么,在标头中有一个脚本来检查具有此URL的集合变量,如果存在,则将其作为参数调用"trackPageView",如果不只是跟踪常规命中,是否可行?欢迎对这种方法的语法提供任何帮助。

所有帮助&在此感谢您的建议!我搜索了GA文档,但没有太多关于这个特殊情况的帮助信息。

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

包含与您在具有相同ID的实时网站中使用的相同跟踪代码…这应该如您所期望的那样工作。。。非常好的问题。。。希望它能帮助。。。

以下是为ST2+编写并简化的GA跟踪。我已经包括了如何初始化,设置基本的导航跟踪,以及包括自定义变量&事件跟踪。

/*
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);
    }
}

我发现这篇文章谈论的是谷歌分析和Sencha Touch

http://wtcindia.wordpress.com/2013/03/21/using-google-analytics-in-sencha-touch-based-mobile-website/

最新更新