Getting user's email in add-on

105 views
Skip to first unread message

Finn Smith

unread,
May 10, 2024, 8:10:15 AMMay 10
to Google Apps Script Community
I'm working on a Sheets add-on with premium features. I need to check if the logged-in user has paid. Is getEffectiveUser() the best way to do this in a published add-on?

Abeer Shaheen

unread,
May 14, 2024, 6:29:09 AMMay 14
to google-apps-sc...@googlegroups.com
What is this about.

On Fri, May 10, 2024, 8:10 AM Finn Smith <finnba...@gmail.com> wrote:
I'm working on a Sheets add-on with premium features. I need to check if the logged-in user has paid. Is getEffectiveUser() the best way to do this in a published add-on?

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/ba1e9486-c76f-4c85-8a90-c588d4b5c412n%40googlegroups.com.

Ed Robinson

unread,
May 14, 2024, 8:40:40 AMMay 14
to Google Apps Script Community
Hi Finn,
Can you clarify your question?  You have several options for determining the user identity. 

Are you asking
1. how to get their indentity/email?  or
2. If the user has a paid Google Workspace acct? or
3. how to determine if the user has subscribed to be a paid user of your add-on? 


Ed Bacher

unread,
May 14, 2024, 10:49:33 AMMay 14
to Google Apps Script Community
Session.getActiveUser().getEmail() or Session.getEffectiveUser.getEmail() will get the user's email address. For details, see https://developers.google.com/apps-script/reference/base/session. This answers Ed Robinson's Question 1.

I'm interested in Question 2 -- determining if the user has a paid Workspace account.

Question 3 depends on how you are processing payments and saving payment/subscription information.

Ed Robinson

unread,
May 14, 2024, 11:41:56 AMMay 14
to Google Apps Script Community
Thx Ed. For Q2. See this article by Amit Agarwal.  Their example code shows how to determine if the user is on a paid or free Workspace acct:

Finn: Does this answer your question?

Ed Bacher

unread,
May 14, 2024, 8:46:11 PMMay 14
to Google Apps Script Community
Thanks, Ed! That code works great (though I've not tested it against a Google Workspace user -- it reports correctly for a Google free account).

Ed Robinson

unread,
May 14, 2024, 9:07:54 PMMay 14
to Google Apps Script Community
For me, on a Workspace account it works OK, but name is null. Email is OK, and hd is the domain name.

Finn asked the original question. Finn did you get the answer you needed?

Finn Smith

unread,
May 17, 2024, 1:33:13 PMMay 17
to Google Apps Script Community
Here is the situation I'm imagining:
  • John Doe is using the free version of my add-on that he installed through the marketplace.
  • John wants the premium features, so he clicks on the link to pay.
  • John pays through Stripe.
  • Stripe sends a webhook event to my event handler.
  • My event handler logs in a database that john...@gmail.com has paid.
  • The add-on gets John's email (john...@gmail.com) <--- This is what I'm asking about.
  • The add-on checks the database to see if john...@gmail.com has paid. <-- I'll have this happen on install and on open, but I'd also like to hear suggestions on elegant ways to do this right after John has paid. That is, if John has just gone through the check-out flow, how would you suggest I trigger the "has this person paid" check?
  • The add-on confirms that the status of john...@gmail.com is active and unlocks premium features.

Ed Robinson

unread,
May 17, 2024, 8:38:35 PMMay 17
to Google Apps Script Community
For enable/disable premium features, the most important thing is certainty + a stable experience for the user (they've just given you their credit card payment).
If you're processing recurring (eg: monthly) payments, you'll also have to handle expired cards, canceled subscriptions, changed subscriptions.

If you're building an editor add on, you could inform the customer "After you've subscribed, please close and re-open Finns-awesome-addon to enable premium features".
Then check the status and do the enable/disable features in the onopen event.   

This is not as graceful as "lighting up features" in real-time, but is simpler and more robust than polling for a sub, or setting up a webhook. Stripe does support webhooks (see: https://docs.stripe.com/webhooks). This would give the real-time enable-features experience, but it will be more complex to set up.

Reply all
Reply to author
Forward
0 new messages