gugaiz
gugaiz

Reputation: 534

How to get Facebook tracking url parameters through API

When I edit an ad on business.facebook.com, I can see a "Tracking" section where there is a field called "URL Parameters".

enter image description here

I am trying to get the value of that field using the (Graph or Marketing) API, but after reading a lot I can't find a way of achieve that.

Does somebody know if that is even possible?

Upvotes: 5

Views: 4200

Answers (3)

Prosper Filipe
Prosper Filipe

Reputation: 11

You can find this information under "url_tags" on the Ad Creative level through Graph API.

Official Documentation: https://developers.facebook.com/docs/marketing-api/reference/ad-creative/#fields

Upvotes: 1

Simon_Weaver
Simon_Weaver

Reputation: 146110

Disclaimer: I'm still pretty new to intermediate graph API usage, but this is what I figured out so far.

The python page seems to give all the fields in a nice long list, so I copy and pasted those into the API URL:

actor_id, actor_image_hash, actor_name, adlabels, applink_treatment, body, call_to_action_type, dynamic_ad_voice, filename, follow_redirect, id, image_crops, image_file, image_hash, image_url, instagram_actor_id, instagram_permalink_url, link_deep_link_url, link_url, name, object_id, object_store_url, object_story_id, object_story_spec, object_type, object_url, place_page_set_id, preview_url, product_set_id, template_url, thumbnail_url, title, url_tag

So something like this (spaces are ok):

/v2.12/act_XXXXXXX/adcreatives/?fields=actor_id, actor_image_hash, actor_name, adlabels, applink_treatment, body, call_to_action_type, dynamic_ad_voice, filename, follow_redirect, id, image_crops, image_file, image_hash, image_url, instagram_actor_id, instagram_permalink_url, link_deep_link_url, link_url, name, object_id, object_store_url, object_story_id, object_story_spec, object_type, object_url, place_page_set_id, preview_url, product_set_id, template_url, thumbnail_url, title, url_tag&limit=100&effective_status=["ACTIVE"]

This gives me the full tree:

{
  "data": [
    {
      "body": "XXXXXXX",
      "call_to_action_type": "LEARN_MORE",
      "id": "XXXXXXX",
      "image_hash": "XXXXXXX",
      "image_url": "XXXXXXX",
      "instagram_actor_id": "XXXXXXX",
      "instagram_permalink_url": "XXXXXXX",
      "name": "#‏XXXXXXX",
      "object_story_spec": {
        "page_id": "XXXXXXX",
        "instagram_actor_id": "XXXXXXX",
        "video_data": {
          "video_id": "XXXXXXX",
          "title": "XXXXXXX",
          "message": "XXXXXXX",
          "link_description": "XXXXXXX",
          "call_to_action": {
            "type": "LEARN_MORE",
            "value": {
              "link_caption": "EXAMPLE.COM",
              "link": "https://example.com/your-page",
              "link_format": "VIDEO_LPP"
            }
          },
          "image_hash": "XXXXXXX"
        }
      },
      "object_type": "VIDEO",
      "thumbnail_url": "XXXXXXX",
      "title": "XXXXXXX"
    },

So now I know it CAN be returned and most definitely is not write-only.

After playing some more I found that it's the SINGLE field object_story_spec that returns ALL this:

"data": [
    {
      "object_story_spec": {
        "page_id": "XXXXXXX",
        "instagram_actor_id": "XXXXXXX",
        "video_data": {
          "video_id": "XXXXXXX",
          "title": "XXXXXXX!",
          "message": "XXXXXXX",
          "link_description": "XXXXXXX",
          "call_to_action": {
            "type": "LEARN_MORE",
            "value": {
              "link_caption": "EXAMPLE.COM",
              "link": "https://EXAMPLE.COM/YOUR-WEBSITE-LINK",
              "link_format": "VIDEO_LPP"
            }
          },
          "image_hash": "XXXXXXX"
        }
      },
      "id": "XXXXXXX"
    },

So perhaps fields like link and object_id aren't for the type of ad I am using (mostly video with link to website) - or perhaps they are just for creating an ad - but I don't really care because now I have the data I need.

I'm using https://developers.facebook.com/tools/explorer for this

Upvotes: 0

mrgreenfur
mrgreenfur

Reputation: 94

See the "Ad Creative" object, "URL Tags" field.

More info here: https://developers.facebook.com/docs/marketing-api/reference/ad-creative

Whoops, that seems to be for writing only. It seems like that field is always empty when reading objects. :(

Upvotes: 5

Related Questions