Web Analytics - (Page) Word Count

1 - 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.

3 - Analytics Threshold

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

4 - Example

4.1 - 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:

4.2 - Custom Element

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap