HFX HFX - 1 year ago 96
Python Question

facebook ads api - can't add custom tracking specs in an ad

I'm using facebook-python-ads-sdk,and i have followed the official site:



Pixel Tracking
You can track the performance of different pixels in an ad by specifying the tracking pixel in the ad's tracking_specs field. Let's say that you define:


The problem is when I added it to an ad,it shows me the error as

"error": {
"code": 100,
"is_transient": false,
"error_subcode": 1634019,
"error_user_msg": "Please check that a valid and non-empty object id is passed in.",
"error_user_title": "The id of the object (post, page, etc) passed in is invalid.",
"message": "Invalid parameter",
"type": "FacebookApiException",
"fbtrace_id": "HhCZrs9+8GH"

my code:

ad = Ad(parent_id=account_id)
ad[Ad.Field.name] = ad_name
ad[Ad.Field.adset_id] = adset_id
ad[Ad.Field.tracking_specs] = {'action.type': 'offsite_conversion', 'fb_pixel': 6029740175958}

when i removed the tracking_specs,it works fine.And i have added the pixel to adset,it also works fine to me.

ad_set[AdSet.Field.promoted_object] = {'pixel_id': 6015522072958}

So the pixel id is correct.

What am I doing wrong?Thanks for any answer.

Answer Source

Damn it, i made a GET request to https://graph.facebook.com/2.5/{Ad_ID}, i have added tracking specs to the Ad before.

And then,i got:

"tracking_specs": [
      "action.type": [
      "offsite_pixel": [
      "action.type": [
      "page": [
      "post": [

Did you notice the difference?

It is the offsite_pixel field. In the above example,it was fb_pixel. ¯\(°_°)/¯