Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support limited "custom logging" from the iOS SDK

Summary: Add support for very specific event logging in the iOS SDK.  Single events, now from FriendPicker launch and PlacePicker launch, get sent to the server.  Underlying support for apps that are not FB auth'd as well.

Test Plan: Tested via HelloFacebook

Reviewers: jacl, clang

Reviewed By: jacl

CC: msdkexp@

Differential Revision: https://phabricator.fb.com/D583180
  • Loading branch information...
commit bbb0b5349ff21634cda51699f7d042a88180e945 1 parent 530bdc3
@gregschechter gregschechter authored
View
2  src/FBFriendPickerViewController.m
@@ -230,6 +230,8 @@ - (void)viewDidLoad
self.tableView.delegate = self.selectionManager;
[self.dataSource bindTableView:self.tableView];
self.loader.tableView = self.tableView;
+
+ [FBUtility logInsightsEvent:@"_friendPickerLaunch" session:_session];
}
- (void)viewDidUnload {
View
2  src/FBPlacePickerViewController.m
@@ -298,6 +298,8 @@ - (void)viewDidLoad
self.tableView.delegate = self.selectionManager;
[self.dataSource bindTableView:self.tableView];
self.loader.tableView = self.tableView;
+
+ [FBUtility logInsightsEvent:@"_placePickerLaunch" session:_session];
}
- (void)viewDidUnload
View
5 src/FBUtility.h
@@ -17,6 +17,8 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
+@class FBSession;
+
@protocol FBGraphObject;
@interface FBUtility : NSObject
@@ -38,6 +40,9 @@
withDefault:(NSString *)value
inBundle:(NSBundle *)bundle;
++ (void)logInsightsEvent:(NSString *)eventName
+ session:(FBSession *)session;
+
@end
#define FBConditionalLog(condition, desc, ...) \
View
106 src/FBUtility.m
@@ -15,12 +15,22 @@
*/
#import "FBUtility.h"
+#import "FBGraphObject.h"
+#import "FBRequest.h"
+#import "FBSBJSON.h"
#import "FBSession.h"
#include <sys/time.h>
-#import "FBGraphObject.h"
@implementation FBUtility
+typedef enum {
+ AttributionIDSendNotChecked,
+ AttributionIDSendAllowed,
+ AttributionIDSendDisallowed
+} AttributionIDSendStatus;
+
+static AttributionIDSendStatus g_attributionIDSendStatus = AttributionIDSendNotChecked;
+
// finishes the parsing job that NSURL starts
+ (NSDictionary*)dictionaryByParsingURLQueryPart:(NSString *)encodedString {
@@ -143,4 +153,98 @@ + (NSString *)localizedStringForKey:(NSString *)key
return result;
}
++ (void)logInsightsEvent:(NSString *)eventName
+ session:(FBSession *)session {
+
+ NSString *appID = [FBSession defaultAppID];
+ if (!appID) {
+ return;
+ }
+
+ // Need to check whether attribution send is needed or allowed.
+ if (session || g_attributionIDSendStatus != AttributionIDSendNotChecked) {
+
+ // Have the information we need, send immediately.
+ [self sendInsightsEvent:eventName session:session];
+
+ } else {
+
+
+ NSString *pingPath = [NSString stringWithFormat:@"%@?fields=supports_attribution", appID, nil];
+ FBRequest *pingRequest = [[[FBRequest alloc] initWithSession:nil graphPath:pingPath] autorelease];
+
+ [pingRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
+
+ @try {
+
+ if (!error &&
+ [result respondsToSelector:@selector(objectForKey:)] &&
+ [[result objectForKey:@"supports_attribution"] boolValue]) {
+
+ g_attributionIDSendStatus = AttributionIDSendAllowed;
+
+ } else {
+
+ // Any error or malformed response winds up here.
+ g_attributionIDSendStatus = AttributionIDSendDisallowed;
+
+ }
+
+ [self sendInsightsEvent:eventName session:session];
+
+ } @catch (NSException *blockException) {
+
+ NSLog(@"Failure during logInsightsEvent ping callback: '%@'", blockException.reason);
+
+ }
+ }
+ ];
+ }
+}
+
++ (void)sendInsightsEvent:(NSString *)eventName
+ session:(FBSession *)session {
+
+ @try {
+
+ NSString *graphPath = [NSString stringWithFormat:@"%@/activities", [FBSession defaultAppID]];
+
+ NSString *attributionID = @"";
+ if (g_attributionIDSendStatus == AttributionIDSendAllowed) {
+ attributionID = [[UIPasteboard pasteboardWithName:@"fb_app_attribution" create:NO] string] ?: @"";
+ }
+
+ NSArray *customEvents = @[
+ @{ @"_eventName" : eventName }
+ ];
+
+ NSError *myError = nil;
+ FBSBJSON *writer = [[FBSBJSON alloc] init];
+ NSString *customEventsJSON = [writer stringWithFragment:customEvents error:&myError];
+ FBConditionalLog(!myError, @"Shouldn't get a JSON encoding error");
+ [writer release];
+
+ NSDictionary *postParameters =
+ @{
+ @"event" : @"CUSTOM_APP_EVENTS",
+ @"attribution": attributionID,
+ @"custom_events" : customEventsJSON,
+ };
+
+ FBRequest *request = [[[FBRequest alloc] initWithSession:session
+ graphPath:graphPath
+ parameters:postParameters
+ HTTPMethod:@"POST"] autorelease];
+
+ // Fire and forget
+ [request startWithCompletionHandler:nil];
+
+ } @catch (NSException *exception) {
+
+ NSLog(@"Failure during sendInsightsEvent: '%@'", exception.reason);
+
+ }
+}
+
+
@end
Please sign in to comment.
Something went wrong with that request. Please try again.