How to Display Total Views on Blogger Posts
ViewsIf your blog has jquery, you don't insert it.
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js' type='text/javascript'/>Insert under code after </body>
<script>
//<![CDATA[
/* View */
jQuery.getScript("//cdn.firebase.com/js/client/2.3.2/firebase.js").done(function () {
$.each($("a[name]"), function (e, o) {
var t = $(o).parent().find("#postviews"),
n = new Firebase("https://postviewd-default-rtdb.firebaseio.com/pages/id/" + $(o).attr("name"));
n.once("value", function (e) {
var a = e.val(),
s = !1;
null == a && ((a = {}), (a.value = 0), (a.url = window.location.href), (a.id = $(o).attr("name")), (s = !0)), t.text(a.value), a.value++, "/" != window.location.pathname && (s ? n.set(a) : n.child("value").set(a.value));
});
});
});
//]]>
</script>
Replace id "postviewd-default-rtdb" by your code registed at firebase.google.com
How to get id from firebase:
Step 1: Create a account firebase.google.com.Step 2: Create a project
Step 3: Create a realtime database
Step 4: Rues update
{ "rules": { ".read": true, ".write": true, } }Step 5: Copy id https://postviewd-default-rtdb.firebaseio.com/ (id is bold part of url).
Add under this code into Widget Blog id (Blog1).
<span class="postviews-post">Good luck to you! Done!<a expr:name="data:post.id"> </a> <span id="postviews" /> <span class="view-text"> Views</span></span>