google-apps-script

How long are Google Apps Script Properties persisted?


Where does the PropertiesService actually store its data and how long does it persist? Is it indefinite or, assuming it's a web app, until a user removes the access permissions?

The properties storage is extremely useful but since the interface is so opaque I have a lot of questions like this. The documentation says what it does, how to use it, but not how it works. Perhaps there is more to this that I haven't found? I'm happy to read any links sent my way also.


Solution

  • A Web App can only use either Script Properties or User Properties. A Web App is not a document (Sheet, Form, Doc or Slide) and therefore has no Document Properties.

    Document Properties are associated with the document, and they will stay with the Document even if a user uninstalls an addon.

    Script Properties are associated with the Apps Script file. Even if you publish an addon that runs as the user who installed the addon, the Script Properties get saved to your Apps Script file. In that situation, if you had 50,000 users, and configured your addon to allow the user to save values to Script Properties, then you'd have a problem very quickly because you'd run out of storage quota. Which brings up the issue of storage.

    Properties Service isn't good for things like large template files. Like a large template email for a mail merge.

    Addons can't access Document Properties or User Properties of other addons. So, for an addon, Document and User Properties are scoped to that addon.

    Script Properties are saved to the Apps Script file of the addon developer who owns the Apps Script file.

    User Properties are associated with the account of the user. The user is the account that approved the permissions, under whose authority the code is running.

    If a Web App is published to be accessible to anyone, even anonymous, but it runs as you, then you (The owner of the Apps Script file) are the user, not the people viewing the Web App. A Web App can actually save user data into a file (E.g. text file) in the users App Data folder.

    See: https://developers.google.com/drive/api/v3/appdata

    For your Web App to store data in the users App Data folder then need to approve a permission. The scope for the App Data folder is: "https://www.googleapis.com/auth/drive.appdata" If a user removes the authorization access to the code, it does not trigger the saved properties to be deleted. Removing authorization or uninstalling an addon without deleting the property keys will create orphaned data taking up quota. Any files in the users App Data folder do get deleted if the app is uninstalled.