February 20, 2013

Widgets

Display Post Views Count in Blogger - New!


blogger postviews pluginYes you heard it right, all BlogSpot blogs will now be able to display a dynamic count for individual pageviews. We can now easily create this  post view counter without worrying about servers or server code. With a free service like Firebase you can now create dynamic and data-driven plugins for blogger without worrying about backend development. Firebase was launched in April 2012 and since then it had been the hub for developers. Amazingly this free plan gives you 10GB Free bandwidth and 5GB Free storage. Which in our case is more than required! We had been lucky to utilize this free service for blogger platform and create some amazing scripts with the help of our developer Ahmed Nasir. Today's tutorial will help you to install a dynamic script that will automatically increment its initial count value when a visitor views your blog posts. The counter data will be stored on a free database provided by Firebase. Lets first see a demo!

 

Demo

Note: The postviews count wont change when you refresh the blog homepage but it will change only when you visit individual posts.

1. Create your Firebase Account

In order to gain access to a free database and be able to keep a backup of your postviews counter data, you must sign up for a free account at Firebase.

Fill up the easy steps sensibly and then once your account has been activated, you must create your first Firebase database.

2. Create a Firebase Database

You can create 2 firebases. At present just create one, we will guide you later in coming posts about amazing things you can play with this free service.

  1. Towards the bottom right side of your account, you will find the following submit box.

creating a firebase

  2.   Inside this box input your website name. In my case I inserted mybloggertricks and this generated the following firebase URL: https://mybloggertricks.firebaseio.com

  3.   Finally hit the create button and note down your firebase URL because we would need it later in this tutorial.

3. Installing Postviews Plugin

  1. Go To Blogger > Template
  2. Backup your template
  3. Click Edit HTML
  4. Tick the box "Expand widget Templates"
  5. Search for ]]></b:skin>
  6. Just above it paste the following CSS code:

/*-------- Post Views  ----------*/
#views-container {
width: 85px;
float: right;
}

.mbtloading {
background: url('http://4.bp.blogspot.com/-PZMStRDcchY/USOp3xFp4yI/AAAAAAAAJOo/rm5FSsaSKh0/s320/mbtloading.gif') no-repeat left center;
width: 16px;
height: 16px;
}

.viewscount {
float: right;
color: #EE5D06;
font: bold italic 14px arial;
}

.views-text {
float: left;
font: bold 12px arial;
color: #333;
}

.views-icon{
background: url('http://4.bp.blogspot.com/-_dXedKDHIws/USOp369zEPI/AAAAAAAAJOs/Cv3fTZUaBTU/s1600/postviews.png') no-repeat left;
border: 0px;
display: block;
width: 16px;
height: 16px;
float: left;
padding: 0px 2px;
}

    Customizations:

  • To change the text color of the numeric count, edit #EE5D06
  • To change the plugin alignment, change right to left.

   7.  Next search for </body>  and just above it paste the following JavaScript code:

