Skip to content

Instantly share code, notes, and snippets.

Created April 28, 2010 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/382433 to your computer and use it in GitHub Desktop.
Save anonymous/382433 to your computer and use it in GitHub Desktop.
// Some code -- but where does it go?
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType () {
NSString *theAnchor = [[request URL] fragment];
if ([theAnchor hasPrefix:@"FAPI_LogEvent"]) {
NSString *textToLog = [theAnchor substringFromIndex:[@"FAPI_LogEvent" length]];
[FlurryAPI logEvent:textToLog];
return NO; // prevent the UIWebView from navigating to this anchor
}
}
// Accompanying JS
function flurryTrackEvent(text) {
window.location.href = 'FAPI_LogEvent' + text;
}
//
//
//
//
//
// Here's what's in FlurryAPI.h provided by Flurry:
@interface FlurryAPI : NSObject {
}
+ (void)startSession:(NSString *)apiKey;
+ (void)logEvent:(NSString *)eventName;
+ (void)logEvent:(NSString *)eventName withParameters:(NSDictionary *)parameters;
+ (void)logError:(NSString *)errorID message:(NSString *)message exception:(NSException *)exception;
+ (void)setUserID:(NSString *)userID;
+ (void)setEventLoggingEnabled:(BOOL)value;
+ (void)setServerURL:(NSString *)url;
+ (void)setSessionReportsOnCloseEnabled:(BOOL)sendSessionReportsOnClose;
@end
// I'm only interested in the logEvent method.
//
// In Obj-C you would call this using
[FlurryAPI logEvent:@"EVENT_NAME"];
// Ideally I would want to do something like
<a onClick="flurryTrackEvent("Click_Rainbows")" href="#Rainbows">Rainbows</a>
<a onClick="flurryTrackEvent("Click_Unicorns")" href="#Unicorns">Unicorns</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment