Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facebook Event Manager not receive events from iOS 14+ #66

Closed
AlexButovFairo opened this issue Jun 30, 2021 · 25 comments
Closed

Facebook Event Manager not receive events from iOS 14+ #66

AlexButovFairo opened this issue Jun 30, 2021 · 25 comments

Comments

@AlexButovFairo
Copy link

AlexButovFairo commented Jun 30, 2021

🐛 Bug Report

I tried to send some events to Facebook Event manager, like this: AppEventsLogger.logEvent('test', 14, { type: 'ios' });
In android and IOS < 14 it works fine, I can easily check this event in Event Manager, but if I try to send an event on IOS 14+, I don't receive anything.
Not any errors appear.

To Reproduce

Well, I don't do any special, just make all like in setup instruction.
I used 'react-native-permissions' package to get permission for advertiser tracking enabled on the first app run.
I also made 5 and 6 steps from here
https://developers.facebook.com/docs/app-events/getting-started-app-events-ios#disable-auto-events
In my app I had AppDelegate.swift file, so in 6 I used Swift part
I init SDK like this:

export const facebookSDKInit = async () => {
  const trackingStatus = await requestTrackingPermission();
  if (Platform.OS === 'ios' && parseInt(Platform.Version) > 13) {
    if (trackingStatus === 'authorized') {
      await Settings.setAdvertiserTrackingEnabled(true);
    }
  }
  Settings.initializeSDK();
};

(I use requestTrackingPermission method from 'react-native-tracking-transparency' package to check if I really had permissions)

and I added to button calling event: AppEventsLogger.logEvent('test', 14, { type: 'ios' });

Expected Behavior

Should receive an event in Facebook Event Manager and check it in recent activity.

Code Example

https://github.com/AlexButovFairo/testFacebookSDK
This is an example of my setup, only left to configure Info.plist

Environment

@mikehardy
Copy link
Collaborator

Perhaps related #25

I don't think this will result in any change to the module, I believe there is a project configuration / API usage issue.

