Post View Counter for Blog and Website

5:51 AM
1 comments
Ever wonder how many people visit your website? If you are an administrator of a site then i am sure you are. Now seriously if you are looking for a post view counter or tracker, then you have definitely come to the right place. Post view counter or tracker is such a widget or plugin that counts (and also displays) how many times a posts has been viewed. This helps blog author (and also readers) to know how much popular that post is. But to create this type of plugin, you have to know php, database, javascript etc, which is not so easy. However i have found a website, Firebase that also does the same job. You can create free accounts at Firebase and you can use their scripts to install post view counter plugin in your site. It doesn't matter which blogging platform you are using because Firebase works with all major blogging platforms and websites.
This is my second post about webpage counter. My previous post was about Download Counter for Blog and Website where i have discussed how Firebase actually works. You can check that out from here in case you are interested about how Firebase works. So i am not going into details.
Let's start.
Before you make any changes in your blogger template, it is recommended to backup your blog in case something goes wrong.
Step 1: Create Your Firebase Account
Signup for a free account at Firebase. Follow the steps carefully given at Firebase to activate your account.
Step 2: Create Your Database at Firebase
Firebase offers you to create 10 unique databases. In our just one database is required. So create one database at Firebase to store your post view stats. Give your database a unique name (for e.g. i named my database as 'bloganalyzer-demo-view-stat') and hit CREATE.

Note down the URL of your Firebase database. For e.g., in my case that URL will be https://bloganalyzer-demo-view-stat.firebaseio.com/.
Step 3: Install Post View Counter Plugin
As i have already discussed how Firebase works in my previous post, so right now i am giving you the script and steps for installing post view counter for your blogger blog and website.
  1. Go to 'Template' and click 'Edit HTML'.

    In case of blogger old interface, make sure that 'Expand Widget Templates' is checked.
  2. Make sure whether jQuery library is already included in your blog. If not, search for (
    Ctrl
    +
    f
    ) <head> and write down the following line just below <head>.

  3. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  4. Search for (
    Ctrl
    +
    f
    ) </head> and paste the following code before </head>.

  5. <script src='https://cdn.firebase.com/v0/firebase.js' type='text/javascript'></script>
    <script type="text/javascript">
    // <![CDATA[
    $(document).ready(function() {
    $('div.post').each(function() {
    var get_position = $(this);
    var get_name = $(this).children('a[name]').attr('name');
    var dataRef = new Firebase('YOUR DATABASE' + get_name);
    dataRef.once('value', function (snapshot) {
    var data = snapshot.val();
    if (data == null) {
    data=1;
    }
    else if (window.location.pathname!='/') {
    data++;
    }
    dataRef.set(data);
    get_position.find('div.blganr-view_counter').children('span').removeClass('blganr-loading').html(data);
    });
    });
    });
    //]]>
    </script>
    Be sure that you replaced YOUR DATABASE in the highlighted line with your actual database that you have created in step 2.
  6. Search for (
    Ctrl
    +
    f
    ) </b:skin> and paste the following code before </b:skin>.

  7. /*--Post View Counter by Bloganalyzer--*/
    div.blganr-view_counter {
    font:18px PT Sans Narrow;
    margin:0 10px 10px 10px; padding:8px 5px 8px 35px; float:right;
    text-align:center;
    box-shadow:0 0 2px #555;
    background:#fff url('http://3.bp.blogspot.com/-L45u_pdvSsg/Umz1WLZEUSI/AAAAAAAAC2A/96QhAnVyq-I/s1600/post-views.png') 3px 50% no-repeat;
    display:inline-block;
    z-index:9999;
    color:#444;
    }
    span.blganr-loading {
    background:url('http://3.bp.blogspot.com/-EERf4K_hjBg/UmzBza69BtI/AAAAAAAAC1Q/67AexTAsKJU/s1600/spinner.gif') 50% 50% no-repeat;
    display:inline-block;
    width:30px;
    height:18px;
    margin:0 0 -3px 0;
    }
  8. Search for (
    Ctrl
    +
    f
    ) post-header. You will find the following code.

    <div class='post-header'>
    <div class='post-header-line-1'/>
    </div>
    Now replace that <div class='post-header-line-1'/> with the following code.

    <div class='post-header-line-1'>
    <div class='blganr-view_counter'>
    Post Views: <span class='blganr-loading'/>
    </div>
    </div>
    So as a whole this will look like the following code.

    <div class='post-header'>
    <div class='post-header-line-1'>
    <div class='blganr-view_counter'>
    Post Views: <span class='blganr-loading'/>
    </div>
    </div>
    </div>
I tried my best to keep things as simple as possible. Any type of question related to this will be welcomed.
Happy Blogging.
Join the Conversation

Comments left on this site will be moderated. Note that all comments with abusive, disruptive or explicit content and comments with links will be deleted immediately.

1 comment so far on 'Post View Counter for Blog and Website'

© 2015 Bloganalyzer | Mirror. All rights Reserved. Designed By meNight Fury.