Yes 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!
UPDATE: Unfortunately firebase is no more free now, its Hacker free plan allows only 50 Max Connections which means it will work for small blogs with just less than 100 visitors per day
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.
- Towards the bottom right side of your account, you will find the following submit box.
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
- Go To Blogger > Template
- Backup your template
- Click Edit HTML
- Tick the box "Expand widget Templates"
- Search for ]]></b:skin>
- Just above it paste the following CSS code:
/*-------- Post Views ----------*/
#views-container {
width: 85px;
float: right;
}.mbtloading {
background: url('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHHYkd_OUt2PdAsKRVoAXdwZzn1_uD9adlxAgcQ6nv0Cj96_7rXYabsfiM_XhW7Q-odBUlqPtlnwqr-ljQvwhyphenhyphen-PEC-yupuTEjvLpt3nEFMkfqnqAgl4mDZ4lhrCzLF5hYf0JG7Od-Pc4e/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('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS9xFG-WYx_ddHQtKxvNA87IW9Cl3NTTLL7YhyucP3cZoAgN9hS4liEveFAMm_Rt_4cbva4HitGTArBH-RsMtX6EcZEtZvEyS5DoJlZ4ejls5ZU47F06A2jSA0dVkE6U988XUp6qGLQBzv/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('loading', '');
}, 10);
</script>
<script src='https://cdn.firebase.com/v0/firebase.js' type='text/javascript'/>
<script>
$.each($('a[name]'), function(i, e) {
var elem = $(e).parent().find('#postviews').addClass('mbtloading');
var blogStats = new Firebase("https://mybloggertricks.firebaseio.com/pages/id/" + $(e).attr('name'));
blogStats.once('value', 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('name');
isnew = true;
}
elem.removeClass('mbtloading').text(data.value);
data.value++;
if(window.location.pathname!='/')
{
if(isnew)
blogStats.set(data);
else
blogStats.child('value').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 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 »
Thanks Qasim! I was searching it from a long time. Firebase is really great. :)
ReplyDeleteWait why mine is just displaying loading icon instead of views number. Is it fine if I put it next to the post-label
ReplyDeleteIt's really very helpful. Thanks for the post.
ReplyDeletehttp://www.24xhtml.com/2013/02/use-unique-facebook-cover-photo-for.html#more
Will the count begin from zero or will it display the actual number of pageviews the post got ?
ReplyDelete@Tanmay Kapse
ReplyDeleteAccording to what I see right now. It's counting from 0. I maybe wrong though. :D
This comment has been removed by the author.
ReplyDeleteAmazing, 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
ReplyDeleteVery basic thought yet never introduce, will certainly help blogger hosted blogs to add this good feature. Great innovation MBT !
ReplyDeleteI was in search for this since long time
ReplyDeleteInstalled and working great ;)
Great Work Bro :D
But the drawback is that this does not show the actual Views of the post
ReplyDeleteAdded it in My blog... Thanks...
ReplyDeleteGreat plugin, but I have one problem, it interferes with my post summary text. I would like to move it away. Can you help?
ReplyDeleteBlog: www.togetheragain2013.com
Mohammad sir,
ReplyDeleteI 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!
Another great article keep it up bro :)
ReplyDeleteGreat!
ReplyDeletehttp://www.4dcores.com/
Can i use the same firebase database for Multiple blogs?
ReplyDeleteI corrected my above issue. I added padding to achieve space between my post summary and the counter.
ReplyDeleteseriously, 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).
ReplyDelete@Tan Nguyen
ReplyDeleteYou 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. :)
@Hardeep Asrani
ReplyDeleteYou 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. :)
goog dear
ReplyDeletewww.mobile9plus.com
Wow..great..really really I like it's my favorite,thanks Mustafa happy nice day 4U and family..from INDONESIA with smile.
ReplyDeleteHehehe... thanks bro.
ReplyDeleteYes, I have net speed of 100kbps
Bas kabhi kabhi dagaa de deta hai ;D
www.artoflivinguniverse.org
hi
ReplyDeleteits not working on my site
http://www.idlebrain5.in/
https://idlebrain5.firebaseio.com
please help
@nani kk
ReplyDeleteI see that you have not added jQuery script. Please add this to your template before the views code.
http://codepaste.net/9bcc4m
This comment has been removed by the author.
ReplyDeleteThanks for worderful info. Like your blog
ReplyDeleteGreat 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.
ReplyDeleteThanks,
John
@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.
ReplyDeleteFound it, fixed it. Works great!
ReplyDeleteUPDATE
ReplyDeleteI 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 :)
Dear Mohammad,
ReplyDeleteIts 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
Great work brother, keep it up :)
ReplyDelete@Ahmed Nasir
ReplyDeletethanks now its working
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.
ReplyDeleteI have a question. I want to know how much can a person earn if he is using Blogspot domain. Please reply
This comment has been removed by the author.
ReplyDelete@atif
ReplyDeleteThanks 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. :)
@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.
ReplyDeleteIf you check my blog from my email id or password, then i send to you via email. Please help me.
I like the concept very much, but have removed it for now because ity does not load very fast...will try again later.
ReplyDeleteI added script after head but the views is stills loading.
ReplyDeletethis is my blog url.
www.wallpapersfever.com
Thank very mushhhhhhhhhhhhhhhhhhhhhhhhh شكرا جدا
ReplyDeleteAwesome MTB I have done Here's My Blog
ReplyDeletehttp://mastereffects.blogspot.in
ijin nyimak brooo,sekalian ijin folliw.mau copy paste ya tutorialnya.sekalian follow saja.
ReplyDeletelicense to practice the tutorial guys, follow all licenses and permits would paste copies of most of the article behind the blog follow me
ReplyDeletethanks for the tutorial.
ReplyDeleteIt tried but it is not showing on my blog..Please help me out..
ReplyDeletehttp://www.yourknowledgeportal.com/
Not showing buddy take a look and help please http://www.animeipics.com/
ReplyDeletehttp://testblogmutnaa.blogspot.com/
ReplyDeleteNOT WORKING HERE EITHER,,, seems like firebase recently changed,,,
i'll try this to my blog,,
ReplyDeletebtw my blog using your template Salahudin Ayubi and i customize like your's
here http://www.depermana-share.blogspot.com
hey deddia,
Deletei wished to know how to get this template that you have on your blog. Its really ausm !!
Could you help me with it. Please.
thanks.! :)
Very nice post
ReplyDeleteI also add my blog
http://clickbrunei.blogspot.com
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.
ReplyDeleteMy Site: www.odishajobs.co.in
thanks a lot!
ReplyDeleteNot working
ReplyDeleteI cannot find the code in my template.Is there another area where I can place the code from step 9#.If there isn't can you tell me where this code is on my template.My web address is
ReplyDeletehttp://knightsofimhotepebooklibrary.blogspot.com/ Thank you.
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletethank you code but there is a problem for my site...
ReplyDeletewhen a page opened it shows first -for example-120 then shows 250... two diferent count. i think first is that page view... second total site view.. how can i fix that.. thnx...
my site: http://kampanyatakip.blogspot.com
This comment has been removed by the author.
ReplyDeletenot working..nothing happen..
ReplyDeletestill have the loading...
ReplyDeleteby da way, really great :)
its not working for my blog,, www.hdwalle.com i am useing custom template.. you can design the page-views same like www.hdwallpapers.in can you do it..?? waiting for your reply..
ReplyDeleteHotep!
ReplyDeleteGreat widget, this is why I'm a subscriber to this blog.I have applied this to two of my blogs already.But on my third blog for some reason it never shows the view counts it just keeps loading.Can you take a look at my blog and tell me what I have done wrong.I have 3 tags in my template and when I post the code under the first one it didn't work.When I post it under the 3 one its shows the views but keeps reloading.There is alot of other code surrounding the 2nd occurrence so I didn't try it there. Can you please help me out.
http://video.thisiskoi.com/
Thank you
Genius! Thank you Mr. Mohammad Mustafa Ahmedzai
ReplyDeleteFully Working!
see http://c8computer.blogspot.com/
Doesn't work for me :(((
ReplyDeleteIn the data base I can see everything, but no counter appears on my posts. Could you tell me why?
http://www.pulbere-de-stele.com/
It works now, but for the steps 8+9 I placed the code after the 3rd data:post.body/ line that I found, and the visits number appeared at last! :)
Deletethe only wonder thing is it takes too much time to show the account.
ReplyDeletemy blog : www.ermchen.com
i didn,t get any thing
ReplyDeleteI try to have my blog
ReplyDeletei have jquery v 1.8.3 plugin in my blog. so my question is that will i need to place jquery v 1 script also.
ReplyDeleteWill it take time to show up? Followed instructions but not appearing yet. Just did it 10 minutes ago...
ReplyDeletewww.investmentjuan01.com
it's working now... a bit. i'm still trying to relocate it since it overlaps with the body of my post. still trying to figure out the code. not too techy here hehe
DeleteMY blog does not seem to work this code although i strongly believe that i have installed your code.
ReplyDeleteCan you help me ?
My blog address: http://youtubehackers.blogspot.com
I have put the code from step by step on my blog http://infokubloggers.blogspot.com/ but the counter not yet display. Please help me to put it on my blog
ReplyDeletethank you
ReplyDeletehttp://aplaticos.blogspot.com
Hi mybloggertricks, nice to meet you...
ReplyDeletei just want to tell you, if your tutorial is not working.
In my blog still loading and not finish, it's so long...
but after i see blog demo seems working.
there may be something missing?
Widget are not working please work on and fix it
ReplyDeleteWhy don't you use Google analytic for this?
ReplyDeleteI was looking for feature like that since long time.
ReplyDeleteReally its a great and usefully idea.
But the widget is not working.
i did all mentionned in the post , but cant see the count , even the pict of views in my blog http://20-02.blogspot.com/
what about if I want it to display below titles on popular widget? I tried many times but it's not work
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHi,
ReplyDeleteCan we give it some initial start up value as we have old posts which have been viewed a nth times and starting it from zero will give a poor impression. Your answer on this aspect will be appreciated.
Regards
http://www.indian-share-tips.com/
Hi! I need help... the thing is that I want my posts to be completely visible, not short as they are now, but I don't know how to change the HTLM to make them look the way I want it.
ReplyDeletePlease, please help me!!!
NOT RUN in my Template, may be error in javascript interpreter brow
ReplyDeletei did it as you said ...followed all the steps but did not worked on my blog....allofmyanswers.blogspot.com
ReplyDeleteif you can edit my template i can give it to you..please reply me
it is very easy
Deletethank you brother for posting, it helped once for a beginner like me :)
ReplyDeleteyou commented on my blog but the link you gave and what i got the tutorial...that widgets is not correct ....it show error in html while saving template
DeleteI have added this with some little modifications. Why does this show and add post views for every posts...It adds up as page views not post views.
ReplyDeletehttp://malayalam.kitmovie.com/2014/05/oru-indian-pranayakadha-2013.html
It is all working very well, but the server serving the page data back is far too slow. It takes a long time and the visitor certainly doesn't wait long enough to see the number. http://lastingrose.blogspot.co.uk/2014/05/hello-india-welcome-to-club-of.html
ReplyDeleteThe server access and serving need to be much much faster
I have checked the database and it seems it is getting updated value with each visit. It looks your routine for updating the html needs some tweeking
ReplyDeleteelem.removeClass('mbtloading').text(data.value);
Hello,
ReplyDeleteThough the dab is getting written to reading back is sporadic and some goes to an ID called more instead of the usual number
8665769378527254191
comment-form
id:
url:
value:
comments
links
linkwithin_link_0
more
id:
url:
value:
undefined:
Any idea why more is created ?
The script is creating four piece of data under "name" variable besides ID
ReplyDeleteComments form
Comments
links
more.
The script then increments all of them for every new page in addition to the
original page
The current value of more (-1) is updated in the widget on HTML
(instead of the value under the ID which is the right one.)
Has it got anything to do with the version of
script src='https://cdn.firebase.com/v0/firebase.js' type='text/javascript'/
which was the one with the original acript.
The version I have running is the current one
script src='https://cdn.firebase.com/js/client/1.0.15/firebase.js'
type='text/javascript'/
This comment has been removed by the author.
ReplyDeletePlease see my message above too.
ReplyDeleteCould you please take a look at
https://idlebrain5.firebaseio.com/pages/id/
which is the DB for a site where the script is actually
working .http://www.idlebrain5.in/2013/10/shruti-haasan-photos.html
Could you see if the script actually creates IDs for comments, links and more etc
for that site.
I have closely examined the source code of the page to see how the three
elements , css, script and call have been placed and can't see any difference.
The problem obviously is in multiple data being created for the same page
and the script goes for one type (which is created last) like more.
When a page is selected which doesn't have that purticular element like more
the script just hangs , not finding the exact match to the previous value.
not work in my blog
ReplyDeleteWell, when the data identifier like <a name= is a string hard coded in to the html like "more"
ReplyDeletethe removeClass () works. This is done in the editor when you insert a break from the menu.
When <a name = it is dynamically created like from code < a expr:name= the MBT code works for creating and updating the Firebase database, but the removeClass function doesn't work.
Anyone knows how to resolve this?
Hello Mustafa,
ReplyDeleteI am quite surprised that you don't support this nice script created by you.
I get this in my data base , but the addClass/ removeClass functions fail.
crackling-fire-6727
pages
id
Why was the 2014 Indian parliament election anything but free and fair and ignored by western media?
id:
url:
value: 2
I request you to please solve this issue.
This comment has been removed by the author.
ReplyDeletethanks. it worked. i did it my blog
ReplyDeletehttp://lankanwada.blogspot.com/
Thanks..In my case, the counter does not increase after 1. LEt me know where I could be wrong
ReplyDeleteHumble apologies for the delayed response. I have been busy over the months and just happened to look back at the code. I have noticed that Firebase has started its premium plans aslo, it could be the reaoson that some changes might have been introduced in send/receive requests. I will review the script and get back with a more updated script
ReplyDeleteThank you for finding it so useful and worth trying. Means a lot :)
It won't work by me? I add all codes into blogger (html). How to enable it at firebase.com?
ReplyDeleteUnfortunately this free service by firebase is limited to 100 Database connections which in other words means that we can no more use it on multiple sites with consistent flow of traffic.
ReplyDeleteGoogle now charges $25/month for this service. :(
We tried our best developing this code first time for blogspot blogs but looks like Google Firebase is no more in mood to offer free lunch!
We can setup this plugin for premium clients if they can bear the firebase $25/month expense.
hey there mohammad, firebase released major update on oct 2016 and it is now up with new console
ReplyDelete