Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do mobile analytics using Jquery mobile

I am looking for a good solution to do mobile analytics for Jquery mobile . I did check this question

Flurry Analytics vs Google Analytics on the mobile platform

but these are all solutions for a platform specific/ phone manufacturer specific but jquery mobile works on all platforms irrespective of the manufacturer or operating system. Essentially i am looking for a analytics solution for webapps.

Additional Info:- bango seems expensive at $49/month. Admob wont work since we dont need it for advertising and not for placing ads.

like image 651
pal4life Avatar asked Aug 11 '11 20:08

pal4life


People also ask

Is jQuery Mobile still used?

The team announced that the cross-platform jQuery Mobile project under its umbrella is fully deprecated as of October 7, 2021. New technologies for mobile app development have evolved since this project was launched in 2010, so we're encouraging developers to plan for this jQuery Mobile transition.

What is the use of jQuery Mobile?

The framework allows developers to build applications that can be accessed by the widest number of browsers and devices, whether it is Internet Explorer 6 or the newest Android or iPhone. Mobile jQuery also gives developers the ability to render basic content (as built) on basic devices.

What is the difference between jQuery and jQuery Mobile?

jQuery is a DOM manipulating/traversing and AJAX JavaScript framework. It abstracts out a lot of the complexity between the different browsers automatically. There are countless jQuery plugins that simplify many task. jQuery Mobile is a UI framework geared to mobile applications that is built on jQuery.

Does jQuery Mobile work with jQuery 3?

According to https://github.com/jquery/jquery-mobile/issues/8546#issuecomment-271163317, jQuery Mobile 1.5 will be compatible with jQuery 3. It doesn't seem to have been released at http://jquerymobile.com/ yet, so we might have to wait, or get it from their GitHub repo.


2 Answers

I'm using the following:

<script>
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-xxxxxx-xx']);

    (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);
    })();

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

        hash = location.hash;

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

    }

});
</script>

The 'pageshow' event fires even for the first page, so don't think you want to include the _trackPageview with the GA setup. Also, location.hash will return url with the "#" character so hash.subtr(1) cleans that off which will normalize hash/pushstate visitors.

Update 11/30/11: Added check for hash length for ie bug (from: Paulo Manuel Santos).

like image 83
Dan Avatar answered Oct 06 '22 18:10

Dan


I use the following bits of code for Google Analytics and it works well:

The following is pretty much the normal Google Analytics setup:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', '**-*****-**']);

(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);
})();

The update for jQuery Mobile is here so that each pseudo-page is logged:

$(document).delegate('[data-role=page]', 'pageshow', function (event, ui) {
    var url = location.href;
    try  {
        if (location.hash) {
            url = location.hash;
        }
        _gaq.push(['_trackPageview', url]);
    } 
    catch(error) {
        // error catch
    }
});
like image 22
Jasper Avatar answered Oct 06 '22 18:10

Jasper