<!-- Post Views Script by MBT -->
<script type='text/javascript'>
    window.setTimeout(function() {
        document.body.className = document.body.className.replace(&#39;loading&#39;, &#39;&#39;);
      }, 10);
  </script>
<script src='https://cdn.firebase.com/v0/firebase.js' type='text/javascript'/>
<script>
$.each($(&#39;a[name]&#39;), function(i, e) {
var elem = $(e).parent().find(&#39;#postviews&#39;).addClass(&#39;mbtloading&#39;);
var blogStats = new Firebase(&quot;https://mybloggertricks.firebaseio.com/pages/id/&quot; + $(e).attr(&#39;name&#39;));
blogStats.once(&#39;value&#39;, function(snapshot) {
var data = snapshot.val();
var isnew = false;
if(data == null) {
data= {};
data.value = 0;
data.url = window.location.href;
data.id = $(e).attr(&#39;name&#39;);
isnew = true;
}
elem.removeClass(&#39;mbtloading&#39;).text(data.value);
data.value++;
if(window.location.pathname!=&#39;/&#39;)
{
if(isnew)
blogStats.set(data);
else
blogStats.child(&#39;value&#39;).set(data.value);
}
});
});
</script>

Make this change:

  • Replace the highlighted brown line with your firebase URL (Step#2). Make sure you replace it correctly by taking care of forward slash (/)

    8.  Now one last step. Find this code:

   <data:post.body/>

Note: If you are finding multi occurrences of the same code then choose the first occurrence.   

   9. Just above it paste the following HTML,

<!-- Post Views Counter by MBT-->
<div id='views-container'><span class='views-icon'/><div class='views-text'>Views:</div> <div class='mbtloading viewscount' id='postviews'/></div>

You can replace views: with any text you like.

 

    10.  Now the final step, paste the following jquery link just below <head>

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'></script>

 

    11.  Hit save and you are all done!

Visit your blog and press F5 (refresh page) to see the counts dancing just perfectly! :)

Copyrights

Developers and niche bloggers are most welcome to share this  Plugin with their readers and friends. Please attribute the credits back to MBT blog as the only favor in return. It takes hours of efforts to write and debug these scripts. This plugin comes under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Need help?

We just hope this plugin adds new fuel to your blogger powered blogs. We tried best to keep it working as efficient as possible. You wont run out of bandwidth as long as you create your own Firebase accounts and not use ours (our firebase url). 

This plugin will display views only once pages are visited. It is not synchronized with your Google analytics stats data, therefore it will only display correct views for the new posts that you publish.

Let me know if you needed any help. We have some more interesting scripts coming up this week. Stay tuned! Peace and blessings buddies :)

Don't forget to try:




If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you Subscribe to our regular Email Updates!

If you don't want to get yourself into Serious Technical Trouble while editing your Blog Template then just sit back and relax and let us do the Job for you at a fairly reasonable cost. Submit your order details by Clicking Here »

78 comments:

shankar on Feb 20, 2013, 12:36:00 AM said... #

thanks I was looking for this to add to my blog http://sreyaghoshalfansclub.blogspot.in/..

A2 Studios EA Cricket 2007 Patches on Feb 20, 2013, 12:50:00 AM said... #

I would definitely try this on my Blog of CRICKET GAME Patches.

http://a2-studio.blogspot.com

Hafeez Khan on Feb 20, 2013, 3:11:00 AM said... #

Well Mohammad you have created this with great efforts we will follow.

Thankss





...▄▀▄▀▄▀▄ ▀ProBloggerTricks▀▄▀▄▀▄▀▄...

Daniel Benny Simanjuntak on Feb 20, 2013, 5:20:00 AM said... #

Thanks Qasim! I was searching it from a long time. Firebase is really great. :)

atiqur rahman on Feb 20, 2013, 6:26:00 AM said... #

Thanks Qasim Brother!
I like this but it is very slow. I was use this my blog:
http://composition-paragraph.blogspot.com/

Tan Nguyen on Feb 20, 2013, 6:40:00 AM said... #

Wait why mine is just displaying loading icon instead of views number. Is it fine if I put it next to the post-label

Regina Sarkar on Feb 20, 2013, 6:57:00 AM said... #

It's really very helpful. Thanks for the post.
http://www.24xhtml.com/2013/02/use-unique-facebook-cover-photo-for.html#more

Tanmay Kapse on Feb 20, 2013, 7:54:00 AM said... #

Will the count begin from zero or will it display the actual number of pageviews the post got ?

Tan Nguyen on Feb 20, 2013, 8:20:00 AM said... #

@Tanmay Kapse

According to what I see right now. It's counting from 0. I maybe wrong though. :D

Yogendra Bhonsale on Feb 20, 2013, 8:47:00 AM said... #

Thanks. Didn't find this too attractive/useful. Most of the users have slow net connection undefinedincluding me ;) ). So the 'views' stats kept loading... loading... :)

Yogi
Art of Living Universe

Asif Shahzad on Feb 20, 2013, 9:11:00 AM said... #

Nice tutorial bro i considered that types of plugins can only be used on wordpress but amaze to know we can alo use it on blogger!

http://www.itstarz.com/
http://www.freeallstuff.com/

Aravind Palla on Feb 20, 2013, 9:16:00 AM said... #
This comment has been removed by the author.
Gireesh Sundaram on Feb 20, 2013, 9:28:00 AM said... #

Great break through to blog and bloggers. Thank you for soding and sharing..

Regards
Gireesh
CoreBlogging

iliyas shaikh on Feb 20, 2013, 9:35:00 AM said... #

thank you

Sumit Kumar Gogawat on Feb 20, 2013, 10:02:00 AM said... #

Amazing, But i want to know how can i add facebook + blogger comments box together with admin reply button Please reply. You are not reply my any queries, I hope this time i got my answer

Rahul Kashyap on Feb 20, 2013, 10:19:00 AM said... #

Awesome tricks thanks for sharing this on web :)

Regards
Rahul Kashyap
Blog: SDMMovies.com

Ranganathan C on Feb 20, 2013, 10:21:00 AM said... #

that was a nice one....was waiting for this kind of post views plugin !!!!!!!!!! TricksWorld 99

Kumar Suhas on Feb 20, 2013, 12:13:00 PM said... #

Very basic thought yet never introduce, will certainly help blogger hosted blogs to add this good feature. Great innovation MBT !

shakeel asghar on Feb 20, 2013, 1:05:00 PM said... #

I could not refrain from commenting. great brother i like it and add on my blog !
Download books and drivers

abdelkarim zanni on Feb 20, 2013, 1:55:00 PM said... #

Thank you Muhammad, this is an useful post, i thinsk i'll add it to my Blog!
_ ¦ _ ¦ _ _ ¦ _
Blogging iGeek
_ ¦ _ ¦ _ _ ¦ _

Jay Ryan Macabato on Feb 20, 2013, 2:18:00 PM said... #

I wanna try this..

www.MoreBlogTools.com

Levis Raju on Feb 20, 2013, 2:29:00 PM said... #

Really cool trick.... Allblogtools released a similar widget but it was a failure. Now you rocks :D

In And Out 2013

Haider Afridi on Feb 20, 2013, 3:31:00 PM said... #

I was in search for this since long time

Installed and working great ;)

Great Work Bro :D

Haider Afridi on Feb 20, 2013, 3:34:00 PM said... #

But the drawback is that this does not show the actual Views of the post

Parwinder Singh Bhangu on Feb 20, 2013, 5:17:00 PM said... #

Really a very helpful plugin for bloggers. I am also going to use this plugin for my website HiFiFun.Com All Kind of Tips and Tricks.

திண்டுக்கல் தனபாலன் on Feb 20, 2013, 5:40:00 PM said... #

Added it in My blog... Thanks...

J and K on Feb 20, 2013, 5:59:00 PM said... #

Great plugin, but I have one problem, it interferes with my post summary text. I would like to move it away. Can you help?

Blog: www.togetheragain2013.com

Mehul Mohan on Feb 20, 2013, 6:21:00 PM said... #

Mohammad sir,
I am very disappointed to say that blogger is not replying me at all. I did whatever you said and I didn't received even a single email from them.
One more blunder, my traffic has fallen from 800 pageviews a day to just 70. Please help me out sir! How to get my traffic back?!! I need your help!

blogging-heaven.com on Feb 20, 2013, 7:25:00 PM said... #

Another great article keep it up bro :)

Tahir Raza on Feb 20, 2013, 7:49:00 PM said... #

Great!

http://www.4dcores.com/

Aravind Palla on Feb 20, 2013, 9:02:00 PM said... #

Can i use the same firebase database for Multiple blogs?

J and K on Feb 20, 2013, 9:26:00 PM said... #

I corrected my above issue. I added padding to achieve space between my post summary and the counter.

Muhammad Touqeer on Feb 20, 2013, 10:24:00 PM said... #

Nice tutorial bro. thanks for the Code
Webhosting Pakistan

Hardeep Asrani on Feb 20, 2013, 11:27:00 PM said... #

seriously, you guys are amazing and thanks for this plugin...but it's not first....i has used a view counter widget in past, which was php based (you have to upload that file to a php hosting to use that plugin).

Mohammad Mustafa Ahmedzai on Feb 20, 2013, 11:27:00 PM said... #

@Tan Nguyen

You might have forgotten to replace the firebase url in step#3. Please create a firebase and then replace the url in the code above. Make sure you have not disabled javascript in your browser.

:)

