17

I have absolutelly the same question as dan here - Facebook conversion pixel with "server to server" option . There was written, that there was no way, but it was 2013, so I hope something changed.

So, is there any way to call facebook pixel events (e.g. CompleteRegistration) from server side now?

I can describe situation in more details. Imagine, that user visits our site, where fb pixel tracks 'PageView' of course. When user passes form and sends his phone number, we call 'Lead' event. But then we need to track one more event, when our manager successfully confirmes this user! Of course, it happens on other computer and so on, so there is no idea, how to "connect" to base user.

I've seen a lot of documentation departments like this, but I can't fully understand even if it's possible or not.

Logically, we need to generate specific id for user (or it can be phone number really), when 'Lead' event is called. Then, we should use this id to 'CompleteRegistration' for that user. But I can't understand, how to do it technically.

It would be gratefull, if somebody could explain it.

P.S. As I understand, it is fully available in API for mobile apps. Is it ok idea to use it for our situation, if there is no other solution?

Community
  • 1
  • 1
lenden
  • 800
  • 2
  • 14
  • 38
  • 1
    You need to create the appropriate hashes first, as described under https://developers.facebook.com/docs/marketing-api/audiences-api If your criterion that you can identify the user by is the phone number - then you need to send the hash for that phone number with your request. – CBroe May 12 '17 at 10:28
  • @CBroe yes, i've read it, it sounds like something, that I need, but I can't find examples how to call event for user and how to select specific user and so on. it's just about audiences filtering, collecting and so on – lenden May 12 '17 at 11:34
  • If you want to submit an offline conversion, then you must know for what user that conversion is upfront. – CBroe May 12 '17 at 14:01
  • @CBroe obviously!) and I just need to know, how to fix that user when lead event is fired and how to call other event for him from any server language. any code example – lenden May 12 '17 at 14:20

2 Answers2

21

Use Offline Conversions to record events that happen after a user has left your website. Logging these conversions, technically, is very easy. Setting everything up takes a little effort

tldr; check the code below


Follow setup steps in the FB docs (Setup steps 1-5) which are:

  • Setup facebook Business Manager account
  • Add a new app to Business Manager account
  • Create an Ad account, if you don't already have one
  • Create a System User for the ad account

After the setup, follow Upload Event Data steps on the same page, steps 1-3 to create an offline event set and associate it with your ad. These can be carried out in the Graph API Explorer by following the links in the examples. These can be done programmatically, but is out of the scope of making the event calls from the server for one campaign.

Once you have created the event set, then you can upload your CompleteRegistration events!

You will need to make a multipart form data request to FB, the data key will be an array of your conversion events. As @Cbroe mentioned, you must hash your match keys (the data you have available about your user to match them with a FB user) before sending to FB. The more match keys you are able to provide, the better chance at matching your user. So if you can get their email and phone at the same time, you're much more likely to match your user.

Here's an example of the call to FB using node.js:

    var request = require('request')
    
    // The access token you generated for your system user 
    var access_token = 'your_access_token'
    
    // The ID of the conversion set you created 
    var conversionId = 'your_conversion_set_id'
    
    var options = {
        url: 'https://graph.facebook.com/v2.12/' + conversionId + '/events',
        formData: {
            access_token: access_token,
            upload_tag: 'registrations', //optional 
            data: [{
                match_keys: {
                    "phone": ["<HASH>", "<HASH>"]
                },    
                currency: "USD",
                event_name: "CompleteRegistration",
                event_time: 1456870902,
                custom_data: { // optional 
                    event_source: "manager approved"
                },
            }]
        }
    }
    
    request(options, function(err, result) {
        // error handle and check for success
    })

Offline Conversion Docs

robyaw
  • 2,274
  • 2
  • 22
  • 29
Jon Church
  • 2,320
  • 13
  • 23
  • 1
    Oh! Firstly, thank you very much for this answer. I need to check my understanding of some things. I'm going to describe process as I understand and then ask questions. There will be several parts, because stackoverflow allows limited symbols. 1) We follow all setup steps up to creating offline event set. Now we have specific ad connected to offline event set. 2) When user clicks ad, he is also connected to event set. 3) We can easily call completeregistration from server, because we know event set id. – lenden May 15 '17 at 12:51
  • 1
    4) User is gonna be identified by his real personal data. E.g. his phone is 123456 and it is used in fb by him. We get sha256 hash of number, that he entered on our site and use it in completeregistration event to identify him. Please correct me, if it's wrong in some place. My questions: 1) How is it connected to fb pixel? As I understand, it is really parallel feature, fb pixel can be used or not with offline conversations. Is it right? 2) Why do you (and fb doc) use two hashes for phone? It just means, that we can use it for different spelling of number? – lenden May 15 '17 at 12:51
  • 1
    3) As I understood, it works for users with real personal data in fb. In our case, we use ads for people in instagram, mostly they don't even have fb account. So, in instagram account they don't have phone or email field at all. Can we generate custom identifier for them? E.g. pass customer_id when Lead event fires and then use it. Is it possible? – lenden May 15 '17 at 12:51
  • 2
    1) The pixel is just one way to get data into your ads account, you create a pixel (typically you only need one) and associate it with your ads account. With offline conversions, you create event sets and associate them with your ad account, then push data to it. 2) I honestly don't know enough about hashing to answer this, but facebook does let people have multiple emails and phone numbers attached to their accounts. 3) With a pixel, I don't believe you can pass custom matching params, but you can with offline conversion events. I would reccommend getting some identifying info like an email. – Jon Church May 16 '17 at 23:50
  • Feel free to edit your question and I'll edit my answer to keep up. – Jon Church May 16 '17 at 23:50
  • 3
    Okay, thank you for this details, i gonna accept the answer, but I need full information, including identifiying users for closing bounty. We can't get email - it has no sence, because our users are not even registered in fb mostly. So it can be only custom indentificators – lenden May 20 '17 at 11:24
  • Would an express server example be helpful? – Jon Church May 20 '17 at 14:07
  • Yes, but I also need part of frontend code. As I understand, we need to create identificator when Lead event fires. Or, may be we can run lead event on the server also? It is ok btw – lenden May 20 '17 at 14:56
  • Understood, I wont be able to get to an example before your bounty runs out – Jon Church May 21 '17 at 05:00
  • v2.9 is deprecated, the latest Graph API version is v2.12 – Lucas Alencar Apr 19 '18 at 12:09
  • From what I have read before and here most likely for this to work effectively you will have to capture their email and hope the one they give you is the same as the one they use with FB. Correct me if I am wrong? – Gary Carlyle Cook May 07 '18 at 17:51
  • @lenden did you guys succeed doing it? I mean, do you even have the email/phone of the users for offline conversions? the right way is to do so with some server-to-server reporting with this unique id, but facebook doesn't support it :( – Guy S Dec 03 '18 at 12:41
3

Facebook has now a Server-Side API: https://developers.facebook.com/docs/marketing-api/server-side-api/get-started

Implementing this is similar to implementing the offline events outlined in the accepted answer.

Keep in mind that it will always be cumbersome to track and connect events from the browser and from your server. You need to share a unique user id between the browser and server, so that Facebook (or any other analytics provider) will know that the event belongs to the same user.

Tools like mixpanel.com and amplitude.com may be more tailored to your needs, but will get very expensive once you move out of the free tier (100+ EUR at mixpanel, 1000+ EUR at Amplitude, monthly). Those tools are tailored towards company success, whereas Facebook is tailored towards selling and measuring Facebook ads.

tyrex
  • 8,208
  • 12
  • 43
  • 50