How to do mobile analytics using Jquery mobile

前端 未结 2 1025
一向
一向 2021-02-06 06:57

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

2条回答
  •  终归单人心
    2021-02-06 08:00

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

提交回复
热议问题