Skip to content

Instantly share code, notes, and snippets.

@israelst
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save israelst/4bba2ea020b9ec625493 to your computer and use it in GitHub Desktop.
Save israelst/4bba2ea020b9ec625493 to your computer and use it in GitHub Desktop.
Function that turns Facebook insights into a flat structure.
function preprocess(post){
var flatPost = post.insights.data.reduce(function(post, insight){
post[insight.name] = insight.values[0].value;
return post;
}, {});
flatPost.likes = post.likes.summary.total_count;
flatPost.comments = post.comments.summary.total_count;
flatPost.shares = (post.shares || {'count': 0}).count;
return flatPost;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment