-
Notifications
You must be signed in to change notification settings - Fork 377
How to setup google analytics or similar
AVAILABLE SINCE BAKER 4.2 - FEATURE STILL IN DEVELOPMENT
For more insights, read:
- https://support.google.com/analytics/answer/2614741?hl=en
- https://developers.google.com/analytics/devguides/collection/ios/v3/events
Get the analytics library you want to use. A few options are:
- Google Analytics for iOS
- Countly with the iOS SDK
Add the library to your Baker Xcode project. In case of Google Analytics SDK 3.0 you must add:
- GAI.h
- GAITracker.h
- GAITrackedViewController.h
- GAIDictionaryBuilder.h
- GAIFields.h
- GAILogger.h
- libGoogleAnalyticsServices.a
Please note that there's also a libGoogleAnalytics_debug.a
, but it will not work (unless you know what you're doing). Specifically, the Google Analytics SDK uses the CoreData and SystemConfiguration frameworks, so you will need to add the following to your application target's linked libraries (select the Target and add them under Summary):
- libGoogleAnalyticsServices.a
- CoreData.framework
- SystemConfiguration.framework
Open BakerAnalyticsEvents.m
and:
- Import the library adding at the beginning of the file:
-
#import "GAI.h"
and#import "GAIDictionaryBuilder.h"
for Google Analytics -
#import "Countly.h"
for Countly
- Add the tracking initialization inside the function
init
with your tracking keys, as provided by the service.
-
tracker = [ [GAI sharedInstance] trackerWithTrackingId:@"YOUR_TRACKING_KEY" ];
for Google Analytics -
[ [Countly sharedInstance] start:@"YOUR_APP_KEY" withHost:@"https://YOUR_API_HOST.com" ];
for Countly
Again in BakerAnalyticsEvents.m
add the event calls you need under receiveEvent:
.
For example, using Google Analytics it could be something like:
if ([[notification name] isEqualToString:@"BakerApplicationStart"]) {
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action" // Event category (required)
action:@"open" // Event action (required)
label:@"Baker App Open" // Event label
value:nil] build]]; // Event value
} else if ([[notification name] isEqualToString:@"BakerIssueDownload"]) {
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action" // Event category (required)
action:@"open" // Event action (required)
label:@"Baker Issue Download" // Event label
value:nil] build]]; // Event value
} else if ([[notification name] isEqualToString:@"BakerIssueOpen"]) {
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action" // Event category (required)
action:@"open" // Event action (required)
label:@"Baker Issue Open" // Event label
value:nil] build]]; // Event value
} else if ([[notification name] isEqualToString:@"BakerIssueBuy"]) {
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action" // Event category (required)
action:@"open" // Event action (required)
label:@"Baker Issue Buy" // Event label
value:nil] build]]; // Event value
} else if (...) {
// add more
}
Using Countly can be something like:
NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys: @"More data", @"Baker", nil];
if ([[notification name] isEqualToString:@"BakerApplicationStart"]) {
[[Countly sharedInstance] recordEvent:@"Baker App Open" segmentation:dict count:1];
} else if ([[notification name] isEqualToString:@"BakerIssueDownload"]) {
[[Countly sharedInstance] recordEvent:@"Baker Issue Download" segmentation:dict count:1];
} else if ([[notification name] isEqualToString:@"BakerIssueOpen"]) {
[[Countly sharedInstance] recordEvent:@"Baker Issue Open" segmentation:dict count:1];
} else if ([[notification name] isEqualToString:@"BakerIssueBuy"]) {
[[Countly sharedInstance] recordEvent:@"Baker Issue Buy" segmentation:dict count:1];
} else if (...) {
// add more
}