如何将Google Analytics集成到jQueryMobile网站中

时间:2021-07-11 13:42:17

jQueryMobile loads its first page as every site does. The usual Google Analytics integration works - the request ist tracked. But following pages are loaded asynchronously and user clicks are not tracked.

jQueryMobile会像每个站点一样加载其第一页。通常的Google Analytics集成工作 - 跟踪请求。但是后续页面是异步加载的,并且不会跟踪用户点击。

How to integrate Google Analytics into a jQueryMobile website, so that all page clicks are tracked?

如何将Google Analytics集成到jQueryMobile网站中,以便跟踪所有页面点击?

3 个解决方案

#1


15  

Jon Gales has written a great article on this.

Jon Gales写了一篇很棒的文章。

http://www.jongales.com/blog/2011/01/10/google-analytics-and-jquery-mobile/

Here's the code he recommends using:

这是他推荐使用的代码:

$('[data-role=page]').live('pageshow', function (event, ui) {
    try {
        _gaq.push(['_setAccount', 'YOUR_GA_ID']);

        hash = location.hash;

        if (hash) {
            _gaq.push(['_trackPageview', hash.substr(1)]);
        } else {
            _gaq.push(['_trackPageview']);
        }
    } catch(err) {

    }

});

Update

Since live is now deprecated you should use the on event instead, if you´re using jQuery 1.7+. http://api.jquery.com/on/

由于live现已弃用,因此如果您使用的是jQuery 1.7+,则应使用on事件。 http://api.jquery.com/on/

#2


4  

For those having problems with Phonegap and google analytics :

对于那些遇到Phonegap和谷歌分析问题的人:

Google code uses cookies and it doesn't work with file:// urls wich is what Phonegap uses. The Pokki team made a good implementation that uses localStorage in place of cookies. I made a fork on github to remove the need of pokki, so here is a solution that works with phonegap as a standalone library

Google代码使用Cookie,但它不适用于file:// urls,这是Phonegap使用的内容。 Pokki团队做了一个很好的实现,使用localStorage代替cookie。我在github上做了一个fork以消除对pokki的需求,所以这里有一个与phonegap一起作为独立库的解决方案

https://github.com/ggendre/GALocalStorage

hope this will help someone else :)

希望这会帮助别人:)

#3


0  

http://code.google.com/apis/analytics/docs/mobile/overview.html http://analytics.blogspot.com/2009/10/google-analytics-now-more-powerful.html

These are references, please read for your knowladge.

这些是参考,请阅读您的知识。

#1


15  

Jon Gales has written a great article on this.

Jon Gales写了一篇很棒的文章。

http://www.jongales.com/blog/2011/01/10/google-analytics-and-jquery-mobile/

Here's the code he recommends using:

这是他推荐使用的代码:

$('[data-role=page]').live('pageshow', function (event, ui) {
    try {
        _gaq.push(['_setAccount', 'YOUR_GA_ID']);

        hash = location.hash;

        if (hash) {
            _gaq.push(['_trackPageview', hash.substr(1)]);
        } else {
            _gaq.push(['_trackPageview']);
        }
    } catch(err) {

    }

});

Update

Since live is now deprecated you should use the on event instead, if you´re using jQuery 1.7+. http://api.jquery.com/on/

由于live现已弃用,因此如果您使用的是jQuery 1.7+,则应使用on事件。 http://api.jquery.com/on/

#2


4  

For those having problems with Phonegap and google analytics :

对于那些遇到Phonegap和谷歌分析问题的人:

Google code uses cookies and it doesn't work with file:// urls wich is what Phonegap uses. The Pokki team made a good implementation that uses localStorage in place of cookies. I made a fork on github to remove the need of pokki, so here is a solution that works with phonegap as a standalone library

Google代码使用Cookie,但它不适用于file:// urls,这是Phonegap使用的内容。 Pokki团队做了一个很好的实现,使用localStorage代替cookie。我在github上做了一个fork以消除对pokki的需求,所以这里有一个与phonegap一起作为独立库的解决方案

https://github.com/ggendre/GALocalStorage

hope this will help someone else :)

希望这会帮助别人:)

#3


0  

http://code.google.com/apis/analytics/docs/mobile/overview.html http://analytics.blogspot.com/2009/10/google-analytics-now-more-powerful.html

These are references, please read for your knowladge.

这些是参考,请阅读您的知识。