This RoboPod requires you to download and add the native 3rd party libraries manually:
- Download the SDK from https://developers.google.com/analytics/devguides/collection/ios/v3/sdk-download
- Put the
libGoogleAnalyticsServices.a
file in your iOS project'slibs/
folder - Add the following to your
robovm.xml
<config>
...
<libs>
<lib>libs/libGoogleAnalyticsServices.a</lib>
</libs>
</config>
Add the following dependency to your build.gradle
:
dependencies {
... other dependencies ...
compile "org.robovm:robopods-google-analytics-ios-noads:$robopodsVersion"
}
Add the following dependency to your pom.xml
:
<dependency>
<groupId>org.robovm</groupId>
<artifactId>robopods-google-analytics-ios-noads</artifactId>
<version>${robopods.version}</version>
</dependency>
If you are planning to use ads in your app, you should use the robopods-google-analytics-ios
artifact.
Add the following dependency to your build.gradle
:
dependencies {
... other dependencies ...
compile "org.robovm:robopods-google-analytics-ios:$robopodsVersion"
}
Add the following dependency to your pom.xml
:
<dependency>
<groupId>org.robovm</groupId>
<artifactId>robopods-google-analytics-ios</artifactId>
<version>${robopods.version}</version>
</dependency>
Google Analytics does not require SDK initialization to allow you to track events.
However it is highly recommended to use a Google Service configuration file if you plan on using more
Google services than just Analytics. You will then have all your keys in one place.
Go to Google Developers and follow the instruction to create your configuration file.
Copy the generated file to a resource folder of your app that will get bundled with your app
(the folder should be specified as a resource in your robovm.xml
).
Add the following code to your application's entry point, typically didFinishLaunching()
in your app delegate.
try {
GGLContext.getSharedInstance().configure();
} catch (NSErrorException e) {
System.err.println("Error configuring the Google context: " + e.getError());
}
Now all your Google services are setup.
When setting up a Google service it's very helpful to get logs.
Add the following code to your application's entry point, typically didFinishLaunching()
in your app delegate.
GAI gai = GAI.getSharedInstance();
gai.getLogger().setLogLevel(GAILogLevel.Verbose);
Note: Don't forget to disable debug logging when you release your app!
To enable crash reporting run the following code (preferably as early as possible in your app):
GAI gai = GAI.getSharedInstance();
gai.enableCrashReporting();
Note: You can only have one (1!) crash reporting service in your app! If you use multiple crash reporters no crashes will be reported!
- Make sure you have setup your app in your Google Play Developer Console.
- Check your logs for any errors, like network failures.
Gather analytics data for your app.
To track any events you have to obtain an instance of GAITracker
.
If you setup Google Analytics with a configuration file you can get the default tracker:
GAITracker tracker = GAI.getSharedInstance().getDefaultTracker();
If you want a specific tracker use the following code:
GAITracker tracker = GAI.getSharedInstance().getTracker("MY-TRACKER-ID");
Now it's time to create the event. Events are just maps of keys and values stored in a NSDictionary
.
There are two ways to build the event dictionary:
A. Manually create a NSMutableDictionary
and fill it. Use the the fields in GAIFields
and GAIEcommerceFields
as keys:
NSDictionary<?, ?> event = new NSMutableDictionary<>();
event.put(GAIFields.EventCategory(), "ui_action"); // Event category (required)
event.put(GAIFields.EventAction(), "button_press"); // Event action (required)
event.put(GAIFields.EventLabel(), "play"); // Event label
event.put(GAIFields.EventValue(), 10); // Event value
B. Use the handy GAIDictionaryBuilder
:
NSDictionary<?, ?> event = GAIDictionaryBuilder
.createEvent("ui_action", // Event category (required)
"button_press", // Event action (required)
"play", // Event label
null).build(); // Event value
If you have parameters that you want to send with every event you can specify them directly on the tracker:
tracker.put(GAIFields.ScreenName(), "Home Screen");
With the tracker and the event in place, we only need to send the event:
tracker.send(event);
Run your app and trigger some event tracking code. If you enabled debug logging, you should see logs confirming your event tracking.
- Make sure you have setup your app in your Google Play Developer Console.
- Check your logs for any errors, like network failures.