From ad48a9ab06617b98ccab9769032bf44fec31b8ec Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Fri, 24 Jul 2020 20:45:19 +0800 Subject: [PATCH] Fixed empty PV issue. --- assets/js/_utils/pageviews.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/assets/js/_utils/pageviews.js b/assets/js/_utils/pageviews.js index 2b34d19..f787f0b 100644 --- a/assets/js/_utils/pageviews.js +++ b/assets/js/_utils/pageviews.js @@ -26,11 +26,13 @@ function countUp(min, max, destId) { function countPV(path, rows) { var count = 0; - for (var i = 0; i < rows.length; ++i) { - var gaPath = rows[i][0]; - if (gaPath == path) { /* path format see: site.permalink */ - count += parseInt(rows[i][1]); - break; + if (rows !== undefined ) { + for (var i = 0; i < rows.length; ++i) { + var gaPath = rows[i][0]; + if (gaPath == path) { /* path format see: site.permalink */ + count += parseInt(rows[i][1]); + break; + } } } @@ -59,7 +61,7 @@ function displayPageviews(data) { } var hasInit = getInitStatus(); - var rows = data.rows; + var rows = data.rows; /* could be undefined */ if ($("#post-list").length > 0) { /* the Home page */ $(".post-preview").each(function() {