Created
December 2, 2020 22:29
-
-
Save ricealexander/a24fd87d9931d91c345f74bc8438724b to your computer and use it in GitHub Desktop.
Given Facebook Insights Reactions/Comments/Shares State, return an object with their sums
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This function simplifies totalling up Reactions, Comments, and Shares in Facebook Insights | |
// To get the Reactions/Comments/Shares state, you must have the React Developer Tools Extension | |
// 1. Navigate to Page Insights > Reach | |
// 2. Set the date range at the top right of the view to the target range | |
// 3. Inspect the "Reactions, Comments, Shares and More" chart | |
// 4. In the React Components tool, navigate to c [from HubbleAreaLineChart] within HubbleChart | |
// 5. In the props, right click on "lines" and "Copy value to clipboard" | |
// The state of Reactions/Comments/Shares is now a nested array within your clipboard | |
// Call this function with getFacebookStats(), in which you paste into the parenthesis | |
function getFacebookStats (stats) { | |
const totals = [] | |
for (const stat of stats) { | |
totals.push(stat.reduce((sum, number) => sum + number, 0)) | |
} | |
const [reactions, comments, shares, others] = totals | |
return {reactions, comments, shares, others} | |
} | |
// Example Usage: | |
getFacebookStats([[90,778,1188,322,112,294,174,194,326,219,156,722,256,174,303,188,302,196,367,929,907,258,537,220,52,370,163,30,124,196],[11,101,339,90,25,38,19,31,26,27,22,140,44,26,47,38,103,47,105,222,248,66,115,89,4,67,33,6,6,93],[21,70,57,47,16,20,13,60,75,24,21,107,24,19,39,32,27,41,79,176,139,34,74,33,11,57,15,1,21,13],[4,8,6,9,4,3,4,7,9,8,9,5,7,4,7,8,6,7,12,7,5,2,3,3,0,5,5,7,6,16]]) | |
// { | |
// reactions: 10147, | |
// comments: 2228, | |
// shares: 1366, | |
// others: 186, | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment