How to check if G Suite marketplace app/Addon store app is installed by my invited user?

50 views
Skip to first unread message

Hoang Trinh

unread,
Sep 1, 2019, 10:37:20 PM9/1/19
to Google Apps Script Community

I'm trying to make the invitation feature for my addon (it will be published to both G Suite marketplace and Addon store)

The scenario is:

1. User A want to invite user B to use the addon (because user A has bonus quota if he does)
2. User A will type the email of user B into a textbox in the Invitation page
3. Apps script code will send an email to user B. In this email, there is a link to install the addon
4. User B clicks the link, installs the addon
5. After that, somehow the our system know that user B installed the addon, and user B installed it via the invitation link from user A
6. Our system will add bonus quota for user A

As you can see, this feature heavily depends on whether our system can detect if "user B installed the addon, and installed it via the invitation link from user A"

So how can I do this?

Thank you very much.

Romain Vialard

unread,
Sep 2, 2019, 9:40:57 AM9/2/19
to Google Apps Script Community
Hi,

The easiest would be to have a referral page, where user A can enter the email address of user B. Your add-on could then send an invite email to user B and save his email address in a database of invitees along with his referrer.
When someone installs your add-on, you can then check his email address and see if it's in your database of invitees. If so, you can credit the referrer with more quota.

If you want to create an invitation link that people can share on social networks and elsewhere, it will be a bit trickier.
Indeed you don't control the installation page for your add-on (G Suite marketplace and Addon store) so you can't add anything there to check for something specific in the url (like a &referrer=userA at the end of the installation link).
To achieve this, you could create your own installation page which would automatically redirect the user to the G Suite Marketplace or add-on store. 
Specifically:
  • you provide a specific installation / invitation link to user A
  • when user B clicks on this link, it opens a web page you created. This page will simply store the referrer ID (contained in your invitation link) in user B's web browser (as a cookie or in the local storage) then redirect the user to the real store.
  • Once user B has installed the add-on from Google store, you can check if there's a referrer ID stored on the web browser. If so, you can credit user A.

Hoang Trinh

unread,
Sep 2, 2019, 11:19:03 AM9/2/19
to Google Apps Script Community
Thanks, Romain

I prefer solution 1, because it's easier and feel more natural to me (cookie is something that I don't want to touch)

In your 2 solutions (which are both great), there is one thing that I don't understand: How to know if user B installed the addon?

At the moment, I think only when user B opens the addon (sidebar/dialog), the system is able to detect this.
But if user B just installs and never open the addon, the system will never know, right? 

But in this case, user A still deserves the bonus quota (even if user B never open the addon).

What can I do to solve this issue?

Thank you.

Romain Vialard

unread,
Sep 2, 2019, 11:25:17 AM9/2/19
to Google Apps Script Community
There's an onInstall() function for add-ons, which is triggered when someone installs your add-on:

Hoang Trinh

unread,
Sep 2, 2019, 11:40:18 AM9/2/19
to Google Apps Script Community
I thought about this trigger, but because it's a simple trigger (onInstall can't be an installable trigger), so it can't use services or take other actions that require authorization.

And in order to connect to my database, I think I need to use service (I'm using this library to connect to Firestore actually https://github.com/grahamearley/FirestoreGoogleAppsScript)

Hoang Trinh

unread,
Sep 2, 2019, 9:52:02 PM9/2/19
to Google Apps Script Community
Sorry, I think I got what you meant

In the onInstall trigger, just call onOpen and do all the interaction with database in this onOpen trigger when AUTH_MODE is LIMITTED, is that correct?

Romain Vialard

unread,
Sep 3, 2019, 5:59:22 AM9/3/19
to Google Apps Script Community
The documentation might be a little bit misleading but the simple onInstall trigger runs with full permissions, as described here:
So you can make your call to Firestore from the onInstall function.

Hoang Trinh

unread,
Sep 3, 2019, 7:07:50 AM9/3/19
to Google Apps Script Community
It's great to know that.

Thank you very much.

Hoang Trinh

unread,
Sep 9, 2019, 1:04:18 AM9/9/19
to Google Apps Script Community
Hi Romain,


I've just published my addon to GSuite Marketplace and I found out that there is one serious issue that I didn't cover.

Thank you.
Reply all
Reply to author
Forward
0 new messages