Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to integrate the Game Analytics for iOS and Android at the same time
Started by arkiteknova Apr 21 2019 11:48 AM

4 replies to this topic
game analytics gameanalytics ios android
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

arkiteknova

[GLOBAL: userInfoPane.html]
arkiteknova
  • Observer

  • 3 posts
  • Corona SDK

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?



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,201 posts
  • Enterprise

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


[TOPIC: post.html]
#3

arkiteknova

[GLOBAL: userInfoPane.html]
arkiteknova
  • Observer

  • 3 posts
  • Corona SDK

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.



[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,201 posts
  • Enterprise

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



[TOPIC: post.html]
#5

arkiteknova

[GLOBAL: userInfoPane.html]
arkiteknova
  • Observer

  • 3 posts
  • Corona SDK

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.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: game analytics, gameanalytics, ios, android