The User property service is handy to store user specific properties in, but it can also be used to assign a unique anonymous reference to users and track their visits. Here’s a useful namespace in the cUseful library you can use to do that.
It returns a closure which makes it easy to remove and update items once a registration has happened.

How to use

Here’s the key, and it’s also on github



Registering a user looks like this. You need to provide a properties service to user, along with the key to store it under.
var registration = cUseful.UserRegistration.register (PropertiesService.getUserProperties(), 'xliberation_registration_key');
That returns an object that looks like this. It will either be created and entered in the property store or retrieved if this is not the first time this user has been detected. In this example, this is the first time this user has visited. The id will be unique to this user for the lifetime of his properties service entry, and can be used to cross reference other data against if you want.
Subsequent visits will return registration objects like this.

Updating and removing

The registration object uses closures to avoid  having to provide keys and property store arguments.
It can be updated like this. Updating automatically maintains the visits count and lastVisit date.
It can be removed from the property store like this

Adding your on data

You can add additional data to the registration object, with something like this.
registration.myData = {
then when you
your data will be written too, and the result of the next registration will be

Exponential backoff

Since the properties store is a rate limited service, exponential backoff is used to ensure successful store access.


The cUseful library contains this and many other things posted around this site.
Here’s the key, and it’s also on github


For more like this, see Google Apps Scripts Snippets

Why not join our forum, follow the blog and or follow me on Twitter for more information and updates.