This is a migrated thread and some comments may be shown as answers.

Google Analytics with ga.js not working

3 Answers 91 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
JohnVS
Top achievements
Rank 1
JohnVS asked on 30 Sep 2013, 10:19 PM
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!

3 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 03 Oct 2013, 01:35 PM
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.
0
JohnVS
Top achievements
Rank 1
answered on 03 Oct 2013, 01:39 PM
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.
0
Steve
Telerik team
answered on 08 Oct 2013, 10:57 AM
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.
Tags
General Discussion
Asked by
JohnVS
Top achievements
Rank 1
Answers by
Steve
Telerik team
JohnVS
Top achievements
Rank 1
Share this question
or