@Tanmay
I have mentioned in the post that it will count from zero and wont display google analytics stats.

:)

@yogendra
I guess if you have a 100kbps Net speed then it must work. If you have a net slower then this, then have mercy on yourself! :p


@Sumit
Whenever I read your comment, I always try to reply captain. :)

For the comment box of facebook with blogger please read: Add Facebook and Blogger comments inside tabs


@kumar
That means a lot :)

@levis
Previously they would host it on their servers but that caused bandwidth problems, thats why it never worked earlier :)

@haider
the drawback is true only for older posts but it will show correct views for the newer one. Glad you liked it captain :)


@J and K
Glad you figured it out. The plugin could easily be positioned and aligned by adding margin property to the class:

#views-container

All CSS is available. For more help do let me know :)


@Mehul
I feel bad buddy. If they have not yet replied then may be your case was a serious one. I would encourage you to not loose hope and create a new one with far better unique content. You must introduce your own style and offer us all something new. I am sure this way you will enjoy your work even more like you always did. About the traffic its natural that it will drop because the domain content has been removed.

You can create a new blog and use the same domain for it as mypremiumtricks. You will be able to refer your readers back to a new blog but the search traffic can't be diverted because your pages are removed.


@Aravind
You can use it for all your 100 blogs! Enough badnwidth and storage there. :)





