Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 beta is now available for download.
    Dismiss Notice

Google Universal Analytics for Unity - Support Thread

Discussion in 'Assets and Asset Store' started by tonic, Sep 25, 2013.

  1. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Introducing Google Universal Analytics for Unity.

    https://www.assetstore.unity3d.com/#/content/11098

    This package brings Google's Universal Analytics to Unity, with widest platform and Unity version coverage using the same asset. This is the only Google Analytics integration library with all of the features listed below.

    • Ready-made Analytics component for drag'n'drop integration.
    Automatic sending of errors and exceptions to analytics.
    Automatic client System Info statistics (sent on first launch).
    Automatic events when new level/scene is loaded.
    Automatic caching of analytics hits when user is offline and throttled sending of cached hits in the background.
    Automatic reachability check which determines if client is offline or the analytics server is reachable. (Generalized version of this feature alone is also available as a separate product: Internet Reachability Verifier).
    • Use the same code to implement analytics for Desktop, Mobile and Web builds!
    • Browser: Unity Web Player plugin
    • Browser: Unity 5 WebGL (NEW!)
    • Desktop: Windows
    • Desktop: Mac OS X
    • Desktop: Linux
    • Desktop: Windows Store
    • Mobile: iOS
    • Mobile: Android
    • Mobile: Windows Phone
    • Mobile: BlackBerry 10
    (Not tested on console platforms, but if UnityEngine.WWW class works, then this should as well.)
    • Note: No support for certain platform-specific features, such as demographics reporting or automatic tracking of traffic sources (iOS / Android specific).​
    • Example scenes to show functionality and how to implement user opt-out possibility.
    • Comes with guide to set up your tracking property to a Google Analytics account, integration instructions and helpful hints how to interpret analytics results and make a custom report.
    Complete API for the Measurement Protocol of Google Analytics.
    • Support for new set of Enhanced E-Commerce analytics (first integration library to add that!).
    • HTTP and HTTPS support.
    • Toggleable debug warnings, e.g. if you're going over session hit limit (enabled by default when running inside editor).
    • Doxygen documentation for the code.
    • Designed with goal of having minimal amount of memory allocations.
    • Custom-built user agent strings on the platforms where that's required to improve detection by Google Analytics.
    Full source code included. Implemented in Unity with C#.
    • No need for big platform-specific library files.
    • No need to tweak project files for each platform.
    • Maintained for Unity 4.x, Unity 3.5.7 and Unity 5.x.

    Note: The analytics service itself is run by Google, and offered for free.

    Edited 2016-01-29: Updated info for version 1.6.2 release.
     
    Last edited: Jan 29, 2016
  2. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Next update will add support for Unity v3.5!
     
  3. Psychor

    Psychor

    Joined:
    Jun 27, 2009
    Posts:
    14
    Hi there. Thinking about getting the plugin. Does it work for Windows Store Apps?
     
  4. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Short answer is that "it should". Hits to analytics are sent using the UnityEngine.WWW class, which is supported for Windows Store targets. But, we haven't personally tested it yet. (Would you like to spend a bit of time to help and test&verify Windows Store support? I'm sending you a private message!)

    EDIT:
    Psychor wrote back and told that running on Windows Store worked well after a minor fix (comment out single row referring to UnityEngine.Handheld class which isn't available when building for that platform). Thanks!
     
    Last edited: Nov 12, 2013
  5. mojtaba64

    mojtaba64

    Joined:
    Aug 3, 2010
    Posts:
    47
    Can we send Custom Dimensions Metrics, Crashes and Exceptions, etc with your package?
     
  6. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Custom Dimensions Metrics as well as Exceptions are part of the Google's spec for measurement protocol, which this package has an API for. So they should work just as well as the other features.

    However, there's some points to keep in mind:

    About Custom Dimensions Metrics -- You need to set them up in the Admin section of your Analytics account, and associate an index to them. For normal Google analytics account there's 20 indices to use, and for premium accounts they give you 200.
    More information in these pages: Custom Dimensions Metrics - Feature Reference and Set up custom dimensions metrics

    About Exceptions -- There's an Exception HitType, and possibility for optional description and "is exception fatal" boolean, which can be sent as a hit for the analytics. However, this package is not a product for intercepting crashes, so it's up to you to solve how to have a normal/stable state and have some real data to be sent to analytics. One way would be to write some code to read UnityEngine.CrashReport.reports on next application start and submit those as analytics (there isn't a ready-made example how to do that though; I might add that in the future).
     
  7. bustedkrutch

    bustedkrutch

    Joined:
    Jun 24, 2013
    Posts:
    20
    Hey Tonic,

    I spent all day today trying to figure out how to get Google Analytics to work with the Unity Webplayer and although I understand a lot more about the measurement protocol I was not able to hack my way into a solution so...

    I just want to make sure :) that your solution works with the Unity Webplayer Builds and sends to www.google-analytics.com directly without having to use an intermediate script on the website that hosts the Webplayer version of the game???

    It's important to me because I'm trying to limit the amount of concurrent connections to my hosting site.

    Thank you for what hopes to be an awesome solution!
     
  8. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    The answer is yes! This package has bit of extra code in it to make it work with the Web player builds as well.

    No need to add intermediate stuff to server hosting website.
     
  9. bustedkrutch

    bustedkrutch

    Joined:
    Jun 24, 2013
    Posts:
    20
    Tonic,

    Awesome! Very easy to setup and get tracking! Everything you said it would be, thank you!
     
  10. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Version 1.2.0 contains these changes:
    • revised up-to-date guide to set up your tracking property to a Google Analytics account
    • updated integration instructions and example scenes, now with persistent user opt-out toggle
    • added instructions how to create a custom report
    • updated the API to contain newest additions of measurement protocol
    Full info, version history and example running in web player:
    http://strobotnik.com/unity/googleuniversalanalytics/
     
  11. starvanger

    starvanger

    Joined:
    Oct 4, 2010
    Posts:
    12
    Hi Tonic,

    today I bought your Asset. Well Done. My Games are also spread on arcade sites, not using the GA code. So, I can use mobile as the property for Analytics. Is there a way to use GUA with all the features of websites, without the need of GA code on site? That is the way, free web games are spread. Any ideas?

    Thank you

    Starry
     
  12. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    The GUA web code works so that it injects javascript to the web page for sending analytics hits. It doesn't need modifications to the web page.

    So, as long as a particular web site doesn't do something weird in their site templates to make it incompatible with the technique, it should be possible to use this in such freely distributed web games as well. I don't have practical experience about this though.
     
  13. starvanger

    starvanger

    Joined:
    Oct 4, 2010
    Posts:
    12
    Hi Tonic,

    thank you for the answer. Yes. it works also without GA Code on the site, but the Google property for that site must be in mobile mode then. Or did I miss something? Were you able to track data in such a way? No GA Code on site, property on web mode?

    Greetings

    Starry
     
  14. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    I think it currently doesn't matter if you have created the property initially to track a Website or Mobile app, but instead it matters which kind of View you use (or create) to the property to check the data. You should use a "Mobile app" view for the analytics using this package.

    The way this stuff is set up in the Google Analytics site has been changed recently. Please make sure you have the latest version of this package (now 1.2.0), which also has an updated setup instructions pdf.
     
  15. starvanger

    starvanger

    Joined:
    Oct 4, 2010
    Posts:
    12
    Ok, got the point. Using 1.2. Using the props mobile as intended.

    Thx

    Starry
     
  16. Komikusac

    Komikusac

    Joined:
    Aug 11, 2012
    Posts:
    30
    I have a problem with iOS tracking. All data that comes in from that platform shows as (not set) and the devices do not show with their device names as Android devices do. What am I doing wrong? :)
     
  17. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Google Analytics should pick up the platform automatically from the User Agent string which is always part of the http requests sent, and use that to show as platform in the standard reports. But, that just doesn't seem to happen all the time, or at least not for all users, and unfortunately there's no way to force the platform/OS manually for the requests. Some other users have also reported this same issue, which is something Google needs to fix.

    I suggest you try (and verify) some or all of the following steps:
    1) Make sure you have upgraded to latest version (currently 1.2.0) of this package. This isn't going to fix anything by itself, but ensures you have the latest instructions how to set up.
    2) Verify your Property in the Google Analytics site is enabled for Universal analytics (i.e. you property shouldn't show "Universal Analytics Upgrade" / "Transfer not started" button).
    3) Try to make a new View for your Property in the analytics web site, and select "Mobile app" for that view. Then make some new hits (and wait for at least 24 hours), and see if you see the hits properly when using that new view.
    4) If that doesn't work, you could also try if creating a totally new Property helps. Follow the updated instructions in Instructions_GoogleUniversalAnalyticsForUnity.pdf.
    5) While this is not exactly the same thing than having the platform correct in the default reports, but you can try to create a custom report and use the data which is part of SystemInfo events sent by Analytics.cs on first launch. To see how to do an "OS from Events" custom report, read the chapter "Example of Creating a Custom Report" in the Instructions_GoogleUniversalAnalyticsForUnity.pdf.
     
  18. jesper42

    jesper42

    Joined:
    Jan 11, 2011
    Posts:
    23
    Hi Komikusac

    I'm having the same problem: iDevices aint recogniced by GA :(

    I've tried your suggestions but they don't seem to fix the issue.

    The root problem must be that the WWW post request useragent header is wrongly formed (according to GA) when on iOS devices. (??)

    I've just read that it actually is possible to supply ones own headers in the "new WWW(...)" call as a third parameter (a hashtable of headers).

    http://docs.unity3d.com/Documentation/ScriptReference/WWW-ctor.html

    ...

    Do you know how to form the useragent string so that GA will parse it correctly?

    With a little "#if UNITY_IPHONE" magic it might be possible to get this working :D

    Cheers,
    Jesper Rasmussen
     
  19. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    I had totally missed that one. Thanks for the tip!

    I will investigate this soon and see if the iOS detection can be fixed this way like you suggested.
     
  20. jesper42

    jesper42

    Joined:
    Jan 11, 2011
    Posts:
    23
    Cool ... :D

    Any ideas on when you have the time to look at it?

    I'm having a release on Wednesday where it would be really nice if it could detect them iThings correctly.

    Cheers,
    Jesper
     
  21. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    I haven't yet gotten around that as I'm working on an another thing for asset store which I'm trying to get released asap. Iterating that part of the analytics requires me to wait a day until I can see if it worked or not, so to get it ready for Wednesday I'd have to make a right guess of how to fix it and send tests with that today or early tomorrow... to be able to verify before Wed if it worked or not. I'll try to squeeze in bit of time to work on that now, but I can't promise to be able to fix that for your release as it's so soon. If I will manage to do it, I'll send you a PM with needed info (or email, if you PM me your email address first).
     
  22. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Ok, the iOS device detection will be fixed in the next release. :D
     
  23. jesper42

    jesper42

    Joined:
    Jan 11, 2011
    Posts:
    23
    Good, good ... do you have any idea when that would be? :D

    Well luckfully the release today is "only" our soft release.

    For this I'd just add

    gua.sendEventHit("Session", "deviceModel", SystemInfo.deviceModel);

    to the endSession.

    ---

    Btw. there's a small bug in the sendHit function of GoogleUniversalAnalytics.cs

    The line:
    if (sessionHitCountResetPending) sessionHitCount = 0;

    Should be :
    if (sessionHitCountResetPending) {
    sessionHitCount = 0;
    sessionHitCountResetPending = false;
    }

    ... or equivalent :)

    Cheers,
    Jesper
     
  24. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    I sent you a PM with url to the updated source files yesterday! :)
     
  25. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Version 1.3.0 has been submitted for approval, which uses custom-built user agent when running on iOS, to fix device type/category and OS version detection (iPhone / iPad / iPod Touch devices). It now also warns you if you are using tracking ID of the example scenes, and users LogError if you haven't set the tracking ID at all.

    Also, please check out this brand new asset:
    Dynamic Text for Unity.

    Dynamic Text website has more info examples why you need it, and it has an interactive demo you can try.
     
  26. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Version 1.3.0 is now available!
     
  27. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    805
    Hi! Great package, easy to use and setup!
    I have a question though.

    What is the best way to report an event for example something like this:
    - user pressed button (string sent with button name)
    - user enetered menu (string sent with menu name)

    sorry if this being obvious... :) but i am beginner in analytics.

    do you have any suggestions about what should be recoreded and what are best practices?
    Thank you very much!
     
  28. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Here is some examples, both have been copy-pasted from the AnalyticsExampleMainScreen.cs:

    For user pressing some button:
    (the 1st param for sendEventHit is event category, and the next one is name for the action.
    Code (csharp):
    1.  
    2.         if (GUILayout.Button("Strobotnik Web Site"))
    3.         {
    4.             Analytics.gua.sendEventHit("OpenWebsite", "Strobotnik.com");
    5.             Application.OpenURL("http://strobotnik.com");
    6.         }
    7.  
    For user entering a menu, i.e. a certain screen:
    Code (csharp):
    1.  
    2.         if (GUILayout.Button("Send \"Menuscreen A\" Hit"))
    3.             Analytics.changeScreen("AnalyticsExample - Menuscreen A");
    4.  
    If you look at the implementation of changeScreen method in the Analytics class, you can see it's actually just a super simple helper method, so the above changeScreen call is same thing as you would do this:
    Analytics.gua.sendAppScreenHit("Options menu");


    For some more ideas, check out the commented-out void exampleAnalyticsTestHits() at end of Analytics.cs file.
     
  29. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Just realized I forgot to answer this, sorry.

    It probably depends a lot about your project and needs to figure out what should be recorded into analytics, and what should not.

    When deciding that, remember to keep the session analytics hit limits in mind, especially limit of 500 hits per session (specified by Google here).

    Most of the time you should probably not track some very trivial things like "did somebody press back button in a sub-menu". Probably better to think first what kinds of questions do you want to be able to answer after collecting data, and then make sure your analytics integration sends the relevant stuff that you'll eventually be able to answer those questions.

    Google also runs online courses to learn more: Digital Analytics Fundamentals, Making Sense of Data (available soon)
     
  30. Victor_Kallai

    Victor_Kallai

    Joined:
    Mar 5, 2014
    Posts:
    123
    Hello, I just bought the plugin and I think it is awesome. But I can't figure out how to send some custom dimensions. When I try:
    gua.addCustomDimension (1, "Test_Dimension");
    I can't see anything in Analytics, even after 2 days. In analytics I get the message: "There is no data for this view.". What can I do? Can you give me a simple example on how to send a custom dimension and a custom metric?
     
  31. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Hi, to use custom dimensions/metrics, you need to set them up in the Google Analytics site.

    Please read more from this instruction page:
    "Set up or edit custom dimensions metrics"
    https://support.google.com/analytics/answer/2709829?rd=1

    It may also be helpful to check out these pages meant for developers as there may be some small details you're interested in:
    "Custom Dimensions Metrics - Web Tracking" (part of Universal Analytics docs)
    https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets
    "Measurement Protocol Parameter Reference - Custom Dimensions / Metrics"
    https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#customs
     
    Last edited: Nov 28, 2014
  32. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Adding to that, based on some hints found online and reports back to me, two things: (1) it seems that custom dimensions might get longer than usual time to update on the Google Analytics site. (2) You might need to actually use an event hit type, and attach the custom dimension to that.

    In any case, don't use custom dimensions if you don't really need them, as it's more hassle to set them up and their number is limited. Usually regular events are enough to track most own stuff, using your custom event category and action, so use them! :)
     
  33. solo024

    solo024

    Joined:
    Jun 5, 2013
    Posts:
    19
    Can I send analytics to 2 account at same time?
     
  34. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Out-of-the-box that isn't supported, as it's probably a very rare use case. But it should be relatively easy to modify the source code to allow that (change to use separate analytics objects instead of a common static singleton instance).
     
  35. lilboylost

    lilboylost

    Joined:
    Feb 12, 2014
    Posts:
    254
  36. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    There's no ready-made support for any platform specific things like that.

    However, you can of course make some own code to listen for the INSTALL_REFERRER intent on Android, and then write the small bit of code which sends that info to analytics using the API provided by this package. (And similar things for other platforms if there even are ways to do the equivalent tracking for all of them.)
     
  37. dharms

    dharms

    Joined:
    Nov 10, 2012
    Posts:
    26
    Offline caching is a huge deal maker or breaker for our application, as it's meant to be used outdoors and doesn't require any internet access otherwise to function properly. This asset looks great and we'd love to use it - do you happen to know when offline caching will be available?
     
  38. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Quite a few have asked about the offline caching, so I'll make that a priority for next update, hopefully available in this or next month.

    Note that Google Analytics still has limited "queue time", meaning that if the cached hits are too old, they may not be processed. (The limit is officially 4 hours by the measurement protocol specification, but I think some analytics forum post said it's actually not that strict, it could be more close up to next day or so.)
     
  39. solo024

    solo024

    Joined:
    Jun 5, 2013
    Posts:
    19
    Hi, mobile, stand build all worked for me, but the web build won't work, no matter in editor or build out. I have tried with both google web and app property, none of them receiving any income from web build. Is there any setting I need do for web build?
    By the way I'm using v1.30
    thanks
     
    Last edited: Apr 11, 2014
  40. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Hi! Indeed analytics for a web build doesn't work when run inside editor.

    But it should work fine when you make a build and run inside a browser (having the unity web player installed). Can you please verify again that (1) in your analytics property you're using a view for Mobile app, (2) you have set the correct tracking ID to your Analytics object in Unity, (3) you have set the app name to the Analytics object in Unity.

    This way you should be able to see incoming hits immediately in the realtime view. Otherwise most of the analytics data will be processed after a delay, generally should be available after you wait for one day.
     
  41. solo024

    solo024

    Joined:
    Jun 5, 2013
    Posts:
    19
    Thanks, It worked, I build out wrong scene when test web build out.:p
     
  42. chirhotec

    chirhotec

    Joined:
    Mar 30, 2010
    Posts:
    47
  43. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Thanks for the hint. They have indeed changed that, and a few other things too - I have old copies of the spec web page so that I can make a diff and compare what's new from the last time I checked through it.

    The next update will reflect the changes. (Meanwhile the appview hit type still works.)
     
  44. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    If you've been thinking of buying this asset but haven't yet done so, now's your chance to get it a bit cheaper.

    The Google Universal Analytics is now in 50% sale, being part of the May Asset Store Madness sale!
    https://www.assetstore.unity3d.com/#/content/11098

    Also, I'm still working on the next update (v1.4.0), which will add support for caching hits when being offline. It's mostly done, but I think I will still need to add a little bit better detection if the device can actually reach the internet (not relying only on Application.internetReachability).
     
  45. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    989
    have you implemented user agent for all these platforms?

    Browser: Unity Web Player plugin
    Desktop: Windows
    Desktop: Mac OS X
    Desktop: Linux
    Desktop: Windows 8 (Windows Store)
    Mobile: iOS
    Mobile: Android
    Mobile: Windows Phone 8
    Mobile: BlackBerry 10

    will i see operating system data on GA?
     
  46. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    By default no custom user agent is used, but instead the one implicitly specified by Unity's own WWW class is used.

    Currently iOS platforms are an exception to this since GA (Google Analytics) doesn't recognize the default user agent string properly. So on iOS a custom user agent string is built which has enough info to make a difference between iPhone, iPad and iPod, and also contains the OS version.

    I'm not fully sure if all your listed platforms and their variants if they are detected perfectly. If needed, that will be further refined with future version updates. Starting from next version (1.4.0) there will be also an easy way to tweak that yourself as well, as new setUserAgent method will be added (specifying forced user agent was added to measurement protocol specs as well).

    You can also use the regular events for collecting more detailed info, and in fact the Analytics MonoBehaviour component by default has code which sends detailed system info statistics on the first launch.

    So yes, you can see OS data in GA.
    There can be some entries which show as "(not set)", since running in editor will only identify with UnityPlayer user agent with no OS shown.
     
  47. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    989
    thanks for info. are you sure about Windows Phone 8? i used www class and i had to implement my custom headers. i do not want to deal with all platforms, so i want to buy your asset. before buying it i want to be sure if it works well for all platforms that you listed on your page. if you tested and see Windows Phone on GA it will be ok for me.
     
  48. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    I just checked again with a WP8 device how running the example scene gets reported.

    The realtime view of GA doesn't let me see the exact detected OS (i.e. I have to wait until next day to see full data).

    However, two things were correct which can be seen right away:
    1) the session was shown to be "mobile" rather than desktop (the realtime view shows these w/different colors)
    2) the 1st-time-launch SystemInfo events (feature of this asset, sent by Analytics.cs) showed that the operatingSystem event was correctly shown as Windows Phone 8.0. There are 25-30 of these SystemInfo events which are sent when a user starts the app for the first time on the device, and they show lots of other useful data as well like graphics capabilities. The operatingSystem event data can be used to see the OS even if the GA itself fails to detect platform/OS from user agent.
     
  49. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    316
    Just verified the results - the operating system was properly detected by GA. Only if you clicked through then the exact version wasn't shown. But even the device type was properly shown as "Nokia Lumia 620", which is the device I used for the test.
     
  50. lilboylost

    lilboylost

    Joined:
    Feb 12, 2014
    Posts:
    254
    Does Asset implement whole of Measurement protocol? I cannot see the documentation without purchasing it.

    All these parameters: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
    including:
    1) Traffic sources - https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#trafficsources
    If yes, does it auto read the campaign source and submit the info to GA?
    2) E-commerce - https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ecomm