One of the problems of measuring script or library usage is the identification of returning users. As you know email addresses or some other identification is not easily accessible (rightly so), and neither should it be stored in Analytics data. In Universal analytics measurement protocol for your GAS libraries I showed how Google Analytics could be used for library measurement, but the problem still persisted of counting the absolute number of different users in a kind of anonymous way.

Since the properties service has a script and a user level store, and although it’s obvious, it occurred to me that this could be used to know whether someone had used a library before. If they had, there would be a user level store – if not – they must be new.

So I put together this library that you can use for tracking usage (it can of course also track its own usage). Here’s the key, or you can copy the code at the end of this post.

MwbZ76EQqpFNfqh-XUl5Jxqi_d-phDA33

How to use

In the script that needs tracking, then do this. It returns the usage stats if you want to look at them

If you need to get overall usage stats, then you can also get them with this

If you want to track a library, I would recommend that you also allow opting-in rather than just tracking without asking. If you are using my version of this library and want to opt in to my tracking, then put this in your script too. The default is that no tracking is done.

What data is stored

Here’s what will be in your script store

And here’s what’s in each users store

The Id

So now every unique user will have an id you can use – for example – now I can improve Universal analytics measurement protocol for your GAS libraries by using this id to submit data against. It has the benefit of not being traceable to a specific person since no identifiable information is stored, but yet is unique and reusable, so will be useful in its own right – whether or not you use this for tracking usage.

The code

Here’s the function code.

Opting in for libraries

As I mentioned earlier, I think you that users should have to opt in to your tracking tracking of the usage of your library. But you can make the tracking mandatory, simply by adding this just before the end of your copy of the namespace, which will initiate track every time a script is run that includes your library.

For more like this see Google Apps Scripts Snippets
Why not join our forum, follow the blog or follow me on Twitter to ensure you get updates when they are available.