Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook pixel events call from server

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?

like image 787
lenden Avatar asked May 11 '17 21:05

lenden


Video Answer


2 Answers

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

like image 189
Jon Church Avatar answered Sep 29 '22 23:09

Jon Church


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.

like image 25
tyrex Avatar answered Sep 29 '22 23:09

tyrex