Facebook Analytics In-App Notifications Framework

Overview

FBNotifications logo

Platforms Build Status

Facebook In-App Notifications enables you to create rich and customizable in-app notifications and deliver them via push notifications, based on the actions people take in your app. You can use text, photos, animated GIFs, buttons or extend the open format to suit your needs.

Getting Started on iOS

Podspec Carthage compatible

To get started on iOS, install the framework using one of these options:

Add the following line to your Podfile:

pod 'FBNotifications'

Run pod install, and you should now have the latest framework installed.

Add the following line to your Cartfile:

github "facebook/FBNotifications"

Run carthage update, and you should now have the latest version of the framework in your Carthage folder.

After you've installed the framework, you would need to add the following to your application delegate to present the notification:

Using Objective-C:

/// Present In-App Notification from remote notification (if present).
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler {
  FBNotificationsManager *notificationsManager = [FBNotificationsManager sharedManager];
  [notificationsManager presentPushCardForRemoteNotificationPayload:userInfo
                                                 fromViewController:nil
                                                         completion:^(FBNCardViewController * _Nullable viewController, NSError * _Nullable error) {
                                                           if (error) {
                                                             completionHandler(UIBackgroundFetchResultFailed);
                                                           } else {
                                                             completionHandler(UIBackgroundFetchResultNewData);
                                                           }
                                                         }];
}

Using Swift:

/// Present In-App Notification from remote notification (if present).
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
  FBNotificationsManager.sharedManager().presentPushCardForRemoteNotificationPayload(userInfo, fromViewController: nil) { viewController, error in
    if let _ error = error {
      completionHandler(.Failed)
    } else {
      completionHandler(.NewData)
    }
  }
}

Getting Started on Android

Maven Central

To get started on Android, add the following to your gradle dependencies:

compile 'com.facebook.android:notifications:1.+'

After you've added the dependency, you'll have to set up an FCM listener service, and add the following to your service:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Bundle data = new Bundle();
    for (Map.Entry<String, String> entry : remoteMessage.getData().entrySet()) {
      data.putString(entry.getKey(), entry.getValue());
    }
  
    NotificationsManager.presentNotification(
        this,
        data,
        new Intent(getApplicationContext(), MainActivity.class)
    );
}

Then when all the content for the notification is ready - it will automatically present the notification to the end user with a pending intent to present a card on open. To hand-off the necessary data from the intent - you need to handle the notification in the onCreate function of your Main Activity:

public class MainActivity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    NotificationsManager.presentCardFromNotification(this);
  }
}

For more help on getting started, take a look at our Facebook Push Campaigns Documentation.

In-App Notifications Format

In-app notifications are powered by a custom format that has an open specification available in this repository. The format describes all the possible values and combinations of content that can be rendered by the framework.

We are open to accepting contributions to the format and the format is constantly evolving. Any version of the framework is compatible with any previous version of the format in the same major version scope.

For example:

  • Framework 1.0.0 is compatible with format version 1.0
  • Framework 1.0.0 is not compatible with format version 1.5
  • Framework 1.5.0 is compatible with format version 1.5
  • Framework 1.5.1 is compatible with format version 1.5
  • Framework 2.0.0 is not compatible with format version 1.0, or 1.5

Contributing

We want to make contributing to this project as easy and transparent as possible. Please refer to the Contribution Guidelines.

License

See the LICENSE file for source code. See the LICENSE-specification file for In-App Notifications format specification.

Comments
  • Unable to install using Carthage

    Unable to install using Carthage

    Is Carthage compatibility working ? I keep getting the following error message:

    A shell task (/usr/bin/env git checkout --quiet 6e7d0b36f73d960cea81f4f207010dc584bffb3b) failed with exit code 128: fatal: Cannot switch branch to a non-commit '6e7d0b36f73d960cea81f4f207010dc584bffb3b'

    I've read similar issues (related to Carthage & submodules), but couldn't find a solution.

    Related issues:

    https://github.com/Carthage/Carthage/issues/936#issuecomment-159097500
    https://github.com/Carthage/Carthage/issues/135
    

    Steps:

    1. Create a file named Cartfile
    2. Add github "facebook/FBNotifications" to it
    3. Run carthage update
    bug 
    opened by bre7 3
  • Fixed NullPointerException when there is no HeroView on Android.

    Fixed NullPointerException when there is no HeroView on Android.

    Looks like we were always trying to get/set the height of the assetView in the HeroView, even though we never add it as a subview. This produced a NullPointerException. Tested with any of the example payloads by removing hero portion of the payload. Also, as a result - we needed to handle the corner radius case in BodyView (which turns out is handled in ActionsView, but not in BodyView).

    CLA Signed GH Review: accepted 
    opened by nlutsenko 2
  • Image is not shown on a card in Android SDK

    Image is not shown on a card in Android SDK

    I tuned In-App Notifications. It works well. But when I set an image, I receive a wrong Bundle on Android:

    ... "hero":{"background":{"$GEPushCardHeroSection3":"Image","url":"my url"},..
    

    as you can see I got strange $GEPushCardHeroSection3 key instead of _type. Because of that I can't get BitmapAssertHandler in Android notifications sdk. For another campaign with color bg I receive right data:

    ..."hero":{"background":{"_type":"Color","rgbaHex":"#768C97FF"},"contentAlign":"center"},...
    

    That leads that I don't see an image at all.

    opened by soniccat 1
  • Example payload

    Example payload

    I'm struggling to use the example payload as such.

    1. It isn't valid JSON -- I can't copy-paste and send it because there are several missing commas.
    2. It's missing (?) a "version" field which makes the FBNotifications framework crash on initial tests when it tries to extract version information.

    At least the framework seems to think that the version field is required. I don't know.

    opened by anohren 1
  • Use ViewControllers instead of Views for presentation and layout of Hero, Body, Actions.

    Use ViewControllers instead of Views for presentation and layout of Hero, Body, Actions.

    Much better structure, and most importantly allows us to unblock:

    • Custom ViewController for Gif presentation
    • Full screen presentation using built-in UIViewController presentation techniques

    Also this includes some cleanup around usage of ivars/properties and addition of missing nullability annotations.

    CLA Signed GH Review: accepted 
    opened by nlutsenko 1
  • Make construction of all assets, configurations be asynchronous.

    Make construction of all assets, configurations be asynchronous.

    This is going to give us an ability to preload every single piece of content from disc off of main thread, as well as allow loading rich media metadata asynchronously.

    CLA Signed GH Review: accepted 
    opened by nlutsenko 1
  • Project link broken

    Project link broken

    current project link is https://developers.facebook.com/docs/analytics/push-campaigns

    screen shot 2017-03-07 at 10 03 50 am

    is the new link https://developers.facebook.com/docs/push-campaigns/overview ?

    opened by ReadmeCritic 0
  • Add missing documentation for public iOS headers.

    Add missing documentation for public iOS headers.

    CocoaDocs.org reports that we have 61% documentation coverage, which is not ideal. Add all the missing documentation, including for unavailable methods.

    CLA Signed GH Review: accepted 
    opened by nlutsenko 0
  • Remove requirement on containing a push campaign identifier in the payload.

    Remove requirement on containing a push campaign identifier in the payload.

    If the card is not coming from FB Analytics Backend or if it doesn't contain campaign identifier - we are throwing a null pointer exception. We actually should be gracefully handling it and not crashing.

    CLA Signed GH Review: accepted 
    opened by nlutsenko 0
  • Add convenience method for presenting cards from a new intent of an activity

    Add convenience method for presenting cards from a new intent of an activity

    Right now - the only way to present a card from existing activity in onNewIntent method is to explicitly set the intent on the activity. We should add a convenience method that is able to present the card from that intent without requiring to set the intent on the activity beforehand.

    enhancement 
    opened by nlutsenko 0
  • Add method for checking whether a given Bundle has a In-App-Notification

    Add method for checking whether a given Bundle has a In-App-Notification

    iOS counterpart has a method for checking whether the payload has a card payload in it. We should add this on Android, as it's generally useful to check whether we can present a card or we should go do something else.

    enhancement 
    opened by nlutsenko 0
  • Intent Redirection vulnerability in presentCardFromNotification method

    Intent Redirection vulnerability in presentCardFromNotification method

    I am using facebook sdk for events and notifications. But Google Play Console rejected my newly updated application. Below is the alert message. I am using the facebook notification SDK in my code. Can you suggest an alternative to resolve the problem

    Security alert
    
    Your app contains an Intent Redirection vulnerability. Please see this Google Help Center article for details.
    
    Vulnerable classes:
    
    com.facebook.notifications.NotificationsManager.presentCardFromNotification
    Please fix the issue before: 
    
    Affects APK version 7.
    
    Go to Manage releases
    
    opened by attiqrehman1991 3
  • Adding Code of Conduct file

    Adding Code of Conduct file

    This is pull request was created automatically because we noticed your project was missing a Code of Conduct file.

    Code of Conduct files facilitate respectful and constructive communities by establishing expected behaviors for project contributors.

    This PR was crafted with love by Facebook's Open Source Team.

    CLA Signed 
    opened by facebook-github-bot 0
  • Crashes in the market version

    Crashes in the market version

    After integrating you library we started getting lots of such crashes

    java.lang.RuntimeException: 
    at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2572)
    at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2654)
    at android.app.ActivityThread.access$900 (ActivityThread.java:175)
    at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1488)
    at android.os.Handler.dispatchMessage (Handler.java:111)
    at android.os.Looper.loop (Looper.java:207)
    at android.app.ActivityThread.main (ActivityThread.java:5728)
    at java.lang.reflect.Method.invoke (Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:789)
    at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:679)
    Caused by: java.lang.RuntimeException: 
    at com.facebook.notifications.internal.asset.handlers.BitmapAssetHandler$BitmapAsset.getBitmap (BitmapAssetHandler.java:116)
    at com.facebook.notifications.internal.asset.handlers.BitmapAssetHandler.createView (BitmapAssetHandler.java:193)
    at com.facebook.notifications.internal.asset.handlers.BitmapAssetHandler.createView (BitmapAssetHandler.java:51)
    at com.facebook.notifications.internal.asset.ParcelableAssetHandler.createView (ParcelableAssetHandler.java:117)
    at com.facebook.notifications.internal.asset.AssetManager.inflateView (AssetManager.java:205)
    at com.facebook.notifications.internal.view.AssetView.<init> (AssetView.java:43)
    at com.facebook.notifications.internal.view.HeroView.<init> (HeroView.java:65)
    at com.facebook.notifications.internal.view.CardView.<init> (CardView.java:63)
    at com.facebook.notifications.internal.activity.CardActivity.displayConfiguration (CardActivity.java:196)
    at com.facebook.notifications.internal.activity.CardActivity.onCreate (CardActivity.java:120)
    at android.app.Activity.performCreate (Activity.java:6305)
    at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1113)
    at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2519)
    
    opened by soniccat 1
  • There is null in FBNCardHeroConfiguration in height in dictionary

    There is null in FBNCardHeroConfiguration in height in dictionary

    App is crashing at this point for finding Null here. See the attached image

    crashreportfb

    2018-01-16 12:56:58.790898+0500 APP[17245:1225043] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull doubleValue]: unrecognized selector sent to instance 0x1b215f650'

    opened by raheelsadiq 1
  • In-App notifications does not work with Android Oreo

    In-App notifications does not work with Android Oreo

    Recently tested out the library where the push notifications work properly (Adding notification channels) with Android Oreo but in-app notifications do not work. Please give an option to provide notification channels for in-app notifications.

    opened by Veeresh8 8
