Tracking sheet visitors

201 views
Skip to first unread message

Medhat Nawras

unread,
Jul 11, 2019, 5:39:37 AM7/11/19
to Google Apps Script Community
Hi all,

I'm a total newbie to Google Apps Script and I'd like to know if there's a way to track all the emails of those within my corporation domain who visited my sheet since its creation to the time being. I tried out getViewers() method but what I found that it detected the viewer who was watching the sheet only at the time I executed the script (which was actually me! :) )

Here's the simple code I wrote to try it out:

function viewViewer() {
  var ss = SpreadsheetApp.getActive();
  var know = ss.getViewers();
  Logger.log(know);
} Your contribution here is greatly appreciated

Vinicius Mello da Silva

unread,
Jul 11, 2019, 9:13:29 AM7/11/19
to google-apps-sc...@googlegroups.com
Do this: 

var user = Session.getActiveUser().getEmail() || Session.getEffectiveUser().getEmail();


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-script-community.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/a1e0df97-82c2-4064-a014-20486d48711e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Medhat Nawras

unread,
Jul 11, 2019, 11:39:59 AM7/11/19
to Google Apps Script Community
Hi Vinicius. Thanks for your response.

The log showed only my alias, the same thing that happened with the intitial script, although the activity dashboard showed some viewers who visited my sheet at a given time.

Thanks


On Thursday, July 11, 2019 at 3:13:29 PM UTC+2, Vinicius Mello da Silva wrote:
Do this: 

var user = Session.getActiveUser().getEmail() || Session.getEffectiveUser().getEmail();


On Thu, Jul 11, 2019 at 6:39 AM Medhat Nawras <alexa...@gmail.com> wrote:
Hi all,

I'm a total newbie to Google Apps Script and I'd like to know if there's a way to track all the emails of those within my corporation domain who visited my sheet since its creation to the time being. I tried out getViewers() method but what I found that it detected the viewer who was watching the sheet only at the time I executed the script (which was actually me! :) )

Here's the simple code I wrote to try it out:

function viewViewer() {
  var ss = SpreadsheetApp.getActive();
  var know = ss.getViewers();
  Logger.log(know);
} Your contribution here is greatly appreciated

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

James Lenthall

unread,
Jul 11, 2019, 11:51:56 AM7/11/19
to google-apps-sc...@googlegroups.com
If you want to track them at the time they're viewing, Vinicius's way will work.

Session.getActiveUser().getEmail()  is the person using it, so when you you're testing as yourself it's you.
Session.getEffectiveUser().getEmail(); is the person that app is running as, which depending on your publish settings will be yourself or the person using it.

So when testing both these options will it will show your alias for both. You'd need to test it via another account to show different.

Medhat Nawras

unread,
Jul 11, 2019, 12:24:53 PM7/11/19
to google-apps-sc...@googlegroups.com
Hi James,

So to double check with you and make sure I got you well: can this way track viewers who visited my sheet on a certain day? Or they have to be viewing it just right now? 

Thanks

On Thu, Jul 11, 2019, 5:51 PM 'James Lenthall' via Google Apps Script Community <google-apps-sc...@googlegroups.com> wrote:
If you want to track them at the time they're viewing, Vinicius's way will work.

Session.getActiveUser().getEmail()  is the person using it, so when you you're testing as yourself it's you.
Session.getEffectiveUser().getEmail(); is the person that app is running as, which depending on your publish settings will be yourself or the person using it.

So when testing both these answer will it will show your alias for both. You'd need to test it via another account to show different.

On Thursday, 11 July 2019 16:39:59 UTC+1, Medhat Nawras wrote:
Hi Vinicius. Thanks for your response.

The log showed only my alias, the same thing that happened with the intitial script, although the activity dashboard showed some viewers who visited my sheet at a given time.

Thanks


On Thursday, July 11, 2019 at 3:13:29 PM UTC+2, Vinicius Mello da Silva wrote:
Do this: 

var user = Session.getActiveUser().getEmail() || Session.getEffectiveUser().getEmail();


On Thu, Jul 11, 2019 at 6:39 AM Medhat Nawras <alexa...@gmail.com> wrote:
Hi all,

I'm a total newbie to Google Apps Script and I'd like to know if there's a way to track all the emails of those within my corporation domain who visited my sheet since its creation to the time being. I tried out getViewers() method but what I found that it detected the viewer who was watching the sheet only at the time I executed the script (which was actually me! :) )

Here's the simple code I wrote to try it out:

function viewViewer() {
  var ss = SpreadsheetApp.getActive();
  var know = ss.getViewers();
  Logger.log(know);
} Your contribution here is greatly appreciated

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

Fernando Falcao

unread,
Jul 13, 2019, 10:58:52 AM7/13/19
to google-apps-sc...@googlegroups.com
Hi James,

I believe you will have record this information in some database ou spreadsheet in case you want to track the history. For example, you could trigger the storing action when the user open the spreadsheet.

Does that make sense for you?

Cheers,
Fernando

James Lenthall

unread,
Jul 16, 2019, 3:48:00 AM7/16/19
to Google Apps Script Community
As Fernando has stated, you'd need to store the info somewhere, but it could be hidden protected sheet if you didn't want others to view it.

So when you're checking the user just run a function that adds a row to a logs sheet.

Apologies for the slow response I've been away.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages