Monday, 3 April 2017

Strange data pulled from Facebook insights

I am pulling video insights for my company's pages from Facebook. I have all the correct permissions and most of the data pulls OK.

Our marketing wants data refreshed automatically, so I built a lambda to run on AWS and periodically pull video_insights from posts.

Regular values are always pulled fine. However, I have a problem with "Objects" as described further. First a fragment of my code, running inside a couple of async loops, so I blamed the problem on a scope issue for a while.

     ...
case 'total_video_complete_views_auto_played':
     fbPost.total_video_complete_views_auto_played = insight.values[0].value;
     break;
case 'total_video_complete_views_clicked_to_play':
     fbPost.total_video_complete_views_clicked_to_play = insight.values[0].value;
     break;
case 'total_video_complete_views_organic':
     fbPost.total_video_complete_views_organic = insight.values[0].value;
     break;
case 'total_video_complete_views_organic_unique':
     fbPost.total_video_complete_views_organic_unique = insight.values[0].value;
     break;
case 'total_video_complete_views_paid':
     fbPost.total_video_complete_views_paid = insight.values[0].value;
     break;
...

All regular fields are being pulled in OK. Fields with objects like: fbPost.total_video_view_time_by_distribution_type are often returned as undefined in a very funky way. I get: JSON.stringify(fbPost.total_video_view_time_by_distribution_type) : {"shared":6058073,"crossposted":845068,"page_owned":1586129} and fbPost.total_video_view_time_by_distribution_type.shared : returns cannot read property shared of undefined. For some reason, locally it happens once in a blue moon while on AWS for almost every post.

Since, to me, this seems like a scope problem, I downloaded an insights report directly from Facebook. Values seem valid - the same values are returned by my script and by Facebook. It makes even less sense. If my scopes are off, I would get "random" values pulled from different posts, probably... Right?

Has anyone seen anything like this? Is there something I should/could try, to pinpoint where the problem is happening?

Thank you.



via Moshe Shmukler

No comments:

Post a Comment