Mohammad Mustafa Ahmedzai on Feb 20, 2013, 11:29:00 PM said... #

@Hardeep Asrani

You are right buddy. That php plugins did exist as I mentioned earlier in my comment but a Javascript based plugin has been introduced first time thanks to the free service of firebase else even we would not be able to achieve this. :)

Akhil Swatantra on Feb 21, 2013, 12:20:00 AM said... #

Really Awesome I Like your This Post So Much Because I am sharing For this Plugin So many Times And i Got Some 4 Or 5 Article But All Script Is Not Working but Your Script Is Working thank you For Sharing man

Etech Entertainment
Online INdia Media Website

Mudassar Hussain on Feb 21, 2013, 1:22:00 AM said... #

Realy Osm... But its Not Work On My Site i Did All The Steps Plz Help me,, Thanks
Awaargi

Sheikh ArsLan AfzaL on Feb 21, 2013, 1:29:00 AM said... #

yes bro meri site per work ni kr rha jsy loading hi ho rhi ha?????

Tanveer Ahmad on Feb 21, 2013, 1:56:00 AM said... #

goog dear
www.mobile9plus.com

Icah Banjarmasin on Feb 21, 2013, 9:03:00 AM said... #

Wow..great..really really I like it's my favorite,thanks Mustafa happy nice day 4U and family..from INDONESIA with smile.

Yogendra Bhonsale on Feb 21, 2013, 5:31:00 PM said... #

Hehehe... thanks bro.
Yes, I have net speed of 100kbps
Bas kabhi kabhi dagaa de deta hai ;D

www.artoflivinguniverse.org

nani kk on Feb 21, 2013, 6:11:00 PM said... #

hi
its not working on my site
http://www.idlebrain5.in/
https://idlebrain5.firebaseio.com

please help

Ahmed Nasir on Feb 21, 2013, 7:18:00 PM said... #

@nani kk
I see that you have not added jQuery script. Please add this to your template before the views code.
http://codepaste.net/9bcc4m

Usama Sonu on Feb 21, 2013, 7:57:00 PM said... #

Like your post

Free Premium Acounts and Cookies - www.codeswork.tk

Vivek Gurung on Feb 21, 2013, 11:22:00 PM said... #
This comment has been removed by the author.
cyberkendra.com on Feb 21, 2013, 11:23:00 PM said... #

Thanks for worderful info. Like your blog

J and K on Feb 21, 2013, 11:43:00 PM said... #

Great plug-in! Is there a way to place it in the post header? My blog www.togetheragain2013.com uses a large 1st post image. When loading, the counter flashes then disappears behind the image. It doesn't show in any post then.

Thanks,
John

Ahmed Nasir on Feb 21, 2013, 11:48:00 PM said... #

@J and K .. It is because you have some problem in your existing javascript. If you move the post-views script above the script which is for avatar then it will work.

J and K on Feb 21, 2013, 11:58:00 PM said... #

Found it, fixed it. Works great!

Mohammad Mustafa Ahmedzai on Feb 22, 2013, 12:35:00 AM said... #

