Search code examples
facebookfacebook-marketing-api

How to set the tracking_specs when creating Facebook ads?


I am trying to create an ad using the Facebook Marketing API. In order to create an ad inside a conversion based campaign, I am required to set proper tracking_specs values.

Querying existing ads (on other similar campaigns) I see the tracking spec is generally defined as follows:

"tracking_specs": [
    {
        "action.type": ["offsite_conversion"],
        "fb_pixel": [<pixel ID>]
    },
    {
        "action.type": ["post_engagement"],
        "page": [<page ID>],
        "post": [<post ID>]
    },
    {
        "action.type": ["link_click"],
        "post": [<post ID>],
        "post.wall": [<post.wall ID>]
    } 
]

How do I find the required tracking_specs values? More specifically, how do I find the post ID and the post.wall ID accordingly for post_engagement and link_click action types?


Solution

  • I managed to figure it out on my own. When creating a new ad, in a conversion typed campaign, an ad data object that includes tracking specs should be provided. These tracking specs should include some reference to a Facebook pixel.

    "tracking_specs": [
        {
            "action.type": ["offsite_conversion"],
            "fb_pixel": [<pixel ID>]
        }, 
    ]
    

    The pixels data can be obtained manually via the Facebook Business Manager or via the Facebook Marketing APIs:

    GET /v2.10/{ad-account-id}/adspixels HTTP/1.1
    Host: graph.facebook.com
    

    Read more in https://developers.facebook.com/docs/marketing-api/reference/ad-account/adspixels/

    Regarding the post and post.wall IDs - these are automatically added by Facebook when the ad is created. So there is no need to include theses when creating the ad.