Thursday, April 17, 2014

Script to check social shares: Facebook comments, shares and likes, tweets, G+ ripples, linkedin and stumbles

Social shares on Facebook, Linkedin, Twitter, Google Plus are relevant - for users, and we assume as well for rankings in search engines. (likely not directly, but indirectly through user behavior). There's a post checking a few platforms - now with more than ever! %-)

This is the version I use most - it covers the biggest relevant platforms (here in the US), and pulls it in the right speed. With my current internet connection, it just pulls slowly enough to not trigger any blocks from the api-s.

I also realized it is easiest to use a random file name, rather than pulling some info in from the site scanned. The url list can come from a sitemap scan or from a sitescan - or any other url list.

This is how the results look like:

I usually sort by each column, to filter out 'outliers', and then use the results.

This is the script:

# set all variables to zero at the beginnning! then value >, replace
# check where the tabs come from (likely one tab to many in one of the echos?
rm "${1}-all-social-shares".csv

echo -e "Url\tripples\tFB-comments\tFB-shares\tFB-likes\ttwitter\tstumble_upon\tlinkedin" > "${1}-all-social-shares".csv
while read -r shortline ;

line=$(echo $shortline | sed -e 's/\?/\%3F/g' -e 's/&/\%26/g' -e 's/#/\%23/g')
echo $shortline
echo $line
ripples=$(wget -qO- "${gpull}" | grep -o "[0-9]*\s*public\s*shares.<" | sed "s/[^0-9]//g"  | tr "\n" "\t" | sed 's/\thttp/\nhttp/g'| sed 's/\t//')

comment_count=`wget -qO- $commentpull | sed -e 's/^.*://g' -e 's/\}//g' -e 's/\(]\)//g'`

share_count=`wget -qO- $sharepull | sed -e 's/^.*://g' -e 's/\}//g' -e 's/\(]\)//g'`

like_count=`wget -qO- $likepull | sed -e 's/^.*://g' -e 's/\}//g' -e 's/\(]\)//g'`

twitternumber=$(wget -qO- "${twitterpull}"  | grep -o 'count\":[0-9]*\,' | sed -e 's/count//g' -e 's/,//g' -e 's/://g' -e 's/"//g' )

stumblenumber=$(wget -qO- "${stumblepull}" | grep -o 'views\":[0-9]*\,' | sed -e 's/views//g' -e 's/,//g' -e 's/://g' -e 's/"//g' )

linkedpull="${line}" #echo ${linkedpull}
linkednumber=$(wget -qO- "${linkedpull}" | grep -o 'count\":[0-9]*\,' | sed -e 's/count//g' -e 's/,//g' -e 's/://g' -e 's/"//g' )

#echo -e "$line\t$value\t$comment_count\t$share_count\t$like_count" >> "$1-all-public-shares".txt
echo -e "${line}\t${ripples}\t${comment_count}\t${share_count}\t${like_count}\t${twitternumber}\t${stumblenumber}\t${linkednumber}" >> "${1}-all-social-shares".csv

done < $1

No comments:

Post a Comment

Bookmark and Share