Tổng hợp một số code thống kê sử dụng trong Blogger

Chào các bạn, để tiện các bạn theo dõi tìm kiếm code thống kê sử dụng trong Blogger nên mình viết sẵn tổng hợp trong bài này và cập nhật khi có code mới. Phương pháp mình sử dụng là GET JSON nên có nhiều ưu điểm tốc độ tảo trang không bị hạn chế và đã là code thống kê phải cho ra một số cụ thể.

Tổng hợp một số code thống kê sử dụng trong Blogger

Lưu ý code được đặt trong đoạn script dưới đây

Copy

<script>

//<![CDATA[

// Code

//]]>

</script>

Đặt script trước thẻ </head> hay trước thẻ đóng </body> đều được tuy nhiên chèn trước </head> sẽ xuất dữ liệu nhanh hơn

1. Tổng số bài viết

Copy

$.ajax({

  url: "/feeds/posts/default?alt=json-in-script",

  type: "get",

  dataType: "jsonp",

  success: function(data) {

    var totalposts = data.feed.openSearch$totalResults.$t;

    $('.total-posts').html(totalposts);

  }

});

– Html hiển thị: <span class=’total-posts'</span>

2. Tổng số trang tĩnh

Copy

<script>

//<![CDATA[

$.ajax({

  url: "/feeds/pages/default?alt=json-in-script",

  type: "get",

  dataType: "jsonp",

  success: function(data) {

    var totalpages = data.feed.openSearch$totalResults.$t;

    $('.total-pages').html(totalpages);

  }

});

//]]>

</script>

– Html hiển thị: <span class=’total-pages’></span>

3. Tồng số nhận xét

Copy

$.ajax({

  url: "/feeds/comments/default?alt=json-in-script",

  type: "get",

  dataType: "jsonp",

  success: function(data) {

    var totalcomments = data.feed.openSearch$totalResults.$t;

    $('.total-comments').html(totalcomments);

  }

});

– Html hiển thị: <span class=’total-comments'</span>

4. Tổng số Label (Nhãn)

Copy

$.ajax({

  url: "/feeds/posts/default?alt=json-in-script",

  type: "get",

  dataType: "jsonp",

  success: function(data) {

    var totallabels = data.feed.category.length;

    $('.total-labels').html(totallabels);

  }

});

– Html hiển thị: <span class=’total-labels'</span>

5. Số lượt chia sẻ và bình luận của một Url bài viết, xem chi tiết >

Copy

var postUrl = location.href;

var get_fbcount = function() {

  $.getJSON('https://graph.facebook.com/' + postUrl, function(data) {

    var commentcount = data.share.comment_count;

    console.log(data);

    if (commentcount) {

      $('.comment_count').append(commentcount);

    } else {

      $('.comment_count').append(0);

    }

var sharecount = data.share.share_count;

    console.log(data);

    if (sharecount) {

      $('.share_count').append(sharecount);

    } else {

      $('.share_count').append(0);

    }

  });

};

get_fbcount();

– Html hiển thị: <span class=”share_count”></span> và <span class=”comment_count”></span>

6. Số lượt theo dõi từ Google+ và YouTube, xem chi tiết >

+ Goolge Plus:

Copy

$.ajax({

  type: 'GET',

  dataType: 'json',

  url: 'https://www.googleapis.com/plus/v1/people/Google+_ID?key=API_Key',

  success: function(data) {

    var gpluscount = data.circledByCount;

    $('.gplus-count').html(gpluscount);

  }

});

– Html hiển thị: <span class=’gplus-count’></span>

+ YouTube:

Copy

$.ajax({

  type: 'GET',

  dataType: 'json',

  url: https://www.googleapis.com/youtube/v3/channels?part=statistics&id=YouTube_Channel_ID&key=API_key',

  success: function(data) {

    var ytcount = data.items[0].statistics.subscriberCount;

    $('.yt-count').html(ytcount);

  }

});

– Html hiển thị: <span class=’yt-count’></span>

View Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Published by
5 years ago