UPDATE

I forgot to mention the step of adding the JQuery script in your templates. If the image keeps on loading then it is because you have no jquery installed in your template. I have updated the tutorial please read Step#3.10


Thanks Ahmed for remining it :)

Atif Imran on Feb 22, 2013, 12:49:00 AM said... #

Masha Allah ,jo b krte ho kmaal ka krte ho , Mohammad Mustafa Ahmedzai , very nice I Hate Cracks

Sumit Kumar Gogawat on Feb 22, 2013, 9:03:00 AM said... #

Dear Mohammad,

Its good to visit your site again and again & i not get any solution of my query, this tutorial is working for other viewers but not running on my blog like your other tutorials. I again request you to see the problem. www.tallyssolution.blogspot.com

Regards

Gagan Masoun on Feb 22, 2013, 7:12:00 PM said... #

Great work brother, keep it up :)

nani kk on Feb 22, 2013, 7:36:00 PM said... #

@Ahmed Nasir

thanks now its working

Ahmed Al-Saadi on Feb 22, 2013, 8:54:00 PM said... #

Thanks
------
Ahmed Blog

Goonoo Muhammad Munawwar Muazzam on Feb 22, 2013, 10:20:00 PM said... #

Assalaamualaikum Brother. I want to say that you are a superb coder and developer. I didn't know that Blogger can be so beautiful with the template that you have just installed. I'm commenting after a long time because of some personal reasons. Seeing you blogging makes me feels good. I'll continue with my blogging and hope to make some money off Google Adsense.

I have a question. I want to know how much can a person earn if he is using Blogspot domain. Please reply

zeeshan jamal on Feb 22, 2013, 10:24:00 PM said... #
This comment has been removed by the author.
Mohammad Mustafa Ahmedzai on Feb 23, 2013, 1:07:00 AM said... #

@atif

Thanks for the kind feedback :)


@Sumit Kumar Gogawat

Buddy apply it on your blog first and then let me know. I visited your site but didn't find it. Please first add it.

For other tutorials you may post all your queries in template customization recipe. I will answer it there soon.

@Goonoo
W.salam brother,

Its indeed an honor and its a greta pleasure that you are commenting after a long time. I wish you keep visting and sharing your ideas with us.

About Adsense I would say its earning is not dependant on what platform you use, be it joomla, wordpress or blogger. your earnings depend on your traffic and CTR. I became a premium Adsense publisher at Blogger so the opportunities are hell lot. :)

Sumit Kumar Gogawat on Feb 23, 2013, 8:55:00 AM said... #

@Mohammad Mustafa Ahmedzai Dear Mohammad, I have already apply code on the blog and checked twicely, thricely. But i think something happen wrong with my blog. Because when i edit or add a widget my blog did not accept it. I was tried your lots of tutorial on my blog but every time its not working.

If you check my blog from my email id or password, then i send to you via email. Please help me.

J and K on Feb 24, 2013, 4:28:00 PM said... #

I like the concept very much, but have removed it for now because ity does not load very fast...will try again later.

Gurpreet Dhillon on Feb 24, 2013, 4:53:00 PM said... #

I added script after head but the views is stills loading.

this is my blog url.

www.wallpapersfever.com

สุรัตน์ สุดดำ on Feb 25, 2013, 10:43:00 AM said... #

Thank very mushhhhhhhhhhhhhhhhhhhhhhhhh شكرا جدا

bigtitlovers on Feb 26, 2013, 12:49:00 AM said... #

@Gurpreet Dhillon

on my blog still loading too...

this is my blog => http://bigtitlovers.blogspot.com/

Mohammad Sharfuddin on Feb 26, 2013, 11:44:00 AM said... #

Awesome MTB I have done Here's My Blog

http://mastereffects.blogspot.in

Zig Zoor on Feb 26, 2013, 4:46:00 PM said... #

ijin nyimak brooo,sekalian ijin folliw.mau copy paste ya tutorialnya.sekalian follow saja.

Zig Zoor on Feb 26, 2013, 4:52:00 PM said... #

license to practice the tutorial guys, follow all licenses and permits would paste copies of most of the article behind the blog follow me

Haz Issac on Feb 28, 2013, 6:34:00 PM said... #

