Social Media has become very important for any website.It is also important to measure social media statistics of your website and pages.You should know which pages on your website are popular in social media.Also if your website is very popular on social media then it is worth displaying that information to visitors as well.Social activity on a post is defined by
- Number of Facebook likes,Shares,Comments
- Number of Tweets
- Number of Google Plus shares and plus ones
- Number of comments on the post
- Other social media actions like Pinterest Pins,Linkedin Share,Reddit share etc.
Out of the five listed above most content management like WordPress systems display only number of comments on the post.But it is good to display count of Facebook likes or shares you post has received.The more social activity a post has visitors feel the post is worth reading.A good article will have good amount of social media activity if not too new.Social media activity can be considered benchmark of good article (interesting article).
Many visitors tend to share articles with good number of activity.They think Hey this article is shared so many times on different Social Media networks like Facebook or Twitter.This means this article is worth sharing.Let me share this with my friends.They might find it interesting or useful.
Nowadays people do not read the article they just scan it.So parameter like Social counts play an important role in keeping users interested in the article.YOu might have noticed many top websites displaying their social counter at top of the page.
You can display Social Media stats of your page using
- Official buttons from Social Media Sites like Facebook like button.
- Using PHP Code as mentioned in this post.
- Using Social Analytics service providers
Using Official buttons
This is the easiest method to display social media statistics on your website.All social media sites have official buttons which display number of activities your post received on that social media network.If you are interested to implement official social buttons then read below tutorials
- For Facebook read this tutorial
- For Twitter read this tutorial
- For Google Plus read this tutorial
- For Reddit read this tutorial
Above tutorials explain the fastest way to implement these buttons on your website.In case you are using WordPress and do not want to edit your theme files then you can read this tutorial.The problem with Official buttons is customization.The counts are displayed on buttons itself.You do not have much control on customization part.You can also not add them up and show as a total count.These things are taken care of in the next method.
Using PHP Code
We will be using PHP code to display social counts on your page.This method can be implemented on any PHP based website.I am outlining the step by step process.
Step 1 :
Create URL of the page you want to display social media statistics.I use below code.You can use any code you want.There are several ways to get URL of page.Different content management systems also provide methods to get URL of page.
$url = ((!empty($_SERVER['HTTPS'])) ? "https://": "http://" ) . $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
Step 2 :
Now we will get statistics of the page.In this step we are querying the web service to get the information about the URL.We get the output in form of JSON.
$json = file_get_contents("http://api.sharedcount.com/?url=" . rawurlencode($url));
Step 3 :
Now we will decode the JSON to get the information in PHP variable.
$counts = json_decode($json, true);
Step 4 :
Now we have the information we want.We will use this variable to display Facebook counts,Twitter counts as well as Google Plus counts.Only these social networking sites are currently supported by this service.This website is using above code for quite sometime without any issues.
It gives sum of Facebook likes,Facebook Shares and Facebook comments made on your post.
Google Plus Counts
Now you can use above PHP code in any way you want on your website.I use it as shown below
<a onClick="demofacebook()" title="Share on Facebook"><?php echo $counts['Facebook']['total_count'] ?>.' Facebook Likes'</a>
This shows the counts as form of link which on click open a pop up using which you can share the post on Facebook.This is not fancy.You can use the code in more fancier way.The advantages of this method are speed and customization options it offers.You can add the counts together or show them separately.You can also display them in any format you want to.There is no additional resource to load in this case.So load time is not impacted at all.
Using Social Analytics Services
Major challenge in using them are speed.They do provide many pre built format for use.So customization is not a major issue.You might find one format as per your requirement.You can also configure them to decrease the load time or load them after initial page load.But this option is available in only HTML mode.You can read this tutorial for more details on implementing them.
I have also listed list of social media engagement services.You can find list of all services along with the features offered by them here.
Out of the three methods mentioned above I would like to recommend second one.It is easy to implement but does require some coding skills.You need to identify area to add the piece of code.Content Management systems like WordPress use several files to generate a page.You need to modify one of these theme files.
If you are not comfortable with above method then you can use either the first one or third one.The third one is more easier then first one.You just need to select social media networks you want to place on your website.But for the first method you need to use social buttons of all social network sites you want to add.So in third method only one piece of code is required while in first method number of codes required is same as that of number of social media buttons you want to place.
So you can try all of the above and select the one which fits in your requirement.Consider sharing the post in case you found this useful