facebook, many, f

Facebook Conversion API Required Fields

It is a known fact that the regular Facebook pixel will no longer work due to the third party cookies regulations. The only way to send conversion data to Facebook will be to use the conversion API without any need for cookies .

There are a few required fields for Facebook conversion API that MUST be sent in order for the conversion to be properly registered in Facebook. If you will not send these fields to Facebook’s conversion API you’ll not get conversions, even though Facebook will not return any error. So it is something that you must remember if you want to work with Facebook’s conversion API. These field values will allow your Facebook conversions to yield good CPA i.e. Cost per action. Good CPA allows you to pay only for actions people take because of your ad. This is useful if you want to control how much you pay for specific actions. Click here to read more about CPA.

Let’s assume that you have a Facebook ad that sends the user to your landing page. In your landing page, you’ll need to add a few hidden fields in order to fill them once the page loads, with values for the required fields. In this scenario, you’ll also have the fbclid parameter in the landing page’s URL.

The hidden fields that I added to the elementor form in my landing page are: 

  1. user_agent (the elementor id for this field will be form-field-user_agent)
  2. click_id (the elementor id for this field will be form-field-click_id)
  3. client_ip (the elementor id for this field will be form-field-client_ip)

Then, you’ll need to add the following code (inside an HTML widget if you are using the elementor builder) and place the code at the bottom of the page so that all of the DOM document elements will be rendered by the time the execution of the script will have to take place.

					 <script language="javascript" type="text/javascript">

/////////user agent//////////////
var userAgent = navigator.userAgent; 
document.getElementById("form-field-user_agent").value = userAgent; 

//////click Id//////////
var clickId = "";

var url = document.location.href;

var qs = url.split("?")[1];
var paramsArray = qs.split("&");
var clickId = '';
for (i = 0; i < paramsArray.length; i++) {
    itemArr = paramsArray[i].split("=");
    if( itemArr[0] == "fbclid" ){
        clickId = itemArr[1];

document.getElementById("form-field-click_id").value = clickId;

/////////client ip///////////////
var clientIp = document.getElementById("form-field-client_ip");
fetch("https://Your-URL-PART.m.pipedream.net/").then(res => res.json()).then(data => {clientIp.value = data.ip;});


Let’s dive into the code above and explain how each field get its value.

  1. The user_agent is a required filed that you must send to Facebook’s conversion API. The user agent is a long string that contains a lot of useful information e.g. the visitor’s browser type, OS type, mobile OS type, device type, etc… The script is extracting this value from the navigator object and then setting it to the hidden field’s value in line 5. If you send the user agent value you MUST also send the IP address of the visitor, so I’ll talk about this field next.
  2. The client_ip field is required if you send the user agent value and vice versa, i.e. , if you send the client IP value you MUST send the user agent value. the script has to call an external service in order to get the IP address of the caller, because the browser does not expose any network information in its API. In line 28 a GET HTTP request is sent to a service in pipedream (click here to read more about pipedream), that simply returns the caller’s IP address. The script is using the browser’s fetch API in an asynchronous way to call pipedream’s end point and in the final “.then” block sets the IP value to the clientIp hidden field. I’ll show the pipedream’s code later on in this post.
  3. In regards to the click_id field, note that if the visitor has been directed to this landing page via a Facebook ad’s click, the fbclid parameter will be present in the page’s URL. So the script iterates on the query string and extracts the value of the fbclid parameter and sets it to the client IP hidden field in line 23. If the visitor has been directed to this page from other source that click id filed will be ampty.      

In order to get the IP address of the visitor, you’ll have to find a way to get the IP from an external service, I used pipdream’s service for the job. In pipedream I created a new workflow with an HTTP trigger as the first step, then I added a node.js step and in it, I added the code you see below. AS you see this code simply gets the client IP address field from the previous trigger step and wraps it in a JavaScript object (as you see in line 4 below) that is sent back as JSON in the response. When you create a new HTTP trigger in pipedream, you get a special end point you can call to trigger the service, so you’ll have to copy the end point’s URL to line 28 in the code above so that the fetch function will call it and get back the IP address (copy it instead of the URL in line 28 , i.e., instead of “https://Your-URL-PART.m.pipedream.net/”).   

  status: 200,
  headers: { "Content-Type": "application/json" },
  body: { ip: steps.trigger.event.client_ip.toString()}

You can see the node.js code step of pipedream’s flow in the picture below:


Now, when your landing page will be submitted to it’s detination, for example to Integromat’s scenrio with a webhook trigger, you’ll have all of the required field’s values in the hidden fields, Then you’ll be able to send them to Facebook’s conversion API and get good CPA values for your campaign.  

Scroll to Top