Facebook Pixel (Request)

Hello Friends,

In order to integrate Facebook Pixel on my app, I’m having to eject but this seems like this should be an Expo core component. In fact, it seems like Expo should be including this package https://github.com/facebook/react-native-fbsdk

I know you can do facebook logins etc, but including the full facebook SDK I think really important because people would like to use many features that Facebook has to offer.

Is this available today and I don’t know about it? Or is there a subscribed methodology of getting user data ie: when someone clicks, installs, subscribes etc, data out of the app for marketing purposes?

1 Like

Thanks for the request. We’d like to support all of these things so we’ll discuss.

1 Like

FYI there is a workaround for anyone that MUST have a Pixel and doesn’t want to eject (like me).

Segment actually integrates directly with Facebook Pixel so you can use Segment for all of your data goodness. Use the Segment events are you’re set.

1 Like

Cool – good to know. Thanks for sharing!

@fourcolors Is this Segment: https://segment.com

Hi there, I’m having the exact same issue. Can you elaborate how did you implement Pixel with expos Segment. I’ve tried that but turns out Segments website only supports web version of facebook Pixel.

1 Like

Hey all, I’m also trying to install the Facebook Pixel to our Expo app, it’s really a pain, I’ve been at it for some time, I’ve not managed to make it work yet.

I’ve tried to use Segment but Facebook Pixel is not compatible with iOS as a source. Anyone managed to get a Facebook Pixel to work with Expo without ejecting?

@fourcolors - what did you put as a destination in front of the iOS source to make it work? Would be grateful to learn it! Cheers, David

Hey, one way to get some access to Pixel events:

If you have a Facebook Business Account, you may want to use the Conversions API. (once called Server API)

They provide a cURL example, which can be easily translated into an Axios request, and you can send authenticated events to Pixel.

import Axios from "axios"
import { sha256 } from 'js-sha256'

const pixel_id = '<PIXEL_ID>'

const PixelApi = Axios.create({
    baseURL: `https://graph.facebook.com/v7.0/${pixel_id}/events`
})

//RECEIVES THE USER EMAIL AND THE EVENT NAME STRINGS
function pixelSaveEvent(email, event) {
    return new Promise((resolve, reject) => {

        const content_name = event 
        const em = sha256(email) //ENCRYPTS THE EMAIL

        const access_token = '<ACCESS_TOKEN>' //CAUTION: YOU MIGHT WANT TO HIDE IT
        const event_name = "PageView" //OR ANY EVENT YOU WANT
        const event_time = 1594759643 //DATE IN TIMESTAMP

        const data = [{
            event_name,
            event_time,
            user_data: {
                em //THE ENCRYPTED EMAIL IS SENT HERE
            },
            custom_data: {
                content_name //THE CUSTOM EVENT NAME IS SENT HERE
            }
        }]

        const objToSend = {
            data,
            access_token //THE ACCESS TOKEN IS SENT HERE
        }

        PixelApi.post('', objToSend).then(() => {
            return resolve()
        }).catch(err => {
            return reject(err)
        })
    })
}

So anything like

pixelSaveEvent('jhon@doe.com', 'View_Pandas_Page')

Will save a custom event in Pixel, this way you’re able to create Conversions in Pixel using the content_name