locked
Can I use google analytics in metro app? RRS feed

  • Question

  • Can I use google analytics in metro app?  Or more generically, can I use any javascript-enabled analytics tools?  If not, is there any guidance for tracking application usage?

    www.emadibrahim.com

    Friday, May 25, 2012 12:59 PM

All replies

  • What type of application usage are you looking for?  Isn't that analytics package for server usage?

    Jeff Sanders (MSFT)

    Friday, May 25, 2012 1:41 PM
    Moderator
  • I would also be interested in that. Would it be possible to load 

    google-analytics.com/ga.js

    into the metro apps script engine and measure clicks and page visits easily via GA?

    Sunday, July 1, 2012 9:03 PM
  • You cannot load remote script into the local context in a JavaScript application.  You would have to load that script in the web context, which would limit what you could do with it.

    Have you looked at the details of the dashboard on the Windows Store?  Many basic analytics are automatically captured for you and are visible on your profile dashboard in the store.


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Monday, July 2, 2012 5:36 AM
  • To answer your last question: "If not, is there any guidance for tracking application usage?"

    Ref this link to know about the Analytics support provided on Store Developer Portal: http://blogs.msdn.com/b/windowsstore/archive/2012/05/10/making-customer-focused-decisions-with-adoption-reports.aspx, usage is one of them. Hope this helps.

    Friday, July 13, 2012 7:49 AM
  • Unfortunately the Analytics provided by MS are off by 48hours or more sometimes and overall not all the informations we would need. GA would allow us to track how often the user opens the app/nav bar, which commands he frequently uses.

    I think it would work if we just include the ga.js file with our package?

    Saturday, July 14, 2012 4:52 AM
  • Did you have any luck including the ga.js file?  Do you have any tips?

    Friday, September 21, 2012 1:39 PM
  • I have google analytics and flurry analytics (html apps are in closed beta for flurry) in my app

    For flurry I was able to avoid having a server hosting an HTML page (included the HTML page in my pass with the iframe pointing to ms-appx://flurryTracker.html however with Google Analytics I had to have a page on my server to actually get the data to show up.

    For google I had to create 1 html page which looked like the following:

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"> <head><title></title></head> <body> <div> <!-- Google Analytics Code --> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-BLAHBLAHBLAH']); </script> <script type="text/javascript" src="http://www.google-analytics.com/ga.js"></script> <script> window.addEventListener('message', trackMessage); function trackMessage(event) { if (window._gat) { var pageTracker = _gat._getTracker('UA-BlahBlahBlah');

    if (event.origin.indexOf("ms-appx://") === 0) { var data = event.data; var category = data.category; var action = data.action; var label = data.label var value; if (+label === label) { value = label; label = action; } var success = pageTracker._trackEvent(category, action, label, value); if (!success) { debugger; } } } } </script> </div> </body> </html>

    Then in my apps html code I did:

            <iframe id="googleTracker" src="http://myServer.com/ThePageAbove.html" height="0" width="0" onload="googleTrackerReady()"></iframe>


    Then in my apps JS code I did:

        var googleTrackerReadyPromise = new WinJS.Promise(function (c, e, p) {
            window.googleTrackerReady = c;
        });

        function track(action, label) {
            googleTrackerReadyPromise.then(function () {
                var data = {
                    category: googleTrackingCategory,
                    action: action,
                    label: label,
                    version: appVersionString,
                    appName: appName
                };

                console.log('Tracking: ' + action + (label ? (' : ' + label) : ''));

                document.frames['googleTracker'].postMessage(data, 'http://myServer');

        });
    }



    • Edited by Cobra Tap Saturday, September 22, 2012 3:07 PM
    • Proposed as answer by Cobra Tap Saturday, September 22, 2012 3:16 PM
    Saturday, September 22, 2012 3:06 PM
  • Am working on Windows 8 app. Even i came across same problem. But whatever method you have said its not working. Can you elaborate it? In iframe there is a function googleTrackerReady(), onload event. is that a promise? can you please elaborate it?

    Thank you

     
    Thursday, May 23, 2013 11:09 AM
  • You could also include this little framework:

    https://gist.github.com/pke/5635575

    and use it like this in your app:

    https://gist.github.com/pke/5635602

    This is coffeescript, but you can convert it to JS online yourself.

    Thursday, May 23, 2013 12:05 PM