ImportJSON icon indicating copy to clipboard operation
ImportJSON copied to clipboard

Importing Facebook API data into Google Sheets results in mismatched Dates value

Open lbrb-sam opened this issue 4 years ago • 0 comments

Goal: Import client data from Facebook Graph API into a Google Sheet to create a dynamic Facebook Ads Dashboard

What I've tried:

Used ImportJSON with a Graph API query created by Faceook's Graph API Explorer. That looks something like this:

/insights?date_preset=lifetime&time_increment=1&fields=account_currency,spend,frequency,reach,impressions,actions,cpm&use_account_attribution_setting=true&limit=5000

Result: Returns 2d-array in Google Sheet filled with the data we want. So far so good.

Problem: The dates are all off by one day (one day behind) for the values associated with query field "actions"

Query field "actions" returns an object with key "actions" and a value which is an array of objects whose keys and values correspond to different kinds of actions users are taking in response to our ads.

All of these are behind by one day.

My Investigation: Google Sheets Output Screen Shot 2020-12-12 at 11 48 51 AM

JSON Excerpt

{
  "data": [
    {
      "account_currency": "USD",
      "spend": "14.76",
      "frequency": "1.263227",
      "reach": "4593",
      "impressions": "5802",
      "cpm": "2.54395",
      "actions": [
        {
          "action_type": "onsite_conversion.messaging_first_reply",
          "value": "2"
        },
        {
          "action_type": "onsite_conversion.view_content",
          "value": "4"
        },
        {
          "action_type": "onsite_conversion.messaging_conversation_started_7d",
          "value": "19"
        },
        {
          "action_type": "comment",
          "value": "1"
        },
        {
          "action_type": "link_click",
          "value": "45"
        },
        {
          "action_type": "offsite_conversion.fb_pixel_custom",
          "value": "1"
        },
        {
          "action_type": "offsite_conversion.fb_pixel_view_content",
          "value": "1"
        },
        {
          "action_type": "post",
          "value": "5"
        },
        {
          "action_type": "post_reaction",
          "value": "25"
        },
        {
          "action_type": "omni_view_content",
          "value": "5"
        },
        {
          "action_type": "page_engagement",
          "value": "76"
        },
        {
          "action_type": "post_engagement",
          "value": "76"
        },
        {
          "action_type": "view_content",
          "value": "1"
        }
      ],
      "date_start": "2020-11-04",
      "date_stop": "2020-11-04"
    },
    {
      "account_currency": "USD",
      "spend": "21.61",
      "frequency": "1.249471",
      "reach": "6145",
      "impressions": "7678",
      "cpm": "2.814535",
      "actions": [
        {
          "action_type": "onsite_conversion.messaging_first_reply",
          "value": "1"
        },
        {
          "action_type": "onsite_conversion.messaging_conversation_started_7d",
          "value": "13"
        },
        {
          "action_type": "comment",
          "value": "1"
        },
        {
          "action_type": "link_click",
          "value": "51"
        },
        {
          "action_type": "offsite_conversion.fb_pixel_custom",
          "value": "1"
        },
        {
          "action_type": "offsite_conversion.fb_pixel_lead",
          "value": "1"
        },
        {
          "action_type": "offsite_conversion.fb_pixel_view_content",
          "value": "2"
        },
        {
          "action_type": "post_reaction",
          "value": "21"
        },
        {
          "action_type": "page_engagement",
          "value": "73"
        },
        {
          "action_type": "post_engagement",
          "value": "73"
        },
        {
          "action_type": "lead",
          "value": "1"
        },
        {
          "action_type": "omni_view_content",
          "value": "2"
        },
        {
          "action_type": "view_content",
          "value": "2"
        }
      ],
      "date_start": "2020-11-05",
      "date_stop": "2020-11-05"
    }

When I look at the sample of my JSON attached and compare it to the Google Sheets output, it looks to me like the "actions" keys and values are inheriting the "date_start" and "date_stop" values of the prior object and that is what is throwing my data off.

Question:

Is there problem here that the values to my "actions" key are not inheriting the appropriate "date_start" "date_stop" values due to the fact that they are, themselves, objects inside an array?

How can I ensure that the values for "actions" are associated with the correct date?

Thanks for reading this. If you have feedback on how to better format my question, or if you have corrections for my terminology, I'd be grateful for that as well!

lbrb-sam avatar Dec 13 '20 18:12 lbrb-sam