Google Analytics with ga.js not working

4 posts, 0 answers
  1. JohnVS
    JohnVS avatar
    76 posts
    Member since:
    Apr 2013

    Posted 30 Sep 2013 Link to this post

    We are using Icenium for our mobile project. We have an index.html file in Icenium that sets up our app to use Kendo (via a call to "new kendo.mobile.Application()" ). We then have our app pulling remote views from an MVC 4 solution via Ajax. All of this works perfectly. We are using the Device Simulator to test.

    We came upon this issue when trying to integrate Google Analytics (GA). I got our GA code to work on another website, then copied the code to this project. In the index.html file in Icenium, I pasted this code in the <head> of the page (account # scrubbed):

    <script>
        var _gaq = _gaq || [];
        _gaq.push(
            ['_setAccount', 'UA-XXXXX-4']
        );
     
        (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);
        })();
    </script>


    Then, in each remote view that is pulled via Ajax, we have this piece of code included:

    <script>
        $(function () {
            if (typeof (_gaq) !== "undefined") {
                _gaq.push(['_trackPageview', '/Home/Index']);
            }
        });
    </script>


    The problem is that even with this piece of code included, the "utm.gif" request is never sent to GA. First, I set "debugger;" right after the push() call to make sure the code was hitting it, and it was. Then, I found that Google provides a debugging JS file for GA, so I used that file instead to see what was going on (just replace "/ga.js" with "/u/ga_debug.js" in the <head>).

    At that point, I refreshed the Device Simulator, and this is what shows in the console:

    _gaq.push processing "_setAccount" for args: "[UA-XXXXX-4]":  console-via-logger.js:182
    _gaq.push processing "_trackPageview" for args: "[/Home/Index]":  console-via-logger.js:182
    Track Pageview


    When I use the same debugging JS file from GA on my other website, there is another console entry after the "Track Pageview," which says, "Tracking beacon sent". As you can see, the tracking beacon is not sent in our Icenium project. It gets to the point of outputting "Track Pageview" but we just cannot get it to send the actual request to GA.

    Is there something obvious we are missing? Is there some "gotcha" with Icenium that is keeping the request from being sent to GA? Any help is greatly appreciated!
  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 03 Oct 2013 Link to this post

    Hi John,

    Switch the Icenium simulator to use Android device so you can get the actual loged info instead of the console-via-logger.js:182.

    On a side note, although I could not find this stated directly, I do not belive the GA code would work on a hybrid app, be it executed in a webview on the device. That is why some kind people have created a custom Cordova plugin to handle this for Cordova apps: GAPlugin.

    Regards,
    Steve
    Telerik
    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  3. JohnVS
    JohnVS avatar
    76 posts
    Member since:
    Apr 2013

    Posted 03 Oct 2013 Link to this post

    Is there a specific reason that GA won't work along with Cordova, without a plugin? We are just confused about this, since we include the GA JS file on the page, then we used GA's documentation to find out how to do a call to _gaq.push(['trackPageview', '/Home/Index']) on each remote view that is loaded by the hybrid app. This works perfectly on our Kendo Mobile app that runs the mobile version of our website, since it just simply sends the GA request to them with the analytics info. Why would that call to .push not get transferred to GA from our project in Icenium? It seems that it should be working, unless there is something in Cordova or other software that is interferring with GA. Can you shed any light on that? Thanks.
  4. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 08 Oct 2013 Link to this post

    Hello John,

    This blog post covers the Cordova/Google analytics matter in more depth.

    Regards,
    Steve
    Telerik
    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
Back to Top