Search code examples
google-apps-scriptgoogle-slides

Count how many times a Google Slide presentation has been opened - Apps Script


I want to measure the interaction with some of my Google Slide presentations. To be precise i want to count how many times a presentation has been opened by somebody.

What i have tried so far:

  1. Put simple onOpen(e) trigger in the G-Slide presentation to count each opening instance in a Google Sheet -> Result: simple onOpen trigger can't do that. Authorization issue...

  2. On the last Slide in the presentation create a single table cell with 0 in it. By simple trigger OnOpen(e) get that cell and that number and increment it by 1. -> Result: simple onOpen trigger can't do that. Authorization issue...

  3. Tried to implement an installable onOpen trigger for the Slide. -> Result: There is no installable onOpen trigger for G-Slide. Only for Sheets, Docs, ...

Is there any way to achieve my goal? If thats not achievable via AppScript I would also be greatful for alternative solutions.

Thanks in advance guys!


Solution

  • In your situation, how about using PropertiesService? I thought that when PropertiesService is used when the Google Slides file is opened, the count can be saved. the sample script is as follows.

    PropertiesService can be used with the simple trigger of OnOpen.

    Sample script:

    Please copy and paste the following script to the script editor of Google Slides and save the script. When you reopen the Google Slides, onOpen() is run. By this, the number of counts is increased.

    // This function is run when the Google Slides file is opened.
    function onOpen() {
      const key = "count";
      const p = PropertiesService.getScriptProperties();
      const c = p.getProperty(key);
      p.setProperty(key, c ? Number(c) + 1 : 1);
    }
    
    // When you run this function, you can see the current number of count.
    function checkCount() {
      const key = "count";
      const p = PropertiesService.getScriptProperties();
      const c = p.getProperty(key);
      console.log(c);
    }
    
    // When you run this function, you can reset the number of count.
    function clearCount() {
      const key = "count";
      const p = PropertiesService.getScriptProperties();
      p.deleteProperty(key);
    }
    
    • In this case, you can check the current number of counts by a script (checkCount function), and also you can manually check it by this method.

    Reference: