15 February 2016
Announcing the Google Analytics plugin
Under the category of “The more you know,” we’ve increased our suite of analytics engine support with the Google Analytics plugin.
In addition to basics like the number of users and sessions, you get a wealth of demographic information about your users such as city, country, language, and “new” versus “returning” users. You also get detailed information like the app version, which OS it’s running on, the device type, screen resolution, and more. Finally, you can track custom events within the app, for example the user’s actions, which UI elements are interacted with the most, and more.
Setting up Google Analytics
To use Google Analytics, you must first set up an account with Google at www.google.com/analytics/. You can have up to 100 accounts under a single login, each account can have up to 50 properties, and each property can have up to 25 views. While each of your apps could be its own account, you’ll probably just need one account with each app as a unique property of it.
To begin, activate the Google Analytics plugin here.
Next, you’ll need to include the plugin within the app’s build.settings
:
1 2 3 4 5 6 7 8 9 10 11 |
settings = { plugins = { ["plugin.googleAnalytics"] = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true, android=true, } }, }, } |
When you create a property in the Google Analytics dashboard — assigning the app name along with it — you’ll get a unique Tracking ID such as UA-12345678-1
. You’ll need to pass both of these values to the googleAnalytics.init() API. For example:
1 2 3 |
local googleAnalytics = require( "plugin.googleAnalytics" ) googleAnalytics.init( "Mega Race 3000", "UA-12345678-1" ) |
Logging analytics events
While simply setting up Google Analytics will give you insight into various demographic and device-related details as mentioned above, you’ll probably want to gather specific data about the user’s actions within the app. Some examples include:
- Checking how long users play the game. If the results aren’t meeting your expectations, you may consider adding incentives or additional features.
- Checking how often — and how long — users play a specific level in the game.
- Checking which options/settings are the most popular among a wide user demographic.
All of these examples involve logging events with Google Analytics. To log an event, simply call the googleAnalytics.logEvent() function:
1 |
googleAnalytics.logEvent( category, action, label ) |
The first parameter, category
, is a required parameter used to create a “group” of events within Google Analytics. For example, a category such as "userAction"
may be used to track actions performed by the user. Or, if your app interacts with a server and data is processed by the server, you might want a category named "serverAction"
.
The second parameter, action
, is a required parameter which associates a specific action with the category. For instance, if the user interacts with a button in your game, you could log an action of "buttonPressed"
in the "userAction"
category.
The third parameter, label
, is an optional parameter which lets you define additional information for the action, for instance the specific button which was pressed. For example, if the user pressed the “Play” button in your game, your googleAnalytics.logEvent() call might look like this:
1 |
googleAnalytics.logEvent( "userAction", "Button pressed", "Play" ) |
Ultimately, it’s your choice on which events should be logged, when, and why. We recommend a certain level of discretion in terms of which events/actions will be useful for analyzing user behavior in your app.
Tracking screens/scenes
The Google Analytics plugin features an additional tracking call which is used to track different screens. Google Analytics’ heritage is based on tracking website activity, which is “screen”-oriented, but the concept of screens can easily be compared to app scenes. This can give you insight on how frequently users visit particular scenes in your app, for example how often the “settings” scene is visited or whether users even view your “help” scene.
To track screen usage, use the googleAnalytics.logScreenName() function:
1 |
googleAnalytics.logScreenName( screenName ) |
This call simply requires a string which names your screen/scene. If you are using Corona’s Composer scene management library, you can simply add one line of code in the scene:show()
function’s "did"
phase to log the screen/scene name with Google Analytics:
1 2 3 4 5 6 |
function scene:show( event ) if ( event.phase == "did" ) then -- Log the screen/scene name with Google Analytics googleAnalytics.logScreenName( composer.getSceneName( "current" ) ) end end |
Additional notes
Like any analytics engine, data isn’t very useful until you’ve accumulated enough to analyze. A majority of the reports you can view need “aggregated” data, although some information is available “live.”
If you intend to track user information, you will likely need to include a privacy policy in your app or on your website so that users can learn about what is being tracked. If you require a privacy policy, please search the web for a template that can be adapted to your company/app.
In summary
As you can see, the Google Analytics plugin can be used to gain virtually any degree of insight about your apps, from user demographics to specific in-app usage patterns.
To learn more about the Google Analytics plugin, please proceed to our documentation, and if you have further questions, please visit the Corona forums.
Scott Harrison
Posted at 18:07h, 15 FebruaryI have submitted two plugins 2 weeks ago still nothing.
Rob Miracle
Posted at 18:14h, 15 FebruaryThis doesn’t seem like the right place to ask this question. Please email support AT coronalabs DOT com to see what’s going on.
Marcus
Posted at 19:07h, 15 FebruaryNice to see another addition to the plugin repository. Well done, guys.
jch_APPLE
Posted at 08:42h, 16 FebruaryThank you for this valuable plug-in, frequently requested by French customers.
Daniel
Posted at 14:35h, 16 FebruaryThis is excellent, however, in your build.settings sample on this page, you suggest to set osx=true, but when I run my app in the simulator, I get the following message “WARNING: The ‘plugin.googleAnalytics’ library is not available on this platform.” on build 2828?
Rob Miracle
Posted at 15:59h, 16 FebruaryThis plugin doesn’t work in the simulator. You can only run this on an Android or iOS device. You will continue to get this warning in the simulator.
Wilson Wan
Posted at 19:27h, 18 FebruaryThe logEvent function only sends category, action and label.
How about the label value (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ev)?
Gili
Posted at 02:01h, 19 FebruaryWill this plugin work on Kindle devices?
If yes, why don’t you add[“android-kindle”]=true to the supported platforms?
George
Posted at 08:50h, 15 AprilCan someone please reply to this?
Rob Miracle
Posted at 11:13h, 15 AprilNo, this is not a plugin available for Kindle Fire devices.
George
Posted at 11:52h, 15 AprilThank you for the quick reply Rob. Are there any plans to support Kindle devices? I think all that is needed to support Kindle devices is to add a couple of lines to the AndroidManifest file.
Rob Miracle
Posted at 12:14h, 15 AprilLet me try to explain. We need an SDK from the provider, Google Analytics in this case. Most of our providers do not offer an Amazon Kindle SDK for us to use. The plugin requires the Google Play plugin on Android. Any Android device that has Google Play installed can use the GA plugin. Since there is no Kindle Fire SDK and Kindle Fires tend to not have Google Play installed. There is nothing we can do about this until Goggle produces an Amazon Kindle Fire SDK or Amazon adds Google Play to their Kindle devices.
George
Posted at 12:36h, 15 AprilHey Rob,
It’s my understanding that the same SDK should work for Kindle. The only difference is that on devices that don’t have Google Play, you need to export/enable a couple of services in the app’s manifest.
https://developers.google.com/analytics/devguides/collection/android/v4/dispatch#background
I could be mistaken though, but that’s what the guide seems to imply.
Renato - Red Beach
Posted at 20:54h, 20 FebruaryJust tested Google Analytics here and it appears that the “label” is NOT optional. ( ERROR: googleAnalytics.logEvent() label expected, got: no value).
Also, as @WILSON WAN mentioned, why we don’t have the “value” param?
Marcus
Posted at 05:01h, 12 AprilAnyone managed to get this to work for iOS?
George
Posted at 13:09h, 15 AprilMy first test doesn’t seem to be working on iOS. It’s working on Android though. Is there a known problem on iOS?
Sam
Posted at 14:50h, 24 AprilI can’t get this to work on iOS or Android… I don’t seem to be getting any errors, just nothing shows up in my GA. I’ve followed the directions, activated the plugin, I have my GA set up, and my tracking code with app name correctly in the init, and nothing is showing…
Also, I think they should add something so it doesn’t crash the simulator. If you are using the simulator to build the app then it seems like they should put an if statement in there saying if simulator then don’t run… It adds more lines of code for me that I feel like don’t need.
Sam
Posted at 15:56h, 24 AprilGot it to work on Android, it was just very delayed for some reason… still not working on iOS
Rob Miracle
Posted at 07:40h, 25 AprilSam, it sounds like you’re having some problems with this. Since we are going to need to see your build.settings at a minimum, please ask this question in the forums. https://forums.coronalabs.com/forum/631-corona-premium-plugins/
and we will get you some help. For the Simulator, you’re right it doesn’t run, but it should have downloaded what we call a “stub plugin” that keeps the simulator from erroring out but instead print a message in the console telling you to test on device.
Daniel
Posted at 23:51h, 05 MayDo you have plugin for Google Tag Manager?
Rob Miracle
Posted at 13:13h, 06 MayNo we don’t. You can go to http://feedback.coronalabs.com and put in a feature request for this.
Daniel
Posted at 01:24h, 03 AugustYour latest update to this plugin 2016.2906, seem to be crashing on Android. I didn’t change a line of code. Works fine on iOS. Doesn’t help to downgrade Corona SDK. Doesn’t help remove Facebook v4 plugin.
Javier
Posted at 16:49h, 09 AugustHave any experienced a problem using this plug in related to the IDFA on apple?