1

I tried Facebook app events integration for ios (flutter) using plugin support of flutter_facebook_sdk and flutter_app_events, but nothing worked out. May I know how to implement this Facebook feature in ios.

shilpi
  • 37
  • 3

1 Answers1

2

At first, you need to have facebook app installed in your device to see any/all app events on your facebook dashboard. Make sure you are using a real device as for some reason simulators do not post events on facebook analytics as facebook app is not installed on simulators.

Secondly, to integrate facebbok app events on IOS just follow the pub docs.

First import the project into your flutter app:

flutter pub add facebook_app_events

Next, edit your info.plist (your_project_folder -> ios -> Runner -> Info.plist) Add the following into your info.plist:

<key>CFBundleURLTypes</key>
<array>
  <dict>
  <key>CFBundleURLSchemes</key>
  <array>
    <string>fb[APP_ID]</string>
  </array>
  </dict>
</array>
<key>FacebookAppID</key>
<string>[APP_ID]</string>
<key>FacebookDisplayName</key>
<string>[APP_NAME]</string>

If your code already contains CFBundleURLTypes, insert the following:

<array>
 <dict>
 <key>CFBundleURLSchemes</key>
 <array>
   <string>fb[APP_ID]</string>
 </array>
 </dict>
</array>
<key>FacebookAppID</key>
<string>[APP_ID]</string>
<key>FacebookDisplayName</key>
<string>[APP_NAME]</string>

Your integration for ios ends here. Next to send app events to facebook:

static final facebookAppEvents = FacebookAppEvents();

static Future<void> sendLoginAnalyticsEvent(
      String userId, String phone) async {
    
    await facebookAppEvents.logEvent(
      name: 'login_user',
      parameters: <String, dynamic>{
        'user_id': userId,
        'user_phone_no': phone,
      },
    );

    print('Successfully Sent loginEvent');
  }
Md. Kamrul Amin
  • 1,870
  • 1
  • 11
  • 33
  • do i need to make any change in appdelegate file of ios folder? – shilpi May 24 '22 at 10:25
  • No buddy. You only need to edit info.plist. After adding the package, please do flutter clean & flutter pub get and remember to delete the existing app from your phone and reinstall it. – Md. Kamrul Amin May 24 '22 at 10:28
  • yes, i had done the pub get and flutter clean all after adding the package previously and also edit the info.plist file but not called this logEvent function....so does this logEvent required for tracking app installs? – shilpi May 24 '22 at 10:31
  • no it is used to log a custom event to facebook analytics when the user is interacting with the app. Like in my app, when the user clicks on LoginButton, i call this function sendLoginAnalyticsEvent to send data to my facebook analytics dashboard. – Md. Kamrul Amin May 24 '22 at 10:34
  • When you use the Facebook SDK, certain events in your app are automatically logged and collected for Facebook unless you disable automatic event logging. These events are relevant for all use cases - targeting, measurement and optimization. There are three key events collected as part of the Automatic App Event Logging: App Install, App Launch, and Purchase. When automatic logging is enabled, advertisers are able to disable these events, as well as other Facebook internal events such as login impression events. – Md. Kamrul Amin May 24 '22 at 10:36
  • flutter_app_events plugin implementation i tried, made modification in info.plist file but no events are tracked by the app after fresh installation and i m trying the debug build. – shilpi May 24 '22 at 11:34
  • First make sure you have added APP EVENTS to your developer.facebook.com. Follow quickstart docs but do not add any code from there as all codes have been added by the flutter fb package. Set your appKey and then visit facebook events manager page. There you will see all your events are published. To check live event tracking go to Test Events tabs. Events takes a while to publish so you probably have to wait. Test Events are shown instantly when you log events. – Md. Kamrul Amin May 24 '22 at 11:42
  • on android platform without facebook_app_events plugin usage, faceboook events manager showing app install as i had followed the official documentation but for ios how to actually implement the same, i tried facebook_app_events plugin, followed the integration steps but not working – shilpi May 25 '22 at 07:25
  • Make sure you are using a real device with facebook app installed and logged in. Please do not forget to mark it as answer if it helped you – Md. Kamrul Amin May 25 '22 at 08:39
  • yes, i m using real device for ios facebook events testing – shilpi May 25 '22 at 09:05
  • You won't see changes instantly. It takes upto 12hrs to see events on dashboard. If you have implemented the code properly in Info.plist, I am sure your events will be fired. Sometime it takes a long time. – Md. Kamrul Amin May 25 '22 at 09:07
  • Sorry may I ask if is this necessary (to install facebook app event plugin) also if I only want to track ios installation from my campaign? – Nicolò Bozzato Sep 23 '22 at 10:43
  • 1
    @NicolòBozzato Yes you need facebook app event plugin to track any or all events. – Md. Kamrul Amin Sep 25 '22 at 04:44