Web Analytics - (Page) Word Count

About

Word Count is a metric that shows the total number of words a page and is a size definition. The more word, the bigger the page.

Analytics Threshold

Example of words threshold
< 400
Between 400 and 800
Between 800 and 1600
More than 1600

Example

Pure javascript

  • The HTML page with some words to count
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam quis neque nibh. Fusce vitae sapien tincidunt, facilisis risus id, vulputate erat. Ut eget ex sem. Donec ornare consequat risus. Fusce cursus non lorem eu pharetra. Quisque in tristique orci. Nunc luctus turpis id augue euismod volutpat. Morbi ut nunc maximus, rhoncus ante at, feugiat nunc.
  • The count function
function countWords(node){
   const text = node.innerText || node.textContent;
   return text.split(/\s+/g).length;
}
  • The main: we select the body node and count the words.
node = document.querySelector('body');
console.log("The total number of words is "+countWords(node))
  • Result:

Custom Element


Powered by ComboStrap