Facebook pixel events call from server

淺唱寂寞╮ 提交于 2019-11-30 04:02:24

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

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