How to integrate the Game Analytics for iOS and Android at the same time

Hi Everyone,

This might be a newbie question, but I have been breaking my head on this one.

I have a game that is distributed in the App Store and Google Play Store.

I want to use gameanalytics.com to retrieve analytics from my game.

Gameanalytics.com requires me to have a different game (with it’s own key) for each platform. So this means that I have two keys. One for iOS and one for Android.

However in the Lua code in my game I can only initialise the Gameanalytics plugin with one key. 

Is it best practice to use system.getInfo(“platform”) to retrieve the current platform (iOS or Android) and then initialise the Gameanalytics plugin with the corresponding key? Or is there any other best practice?

You have the basic idea. Here is the GA code from my game:

myData.GAgameKey = nil myData.gameanalytics = nil if myData.platform ~= "ios" or myData.platform ~= "android" then return end myData.gameanalytics = require("plugin.gameanalytics\_v2") if "ios" == myData.platform then myData.GAgameKey = "my iOS gameKey" myData.GAgameSecret = "my iOS gameSecret" elseif "android" == myData.platform then myData.GAgameKey = "my Android gameKey" myData.GAgameSecret = "my Android gameSecret" end print("\*\*\*\*\* initializing GameAnalytics", myData.GAgameKey) if myData.GAgameKey then myData.gameanalytics.configureAvailableResourceCurrencies({ "coins", "coffee", "pickup"}); myData.gameanalytics.configureAvailableResourceItemTypes({ "coin", "bomb", "health", "EMP", "freeze", "toxic", "nuke"}); myData.gameanalytics.configureAvailableCustomDimensions01({"fighter", "warrior", "knight"}); myData.gameanalytics.configureBuild( "1.0.0" ) print("Calling GA.init()") myData.gameanalytics.initialize { gameKey = myData.GAgameKey, gameSecret = myData.GAgameSecret } end

Hi Rob,

That’s almost exactly how I ended up implementing it. Nice to know that I was on the right track.

Thanks so much!

I also noticed that switching between the two keys on the same device during Live Build, has some unexpected behaviour. Can it be that there is some caching going on? I know that this is not relevant anymore with the current implementation strategy, but I was just curious.

Live builds has no idea what your code is actually doing. It simply detects changes and tells the device to reload. If your code isn’t doing platform detection, it has no way to pick which API key to use, so if you have an android key selected and live builds reloads the iOS app with the Android key. The device detection code assures the right key will be used when the app reloads.

Rob

Hi Rob,

I understand, but this behaviour occurred before I implemented the device detection. E.g. I had Live build on an iOS device with the iOS API key. Events are being sent to my iOS game account in Game Analytics as expected. I then manually change the API key to the Android API key. After the Live build syncs, the events are still being sent to my iOS game account. Only after I remove the App from my phone and reset Live build, the events are being sent to my Android game account in Game Analytics.

However, I have to reproduce this to make a good case, but I think it is not so relevant, because this is a situation that should not occur in real life.