I fixed a crucial bug that prevented the framework from actually calling out to the google analytics server. This bug occurred on almost all 10.6 installations but not on 10.8 and was the result of a very slight change in the behaviour of cocoa's WebView class between OS releases which I mist.
NOTE: this class is not feature complete. It is specifically tailored to suit the needs for GA in the doo app and is also intended as Demo of how to use a JS SDK from Cocoa.
(If Google ever decides to port their iOS SDK to the mac, im all for it :) till then this approach works fine.)
how to use
The Framework is accompanied by a small demo app which you can use to test the available features of the tracker:
Also vailable via cocoapods
The Tracker has the following Properties and methods
This method tries to find a tracker for the specified Google Analytics account ID (the string that begins with "UA-") in an internal List. If no tracker for that ID is up, it inits a new one
starts this tracker
stops this tracker, flushing any calls left
@property(readonly) NSString *accountID;
the account ID
@property(readonly,getter = isRunning) BOOL running;
is the tracker running?
@property(nonatomic) NSUInteger batchSize;
use batching of requests. size<=1 = no batching It defaults to 0.
@property(nonatomic) NSTimeInterval batchInterval;
the max interval for dispatching batches. It defaults to 0.
@property(readwrite) BOOL debug;
If the debug flag is set, debug messages will be written to the log. It is useful for debugging calls to the Google Analytics SDK. By default, the debug flag is disabled.
@property(readwrite) BOOL dryRun;
If the dryRun flag is set, hits will not be sent to Google Analytics. It is useful for testing and debugging calls to the Google Analytics SDK. By default, the dryRun flag is disabled.
@property(readwrite) BOOL anonymizeIp;
If the anonymizeIp flag is set, the SDK will anonymize information sent to Google Analytics by setting the last octet of the IP address to zero prior to its storage and/or submission. By default, the anonymizeIp flag is disabled. Currently only takes effect if the the tracker has not been started yet.
-(BOOL)trackPageview:(NSString )pageURL withError:(NSError *)error;
Track a page view. Returns YES on success or NO on error. Note that trackPageview will prepend a '/' character if pageURL doesn't start with one.
-(BOOL)trackEvent:(NSString )category action:(NSString *)action label:(NSString *)label value:(NSInteger)value withError:(NSError *)error;
Track an event. The category and action are required. The label and value are optional (specify nil for no label and -1 or any negative integer for no value). Returns YES on success or NO on error.
configurable via additional preprocessor macros, when building the framework from source:
DEFAULT_BATCH_INTERVAL :: float
default value: 5.0
FREE_WEBVIEW_AFTER_BATCH :: bool
default value: 0
DEBUG_WEBVIEW_ENGINE :: bool
default value: 0