1

I am currently using a Google Sheet to keep track of viewer count on several Instagram videos. My current formula:

=REGEXEXTRACT(IMPORTXML("A1","//script[@type='application/ld+json']"),"userInteractionCount"":""(\d+)")

(A1 is actually the instagram page link) It grabs the viewer count that I need , but it doesn't seem to auto-update when I refresh the page or when I close and reopen the page. Only way for the number to update is deleting are re-entering the formula. As I will be eventually keeping tabs on almost 1,000 videos, I would love a solution on how it updates with a page refresh or when I re-open the page.

rmrose
  • 11
  • 1

1 Answers1

0

Solution:

In order to make sure the imported data updates periodically, you can set up an Apps Script time-driven trigger that will periodically execute a function (called myFunction in the example below) that will:

Workflow:

  • Click Tools > Script editor in order to open the script editor.
  • Install the time-driven trigger. You can do that manually, following these steps, or programmatically, by copying this function to the script editor and executing it once:
function createTrigger() {
  ScriptApp.newTrigger("myFunction")
  .timeBased()
  .everyMinutes(1) // Alternatively, set it to 5,10,15,30 or use .everyHours
  .create()
}

Note: In this example, the function is set to run every minute; you can change that period by setting another value at .everyMinutes(1) -1, 5, 10, 15, 30 are allowed, see everyMinutes(n)- or using everyHours(n) instead, that's up to you.

  • Once the trigger is installed, a function called myFunction will run with the periodicity you have previously set. For example, if the formula is in cell A2 from Sheet1:
function myFunction() {
  const sheet = SpreadsheetApp.getActive().getSheetByName("Sheet1");
  const cell = sheet.getRange("A2");
  const formula = cell.getFormula();
  cell.clearContent();
  SpreadsheetApp.flush();
  cell.setFormula(formula);
}

Related:

Iamblichus
  • 18,540
  • 2
  • 11
  • 27