I´ve encountered a problem with implementing Google Analytics on a LibGDX Game App. I want to track the screens of the game, but Google Analytics works only in the android folder part of the Gradle project. In the core part, it doesn´t get the Context for the game screen classes, although I´ve added the libGoogleAnalyticsServices.jar to the core folder also. I´ve searched for solutions over the internet, but nothing worked out so I cannot initialize Google Analytics in the core part of the project.
This is a code snippet where I try to initialize Google Analytics:
GoogleAnalytics GA = GoogleAnalytics.getInstance();
and it gives me this error “ The type android.content.Context cannot be resolved. It is indirectly referenced from required .class files ”
Should I use the libGoogleAnalyticsServices.jar of the Android project in the Core also or should I use another jar file for this task?
Below are some links where I found information for this issue.
Google Event Tracker v3 https://developers.google.com/analytics/devguides/collection/android/v3/migration http://badlogicgames.com/forum/viewtopic.php?f=11&t=4298
Any answer on this specific issue would be very useful. Thank you in advance.
You should use the Google Analytics sdk only in the android project, not in the core project. In the core project should only be platform-independent code. Don't import android libs into your core project.
If you want to track a screen view within core project you should can achieve that by using an interface. There is a wiki guide for interfacing libgdx
Your interface for tracking screen views could be something similar to this:
public interface Trackable {
public void trackScreen(String screenName);
}
In your android project this method would then implement the Google Analytics tracking code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With