Facebook pixel events call from server

放肆的年华 提交于 2019-11-29 01:16:36

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/43925859/facebook-pixel-events-call-from-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!