Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where exactly should I put the call to [FBSettings publishInstall:appId]

Tags:

ios

facebook

sdk

I'm looking at integrating support for tracking Facebook's new mobile app ads.

I've read the tutorial here: https://developers.facebook.com/docs/tutorials/mobile-app-ads/

It says:

Include the following code to be executed when your app opens for the first time by user

[FBSettings publishInstall:appId];

So the first question is - where do I put this so that it only invokes the call if the install was driven from Facebook? I don't want FB to get credit for someone who found my app themselves on the app store.

Do I need to manually track whether or not I've called the publishInstall before for this specific user? (The preamble sentence implies this - but the SDK documentation for publishInstall implies otherwise).

And even more confusing is that the SDK FBSettings reference includes shouldAutoPublishInstall which defaults to YES. This would suggest that I don't need to do anything other than have the SDK integrated. So why does the tutorial not mention this as an option?

I assume that the appId is the associated Facebook appId (as opposed to the App Store App ID). This is also not clear from the documentation.

like image 317
sckor Avatar asked Oct 18 '12 12:10

sckor


3 Answers

I browsed the sources of facebook iOS SDK, and it seems that guide is wrong.

You are right, that autoPublishInstall is set to YES by default, which means we don't need to invoke [FBSettings publishInstall:appId]; manually. AppId is indeed the facebook app id.

When you invoke openActiveSessionWith.... method, it initializes FBSession with initWithAppID:permissions:defaultAudience:urlSchemeSuffix:tokenCacheStrategy: which contains in the end [FBSettings autoPublishInstall:self.appID];

+ (void)autoPublishInstall:(NSString *)appID {
    if ([FBSettings shouldAutoPublishInstall]) {
        dispatch_once(&g_publishInstallOnceToken, ^{
            // dispatch_once is great, but not re-entrant.  Inside publishInstall we use FBRequest, which will
            // cause this function to get invoked a second time.  By scheduling the work, we can sidestep the problem.
            [[FBSettings class] performSelector:@selector(publishInstall:) withObject:appID afterDelay:FBPublishDelay];
        });
   }
}

So technically it should report the install out of the box (if I'm not missing something). I'm going to play with it a little more today to see if it works as expected and update answer with results.

like image 58
Michał Zygar Avatar answered Nov 15 '22 00:11

Michał Zygar


  1. Just put it at -[application:didFinishLaunchingWithOptions].

  2. Not all of the apps want to integrate the Facebook login. They only want the feature "mobile app install ads". For these kind of app, they should invoke +[FBSettings publishInstall:appId] manually. On the other hand, if your app has already integrated facebook login, you can assume that the FB sdk has published the installation.

like image 6
popcorny Avatar answered Nov 14 '22 23:11

popcorny


If we just have to put

[FBSettings publishInstall:appId];

manually in

-[application:didFinishLaunchingWithOptions]

how will I identify which install happened from facebook? I don't want FB to get credit for someone who found my app themselves on the app store.

like image 3
a4arpan Avatar answered Nov 15 '22 01:11

a4arpan