Releases(android-1.0.2)
Owner
Meta Archive
These projects have been archived and are generally unsupported, but are still available to view and use
Meta Archive
Easily create Local Notifications in swift - Wrapper of UserNotifications Framework

In IOS 10, apple updated their library for Notifications and separated Local and push notifications to a new framework: User Notifications This librar

Devesh Laungani 208 Dec 14, 2022
Push notifications allow developers to reach users, even when users aren't actively using an app!

Push notifications allow developers to reach users, even when users aren't actively using an app! With the latest update of iOS Apple provide very useful extensions which are user-friendly. In this tutorial, I am going to share the configuration, set up of Notification with the media attachments like.

MindInventory 16 Mar 3, 2022
Custom in-app notifications.

CRNotifications CRNotifications are custom in-app notifications with 3 types of layouts. The notifications will animate in and out. They will hide whe

Casper Riboe 112 Sep 2, 2022
Library to send mock remote notifications to the iOS simulator

SimulatorRemoteNotifications SimulatorRemoteNotifications is a library to send mock remote notifications to the iOS simulator. The library extends UIA

Arnaud Coomans 1.4k Dec 20, 2022
Pushkin is a free open source tool for sending push notifications

Unmaintained This repository is no longer maintained. Pushkin Introduction Pushkin is a free open source tool for sending push notifications. It was d

Nordeus 257 Nov 3, 2022
See all your scheduled local notifications in one place

ScheduledNotificationsViewController Nice Photon is available for hire! Talk to

Nice Photon 171 Oct 8, 2022
Gently notifies you about 'important' GitHub notifications

OctoBlast Gently notifies you about important GitHub notifications Setup Personal access token Head to preferences, and pop in your a new GitHub perso

Jason Watson 6 Nov 14, 2022
OS X and iOS application and framework to play with the Apple Push Notification service (APNs)

Pusher OS X and iOS application and framework to play with the Apple Push Notification service (APNs) Installation Install the Mac app using Homebrew

noodlewerk 6.2k Dec 22, 2022
OS X app for sending push with Apple Push Notification service (APNs)

pushHandle OS X app for sending push with Apple Push Notification service (APNs) About This app was created just to allow painless testing of push not

hbk3 3 Nov 17, 2022
Facebook Analytics In-App Notifications Framework

Facebook In-App Notifications enables you to create rich and customizable in-app notifications and deliver them via push notifications, based on the a

Meta Archive 496 Nov 17, 2022
Facebook Analytics In-App Notifications Framework

Facebook In-App Notifications enables you to create rich and customizable in-app notifications and deliver them via push notifications, based on the a

Meta Archive 496 Nov 17, 2022
Google Analytics tracker for Apple tvOS provides an easy integration of Google Analytics’ measurement protocol for Apple TV.

Google Analytics tracker for Apple tvOS by Adswerve About Google Analytics tracker for Apple tvOS provides an easy integration of Google Analytics’ me

Adswerve 81 Nov 13, 2022
Analytics layer abstraction, abstract analytics reporters and collect domain-driven analytic events.

?? Tentacles Current State: Work in Progress Documentation & Tests(100% completed, but needs refactoring and structuring) started but not done yet, im

Patrick 3 Dec 2, 2022
Joseph Miller 0 Jan 7, 2022
The hassle-free way to add Segment analytics to your Swift app (iOS/tvOS/watchOS/macOS/Linux).

Analytics-Swift The hassle-free way to add Segment analytics to your Swift app (iOS/tvOS/watchOS/macOS/Linux/iPadOS). Analytics helps you measure your

Segment 53 Dec 16, 2022
iOS SDK for cross-platform in-app purchase and subscription infrastructure, revenue analytics, engagement automation, and integrations

Qonversion is the data platform to power in-app subscription revenue growth. fast in-app subscriptions implementation back-end infrastructure to valid

Qonversion 253 Dec 18, 2022
Simplify your iOS/Mac analytics

ARAnalytics v4 ARAnalytics is to iOS what Analytical is to ruby, or Analytics.js is to javascript. ARAnalytics is an analytics abstraction library off

Orta Therox 1.8k Dec 29, 2022
The hassle-free way to integrate analytics into any iOS application.

Developer Feedback Requested: Analytics-Swift Pilot A pilot release of the new Analytics-Swift library is available at the Analytics-Swift repository.

Segment 383 Dec 14, 2022
Analytics for my apps. Currently using Telemetry as the provider

RRAnalyticsKit Analytics for my apps. Currently using Telemetry as the provider Usage For example, I've a method evaluate() in MainViewModel that acts

rryam 2 Jan 26, 2022
Trackable is a simple analytics integration helper library. It’s especially designed for easy and comfortable integration with existing projects.

Trackable Trackable is a simple analytics integration helper library. It’s especially designed for easy and comfortable integration with existing proj

Vojta Stavik 145 Apr 14, 2022