i just use this.. simple and excellent.. http://graddit.com/ratings-widget :)

TiranaAduka on Mar 3, 2013, 8:22:00 AM said... #

thanks for the tutorial.

سید آصف جلال on Mar 8, 2013, 4:22:00 PM said... #

ایک مسئلہ درپیش ہو گیا ہے۔۔۔ میں نے اس پلنگن کو انسٹال کر لیا ہے لیکن اس سے متعلقہ پوسٹ کے کو شروع سے دکھا رہا ہے۔۔۔۔۔۔۔۔۔۔۔ فرض کریں بلاگر کنٹرول پینل میں میری پوسٹ کے 100 دیکھنے والے ہیں لیکن اس پلگن میں 0 سے سٹارٹ کر رہا ہے۔۔۔۔۔۔۔۔ کیا یہ ممکن ہے کہ وہ کنٹرول پینل پر سے بلاگر کے ویورز کو کاونٹ کرنا شروع کرے۔۔۔ ضرور بتائیے گا۔
سید آصف جلال
http://www.sadaemuslim.com/

kashif razzaq on Mar 12, 2013, 8:53:00 PM said... #

nice code for my blogger and i hope for other friends and very nice Artical..Download Pc Games

Admin on Mar 23, 2013, 6:45:00 PM said... #

It tried but it is not showing on my blog..Please help me out..

http://www.yourknowledgeportal.com/

Awais Ahmed on Apr 3, 2013, 1:59:00 AM said... #

Not showing buddy take a look and help please http://www.animeipics.com/

Мөнхбаяр on Apr 4, 2013, 10:31:00 AM said... #

http://testblogmutnaa.blogspot.com/

NOT WORKING HERE EITHER,,, seems like firebase recently changed,,,

Deddia Permana on Apr 12, 2013, 7:51:00 PM said... #

i'll try this to my blog,,
btw my blog using your template Salahudin Ayubi and i customize like your's

here http://www.depermana-share.blogspot.com

MD SHAMEEM AHAMMED on Apr 14, 2013, 5:15:00 AM said... #

Very nice post
I also add my blog
http://clickbrunei.blogspot.com

Ganesh Panda on May 2, 2013, 10:42:00 PM said... #

Thank you for this it works well but it shows wrong visit nos because in blogger view count it shows as 434 nos. But in this way it shows 133 views. why it shows so different.

My Site: www.odishajobs.co.in

AtiQah on May 5, 2013, 3:46:00 PM said... #

thanks a lot!

Click Here To add Comment

Confused? Feel free to ask

Your feedback is always appreciated. We will try to reply to your queries as soon as time allows.

Note:
1. To add HTML CODE in comments then please use our HTML Encoder
2. You can always Test the tutorial on our HTML Editor
3. No cheesy/spam Comments tolerated Spam comments will be deleted immediately upon our review.

Regards,
Mohammad

Support Us

If our Tutorials have helped you a little, then kindly spread our voice using the badge below:-

or try a Beautiful Banner


Widgets

 
  • MBT Icons and buttons

    Icons and Buttons

    Our resources have been successfully downloaded over 10K times and found almost every where. Get yours!

  • choosing webhost for a blog

    Why HostGator?

    Learn Why we chose HostGator as our Web Host and find discount coupons to kick start your blog today!

  • SEO Settings for blogger

    ALL IN ONE SEO PACK 2012

    Learn every single SEO tip that will boost your blog's ranking and organic traffic. We got them all!

  • Blogger widgets and plugins

    Visit MBT's Blogger LAB

    Why not take a tour of all great Blogger widgets published so far? You Name it we have it!

  • become a six figure blogger!

    Become a SIX FIGURE BLOGGER

    Learn what it takes to become a successful entrepreneur and build a living online!

About The Author

Hi! I am Mohammad, a certified SEO Consultant, Pro Blogger, Computer Engineer and an addicted Web Developer. Read More..

Recipes

SEO Affiliate Marketing Social Media

Make Money Online Web hosting

Blogging Tips Web Designing

Plugins and Widgets Blogging Ethics

Recent Comments

Popular Series

Powered by:

My Blogger Tricks © 2013. All Rights Reserved | Contact |