An example (https://stackoverflow.com/help/minimal-reproducible-example) in this case would be a complete App.js that may be dropped in the example project and run without modification that shows the issue

Separately I would suggest react-native-permissions is a superior library to the one you are using though it will not actually change your result

@AlexButovFairo
Copy link
Author

AlexButovFairo commented Jun 30, 2021

added a small code example to my bug report, it will be great if someone take a look

@AlexButovFairo
Copy link
Author

AlexButovFairo commented Jul 8, 2021

looks like this is a problem with Facebook IOS SDK
facebook/facebook-ios-sdk#1667

@mikehardy
Copy link
Collaborator

Good find - but also a bit unfortunate as it implies any fix there will be for current versions and there's a forward port required #55 with no one currently interested + motivated to do it 😅

@Fublvckmagik
Copy link

Temporary solution

@PrimulaX
Copy link

PrimulaX commented Jul 12, 2021

Same problem, I have this code and it doesn't work on +iOS14

const ATT_CHECK = await check(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY);

        if (ATT_CHECK === RESULTS.DENIED) {
            try {
                const ATT = await request(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY);
                if (ATT === RESULTS.GRANTED) {
                    Settings.setAdvertiserTrackingEnabled(true).then(() => {
                        Settings.initializeSDK();
                    });
                }
            } catch (error) {
                throw error;
            } finally {
                Settings.initializeSDK();
            }

@mikehardy
Copy link
Collaborator

@PrimulaX this appears to be an upstream issue - please report back when it is resolved there and note that until someone takes up #55 (could be you!) that will still need to be done here in order to take advantage of the upstream fix. I do not believe this is actionable here though.

For future people to be very clear I believe these are the needs:

  • someone forward port this module to upstream SDK 11
  • upstream issue fixed

Further +1s and metoos etc are not helpful, but do feel free to hit the thumbsup on the issue, that is equivalent to a popularity vote and shows whether it is important to you, without generating notifications that are not actionable.

@PrimulaX
Copy link

PrimulaX commented Jul 12, 2021

@mikehardy Thanks for your answer.
I'm not sure if I can do that 😃 but I can give it thumbs up.

@trilam1409
Copy link

trilam1409 commented Jul 15, 2021

Is there any way to resolve this issue? My customer asks me frequently. They can't create ads.

I try to integrate Facebook login. It also works but Facebook Add Manage still shows No SDK installed

I'm not familiar with native IOS code.

Screen Shot 2021-07-15 at 19 04 09

@mikehardy
Copy link
Collaborator

@trilam1409 your comment is just a fancy "me too"

For future people to be very clear I believe these are the needs:

someone forward port this module to upstream SDK 11
upstream issue fixed

@trilam1409
Copy link

@trilam1409 your comment is just a fancy "me too"

For future people to be very clear I believe these are the needs:

someone forward port this module to upstream SDK 11
upstream issue fixed

Thanks for your answer.
I changed the FB SKD 9.3.0 => 11.0.1
But many methods were removed that listed below:

https://github.com/facebook/facebook-ios-sdk/blob/master/CHANGELOG.md?fbclid=IwAR2V7E7kgxIzMi8grt9pEKzL-90PyU5ahS7NeQpWDIsGuWPHbwNFii3Svks#removed

I'm not familiar with native code. You can help me know how to change the initial method in fbsdk 11.

Integrate two products of FB that was quite difficult haha.

@mikehardy
Copy link
Collaborator

Unfortunately I can't help without actually trying to do it: changing those methods is the task. We need someone that has the time to just do it. I don't have the time now unfortunately.

Note that even after forward-porting I think we're still waiting on the upstream issue? So it may not be fully fixed after the forward port here, but it means that at least when upstream does fix a bug, we can get the fix since we can access the new versions

@tereshchenkoartyom94-da

For people that struggling with this bug please make sure that you HAVE A FACEBOOK APP INSTALLED AND LOGGED IN!
I have tried everything, even 11+ version of SKD
only a real device with a FacebookApp installed fixed that.

@santiagofm
Copy link
Contributor

santiagofm commented Jul 29, 2021

I cannot explain how frustratingly difficult it was for me to get this """"""working"""""", and by working I mean getting events to show up on the "Test Events" tab of the Events Manager web app. I have absolutely no idea if this means that events will be captured for our users or not but I guess it's a start :bang-head-on-wall:.
This comment here was my lifesaver, it basically outlines all the stuff that needs to happen for this to work.

In summary, for it to work you need to:

  • Run the app on a real device
  • Have the facebook app running in the background and logged in to an account
  • Have that account you used on Facebook added as an "Advertising Account" for your app on Facebook's dashboard
  • AND LAST AND IMPORTANT: Have ATT enabled both on the FACEBOOK APP and YOUR APP. It took like half an hour for facebook to prompt me to enable ATT(I don't use facebook and had to install the app), before that it just wouldn't work.

This will make it so events you log on your app by YOU—which I guess they determine by seeing who is logged in on the Facebook App— are the ones to show up on the Event manager.

Worst part is that events weren't even showing on the "Overview" tab before enabling ATT on both apps, this is troubling because I suppose the chances of this happening is rather low.

@mikehardy
Copy link
Collaborator

If someone wants to PR the documentation (just hit the edit button at the top right of the page! To add the steps from @santiagofm that would be most welcome! Looks nearly impossible to figure out.
We're shipping a version with ios SDK 11 shortly which may help, going to close this as I don't think it's really actionable here except needing a PR to the docs (someone please please PR it, we do need contributors not just users...)

@AaronDsilva97
Copy link

I cannot explain how frustratingly difficult it was for me to get this """"""working"""""", and by working I mean getting events to show up on the "Test Events" tab of the Events Manager web app. I have absolutely no idea if this means that events will be captured for our users or not but I guess it's a start :bang-head-on-wall:. This comment here was my lifesaver, it basically outlines all the stuff that needs to happen for this to work.

In summary, for it to work you need to:

  • Run the app on a real device
  • Have the facebook app running in the background and logged in to an account
  • Have that account you used on Facebook added as an "Advertising Account" for your app on Facebook's dashboard
  • AND LAST AND IMPORTANT: Have ATT enabled both on the FACEBOOK APP and YOUR APP. It took like half an hour for facebook to prompt me to enable ATT(I don't use facebook and had to install the app), before that it just wouldn't work.

This will make it so events you log on your app by YOU—which I guess they determine by seeing who is logged in on the Facebook App— are the ones to show up on the Event manager.

Worst part is that events weren't even showing on the "Overview" tab before enabling ATT on both apps, this is troubling because I suppose the chances of this happening is rather low.

Tried exactly as mentioned by @santiagofm but app_install event is not showing up, All other events are populating in the events manager.

@reyalpsirc
Copy link

reyalpsirc commented Nov 16, 2022

I was finally able to log events to Facebook Event Manager by changing the AppDelegate with the following code:

#import <AppTrackingTransparency/AppTrackingTransparency.h>

[...]

- (void)applicationDidBecomeActive:(UIApplication *)application {
  [FBSDKAppEvents.shared activateApp];
  [FBSDKApplicationDelegate.sharedInstance initializeSDK];
  [FBSDKSettings.sharedSettings setAutoLogAppEventsEnabled:YES];
  // Enable this if you you want to debug FBSDK stuff
  /*[FBSDKSettings.sharedSettings enableLoggingBehavior: FBSDKLoggingBehaviorAppEvents];
  [FBSDKSettings.sharedSettings enableLoggingBehavior: FBSDKLoggingBehaviorDeveloperErrors];
  [FBSDKSettings.sharedSettings enableLoggingBehavior: FBSDKLoggingBehaviorCacheErrors];
  [FBSDKSettings.sharedSettings enableLoggingBehavior: FBSDKLoggingBehaviorUIControlErrors];*/
  [self requestTracking];
}

- (void) requestTracking {
  if (@available(iOS 14, *))
  {
      ATTrackingManagerAuthorizationStatus status = [ATTrackingManager trackingAuthorizationStatus];

      if(status == ATTrackingManagerAuthorizationStatusNotDetermined)
      {
          [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status)
          {
              // Tracking authorization completed.
              [FBSDKSettings.sharedSettings setAdvertiserTrackingEnabled:YES];
          }];
      }
      else
      {
        [FBSDKSettings.sharedSettings setAdvertiserTrackingEnabled:YES];
      }
  }
}

Please note that you also need to add AppTrackingTransparency.framework to your XCode project (under the General tab):

Screenshot 2022-11-16 at 13 39 59

I'm using react-native-fbsdk-next 10.1.0.
If this works well for others, feel free to add this on the docs somewhere.

@mikehardy
Copy link
Collaborator

Wow! That looks like exactly the sort of thing that this module should do itself? Is there something missing in the events module wrapper code here that requires all that code in your AppDelegate?

@reyalpsirc
Copy link

@mikehardy no idea. I tried multiple things over 4 hours and in the end the only solution was that code (which is based on the link posted by @santiagofm )

All I know is that without it, no AppTrackingTransparency dialog appears on the App, I didn't try the solutions that use AppTrackingTransparency through other react-native libs however, I did try to call Settings.setAdvertiserTrackingEnabled(true); before with the logging enabled but nothing was showing on XCode logs besides the auto app_open event. For some reason, my custom events only appeared on logs with that setting set on AppDelegate. The last step was to put the AppTrackingTransparency around it so that the calls to graph.api could work

@santiagofm
Copy link
Contributor

It's a little weird that AppTrackingTransparency.framework isn't linked automagically tbh, perhaps it depends on the iOS version you are targeting?
In our project we used react-native-permissions to deal with permissions so I guess the library already links the required native dependencies.

@reyalpsirc
Copy link

Well, all I know is that without it, it was giving an “undefined symbols” error when building

@mikehardy
Copy link
Collaborator

I use react-native-permissions myself, and it has ATT support. I'm not sure why anyone would avoid it - that's the go-to module for permissions (including ATT) and may eliminate the need for some of that code

@reyalpsirc
Copy link

We are still starting our project, so we didn’t need other permissions for now and since the setting on JS didn’t seem to be working, I used the objective C directly.

@kesha-antonov
Copy link
Contributor

kesha-antonov commented Mar 28, 2023

I was finally able to log events to Facebook Event Manager by changing the AppDelegate with the following code:

#import <AppTrackingTransparency/AppTrackingTransparency.h>

[...]

- (void)applicationDidBecomeActive:(UIApplication *)application {
  [FBSDKAppEvents.shared activateApp];
  [FBSDKApplicationDelegate.sharedInstance initializeSDK];
  [FBSDKSettings.sharedSettings setAutoLogAppEventsEnabled:YES];
  // Enable this if you you want to debug FBSDK stuff
  /*[FBSDKSettings.sharedSettings enableLoggingBehavior: FBSDKLoggingBehaviorAppEvents];
  [FBSDKSettings.sharedSettings enableLoggingBehavior: FBSDKLoggingBehaviorDeveloperErrors];
  [FBSDKSettings.sharedSettings enableLoggingBehavior: FBSDKLoggingBehaviorCacheErrors];
  [FBSDKSettings.sharedSettings enableLoggingBehavior: FBSDKLoggingBehaviorUIControlErrors];*/
  [self requestTracking];
}

- (void) requestTracking {
  if (@available(iOS 14, *))
  {
      ATTrackingManagerAuthorizationStatus status = [ATTrackingManager trackingAuthorizationStatus];

      if(status == ATTrackingManagerAuthorizationStatusNotDetermined)
      {
          [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status)
          {
              // Tracking authorization completed.
              [FBSDKSettings.sharedSettings setAdvertiserTrackingEnabled:YES];
          }];
      }
      else
      {
        [FBSDKSettings.sharedSettings setAdvertiserTrackingEnabled:YES];
      }
  }
}

Please note that you also need to add AppTrackingTransparency.framework to your XCode project (under the General tab):

Screenshot 2022-11-16 at 13 39 59

I'm using react-native-fbsdk-next 10.1.0. If this works well for others, feel free to add this on the docs somewhere.

I started seeing events in xcode debug view: FBSDKLog: FBSDKAppEvents: Flushed @ 1679994074.000000, 1 events due to

Thanks!

@Nagibaba
Copy link

In my case adding AppTrackingTransparency with react-native-permissions worked. Also if you have multiple info.plist files, add config for all of them. Additionally FB config is not enough. Add Client Token too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests