Keep track of how often a (public) sheet has been opened using google app script

Little script to keep track on how often a (demo) sheet has been opened.

 

function onOpen() {
  
  var value = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Demo").getRange('C18').getValue();
  var results = value + 1;
  var range = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Demo").getRange("C18");
  range.setValue(results);
}

 

Here's a demo !

Enjoy !