Home > Back-end >  Access the wanted field parameters from the output of facebook ads graph api
Access the wanted field parameters from the output of facebook ads graph api

Time:01-08

I've installed Facebook Pixel on my website, and it records purchases made on my site. The script on my site is the normal purchase standard event:

Right now, my query looks like this:

{
  "data": [
    {
      "actions": [
        {
          "action_type": "link_click",
          "value": 19
        },
        {
          "action_type": "offsite_conversion.fb_pixel_purchase",
          "value": 1
        },
        {
          "action_type": "offsite_conversion.fb_pixel_view_content",
          "value": 19
        },
        {
          "action_type": "post_like",
          "value": 88
        },
        {
          "action_type": "page_engagement",
          "value": 107
        },
        {
          "action_type": "post_engagement",
          "value": 107
        },
        {
          "action_type": "offsite_conversion",
          "value": 20
        }
      ],

As you can see, the query returns a lot of parameters that i dont want to track. There are some fields that i only want to record i.e link_click & post_like. Rest other parameters i want to remove them.

Is there any way to get only some required fields rather than whole bunch of metrics

I tried using specific metrics mentioned in the facebook api parameters. like actions.purchase_conversion_value but the output is no such parameters found.

CodePudding user response:

Solution 1: If you get this data from API, then you must subscribe to get data. So you can filter your needed data yourself using RXJS operators specially filter. If we consume data as actions list Then the code will be like this:

this.api
  .pipe(
    map((actions) => actions.filter(
      (action) => ['link_click', 'post_like'].includes(action.action_type))
    )
  )
  .subscribe(
    data => console.log(data)
  )

And the output will be:

[{
    "action_type": "link_click",
    "value": 19
},
{
    "action_type": "post_like",
    "value": 88
}]

Solution 2: Or if you have just the data without subscribing, again you can filter it by javascript filter function like this:

let result = this.data.filter((action) => ['link_click', 'post_like'].includes(action.action_type));

Result will be the same

CodePudding user response:

Yes, it is possible to specify which fields you want to include in the query response. You can do this using the fields parameter in the Graph API.

To specify which fields you want to include, you can pass a comma-separated list of field names in the fields parameter. For example, if you want to include only the link_click and post_like fields in the response, you can use the following query:

{
  "data": [
    {
      "actions": [
        {
          "fields": "link_click,post_like",
          "value": 19
        },
      ],
}

Also, you might need to specify the fields parameter for each field that you want to include in the response.

  • Related