Last year I shared this popular tip for counting how many times a web link has been shared on Twitter or Facebook. I use this technique daily to report on the social media "popularity" of our blog articles at SAS.
I wanted to add LinkedIn into the mix. Like Twitter and Facebook, LinkedIn also has a REST-based API that can be used within a SAS program. For example, if I want to know how many times my recent post "It's raining analytics" has been shared on LinkedIn, I can use PROC HTTP to hit this URL:
Update 15Dec2014: LinkedIn recently changed their API endpoint to support a higher level of encryption, and as a result the programmatic use of the API requires the HTTPS protocol instead of HTTP. If you receive an error such as: "ERROR: SSL Error: Missing CA trust list", try using HTTPS in your API call.
Here is the JSON-formatted response (as of today):
Wow! That blog post has done pretty well on LinkedIn (with "count"=89) - it's my most-shared post this year.
Here's a SAS program that checks the LinkedIn shares for me:
%let url=https://blogs.sas.com/content/sasdummy/2013/01/15/its-raining-analytics/; /* temp holding area for LinkedIn response */ filename li temp; /* call the LinkedIn API */ proc http url="http://www.linkedin.com/countserv/count/share?url=&url." method='GET' /* proxyhost= if behind corp firewall */ out=li; run; /* use RegEx to gather the "count":n value */ data liresult (keep=url lishares); length line $ 1000 lishares 8; length url $ 300; url = "&url."; infile li; input line; if _n_ = 1 then do; retain li_regex; li_regex = prxparse("/\""count\""\:([0-9]*)/"); end; position = prxmatch(li_regex,line); if (position ^= 0) then do; call prxposn(li_regex, 1, start, length); lishares = substr(line,start,length); end; run; /* clear our temp response file */ filename li clear;
That's a lot of code to retrieve the answer for just one link. Thanks to the power of the SAS macro language, I can scale this to retrieve the values for an entire collection of links. With those results in hand, I can run other stats:
Of my 63 posts in the past 12 months, my links have been shared to LinkedIn an average of 4.58 times, with a total of 289 shares overall.
I'm not so naive that I consider these to be impressive numbers, but I've only just begun the habit of sharing my posts on LinkedIn. With this process as part of my daily blog reporting, I can now measure how my "LinkedIn engagement" improves as I share more content. Collect data, count, measure, report -- that's what it's all about, right?
Note: Many web articles, such as blog posts, can have multiple URLs. For example, the WordPress platform offers "short-link" GUID URLs as well as the longer, more descriptive URLs. While all of these different URLs might lead to the same page, LinkedIn counts only the URL you share. So if you are in the habit of publicizing different URLs for convenience or other tracking purposes, you might need to check each permutation of a page URL with this program to get the complete "LinkedIn shares" picture.