Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use standard events in the react native Facebook SDK

The Facebook SDK has the ability to record both custom events and standard events. The standard events are things like "Purchases" "Add to cart" "Completed Registration" etc...

Recording these standard events gives you access to specific bidding features on Facebook ads that you don't get without the events.

I have an app that has the React Native FBSDK

There are two methods for defining an event - one for purchases and one for everything else as seen here

There is zero documentation for standard events on react within the SDK on Github or on the event tracking docs on Facebook's developer platform.

Right now I'm trying to track the standard events by using their various names, as recorded across FB's documentation. I've tried the following:

AppEventsLogger.logEvent('FBSDKAppEventNameCompletedRegistration'); AppEventsLogger.logEvent('CompletedRegistration'); AppEventsLogger.logEvent('Completed Registration');

All of these just create custom events with those names, but aren't recognized as standard events.

Has anyone gotten standard events to work using the React Native wrapper for the FB SDK? If so how do you name the events to get FB to recognize them?

like image 279
sca4 Avatar asked Dec 05 '16 20:12

sca4


2 Answers

I managed to find the actual event name by generating standard event code using tool on Facebook's documentation, run the code in AppDelegate.m, and get the exact key-values from Events Manager. With this roundabout way, I realized the actual name of Add to Cart event was fb_mobile_add_to_cart. From there I googled for the name and found the list documented in Marketing API (why not App Events?).

I don't know if it is the right place, but you can refer to https://developers.facebook.com/docs/marketing-api/app-event-api/ for actual standard event names and parameter names. At least it worked in my case. Here's my Add to Cart event code:

function logAddToCart(totalPrice, contentType, contentId, currency) {
    const params = {
        'fb_content_type': contentType,
        'fb_content_id': contentId,
        'fb_currency': currency
    };
    AppEventsLogger.logEvent('fb_mobile_add_to_cart', totalPrice, params);
}
like image 174
PaperMonster Avatar answered Nov 04 '22 12:11

PaperMonster


Update: As the comment below highlights, the more recent link is https://developers.facebook.com/docs/marketing-api/app-event-api/

It looks like you'll have to pass the strings that those standard events get evaluated to, i.e. instead of 'FBSDKAppEventNameCompletedRegistration', you'll have to use: 'fb_mobile_complete_registration'.

Here's the source:

Sorry if this is a bit late. Hope this helps.

like image 31
ppsreejith Avatar answered Nov 04 '22 12:11

ppsreejith