How To Add Post Views Counter To Blogger

Views

How To Add Post Views Counter To Blogger

This plugin is a great addition to your blog by letting your readers see how frequent the post was viewed. This might not be as accurate as GA but this plugin works like a charm, thanks to Firebase for making this possible by hosting this for FREE.

The process will require some editing on the Template section so i suggest to back up the theme first , here's how to back up your blogger theme. If your done backing up your theme lets get started.


1. Create Firebase account
Go to: https://firebase.google.com/
Start by creating an account , once done you will be redirected to firebase dashboard

2. Create a Project
Go to: https://console.firebase.google.com/
Click "Add a project" to get started 

Create Firebase account

3. Go to Database Tab and copy your Firebase database link
save it as we need it later

Firebase database link


4. Now go to Blogger Dashboard > Theme > Edit HTML
Copy this code then paste it before <data:post.body/> so it appears above your every post and below post title. 

<a expr:name='data:post.id'/> <i class='fa fa-eye'/> <span id='postviews'/> Views
5. Add this Javascript before </body>
to find </body>  press (CTRL+F)

<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;);
var blogStats = new Firebase(&quot;https://YOUR-APP-NAME.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.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>

6. Change the highlighted Red with your Firebase database link you previously saved.

Save Your theme now and the plugin works great!
To check the demo , check the views counter above my post.

How do you like this plugin? Any issue with the installation? Do let me know by leaving a comment below.

No comments:

Post a Comment

● Be sure to click "Notify Me" below, to get notified for follow up response.
● Respect! Do not Spam/Flood, you will be banned if you do so.
● Admin will try to get back to you as soon as we possibly can.

Need help with your blog?

Name

Email *

Message *

Popular Post

Comments