All Collections
Tracking setup guides for traffic sources
Facebook
Using the Facebook Conversions API (CAPI) to track conversions
Using the Facebook Conversions API (CAPI) to track conversions

How to track conversions using the Facebook server-to-server API

Zeno avatar
Written by Zeno
Updated over a week ago

With Facebook you're likely used to tracking using the Javascript "pixel" code.

This is fine and all, but it relies on cookies and/or the user being logged in, and is not usable in situations where an offer/advertiser only supports postback URL tracking of conversions.

Using the Facebook S2S API is convenient and accurate, and now can be set up relatively easily.

You can still use the pixel for tracking everywhere, but if you want to use the S2S API to track conversions/purchases, don't double-up the pixel tracking there (i.e. don't place FB Pixel JS on the conversion page and use postbacks to send conversions to FB too, as you can get duplicates).

To do this you're going to need a few things:

  1. A Business Manager account in Facebook

  2. A Facebook Pixel set up

  3. Access to the events manager, where you'll get an access token

  4. A few minutes to set things up


Step 1: Create a FB App/Access Token

This part is mainly up to you.

Firstly, check Facebook's documentation here.

You will need to go through a few steps, assuming you already have a FB pixel set up.

  1. Go to https://business.facebook.com/ then to Data Sources > Pixels

  2. Select your pixel, then click Open in Events Manager

  3. Click the Settings Tab, then scroll down to Conversions API > generate access token:

Once this generates a token, copy and store this in a text editor for later use.


Step 2: The Traffic Source Setup

Now that we have that sorted, lets make sure the Facebook traffic source in FunnelFlux is configured correctly.

I recommend using our template, then modifying afterwards.

Here I have:

  • Loaded the Facebook Ads template

  • Added a new tracking field

  • Set "fbclid" as the name

  • Set "DELETE_ME" as the placeholder value

Why did I set DELETE_ME?

Well, Facebook automatically appends fbclid to clicks. So we don't want to add it to our links, but we need to define it here so that we capture it and store it in the database.

So, when you generate links, whether its a redirect link or, more like a direct URL for using JS tracking, just remove the fbclid=DELETE_ME part from the URL or optional URL params box.

I put it in all caps to make it a clear reminder to do this, to keep things clean and ensure we don't conflict with Facebook's automatic data passing.


Step 3: Conversion Tracking Setup

Scroll down to the conversion tracking part of the traffic source and select postback URL.

Here, we need to build a rather large postback URL, but this is much easier if we do it in a text editor.

Take the following code and place it in a text editor:

https://functions.funnelflux.pro/facebook-s2s-api?fbclid={trackingfield-fbclid}&funnel_id={funnel-id}&hit_id={flux_hid}&vid={flux_hid}&revenue={flux_payout}&currency=USD&page_url={page-url}&ip={connection-ip}&user_agent={connection-useragent}&entrance_timestamp={unix-timestamp}&conversion_timestamp={unix-timestamp}&txid={flux_txid}
&access_token=ACCESS_TOKEN_HERE
&pixel_id=PIXEL_ID_HERE
&event_name=EVENT_HERE

For the above, you will need to:

  • Replace ACCESS_TOKEN_HERE with the access token value you copied from Facebook.

  • Replace PIXEL_ID_HERE with the ID of your Facebook pixel

  • Replace EVENT_HERE with an event name -- for now you can only use one, which must be a standard event -- see the "Event Name" column here

  • Remove the line breaks for the final three lines, so that it is a single URL string

Optionally, you can also:

  • Send a test event code, so that you can use Facebook's event manager section to check the integration is working.

  • To do this, append &test_event_code=OPTIONAL to the end of the above URL (see the section at the end of this document).

We know that one challenge with this integration right now, particularly for affiliates, is that the event URL sent must be a verified domain. Unless you have had the domain shared to you by the advertiser, this simply won't be the case.

So, you can also consider change &page-url={page-url} to some hard-coded lander URL that is from a verified domain.

This can be a bit tedious and annoying, but at the moment there is no token in FunnelFlux for passing some initial page visit.

If you opt to do this, make sure you encode the value sent, i.e. instead of:

Pass instead

  • &page-url=https%3A%2F%2Fgoogle.com


Guide: Manual Self-Testing

Its very difficult to fully test this before setting it live, as we need real FBCLIDs else the Facebook API will reject the calls.

However, you can test this by getting a direct link to one of your offer pages, with FB set as the source (generate a direct link via the Funnel Builder).

Then in FB messenger send it to yourself in chat. This will generate a link preview.

Open the link in a new incognito window and you should see it redirect to your page with fbclid=xxx in the URL.

Go to the Stats (Flat) page and load a report of traffic source, node type, node name, hit ID and time, URL tracking field.

This should give you a solid log report where you will quickly identify the offer hit from yourself, and you can hopefully see the FBCLID in the URL tracking field column for that hit.

Now in the FB Business Manager, head back to the event manager > pixels section and the Test Events page. You want to find your test code:

Make sure you have added this as the &test_event_code=XXX in the postback.

Be sure to remove this before going live as otherwise all events will be test events.

Now, go to the conversions update section and paste your hit ID, submit it as a conversion.

If all goes well, you should see the event come up in the test events section in FB.

Did this answer your question?