referkit
TypeScript/JavaScript adapter for integrating referral programs with Referkit API.
Sign up
Please make sure you have signed up with Referkit and have your email and password ready.
Install
npm i referkit
Getting started
In your project, authenticate (login) in the appropriate place to get an Auth
instance, which will be used to authenticate a Product
.
; { const auth = ; await auth; // Now we can use auth instead of raw token, which // atomically keeps track of the signed-in state. let product = 'alphaseek.io' auth; // Save product product = await prod; // Note that from field is the referral code of another referring user. const user = await 'user1@gmail.com' product from: '916hqpB7'; // Get user's unique referral link and code const url moniker score referrer = userreferral; console; // https://alphaseek.me/i/99PpQrh7 console; // 99PpQrh7 console; // 1 console; // 916hqpB7}
Authentication
To log into your account, use an Auth
as a static class or instantiate a singleton object. It is a single source of truth for your account identity as Alphaseek customer.
Static
; const token = await Auth;
The token will be stored in the browser's localStorage
if it's available and also in-memory as a static variable.
You can opt-out of storing the token in the browser's localStorage by setting Auth.useLocalStorage = false
before calling login()
.
To log out (invalidate the access token):
const ok = await Auth;
This also clears old token from the localStorage if Auth.useLocalStorage
is set to true
.
Singleton
You can also create an Auth
singleton instance so you could pass it around in other calls.
const auth = ;const tok = await auth; // Create a new product.const prod = 'awesome.app' auth;
Optionally, you could pass the access token as token
field in the object parameter
like so:
const prod = 'awesome.app' token: tok;
You can also inquire for your account information with
const myInfo = await auth;
Product
A Product
is the namespace of a campaign and its User
s.
An account has a default Product
tied to its registered email address's domain name,
for instance, a Product
with alias awesome-app-732109 is tied to a domain name
awesome.app.
An account can create more than one Product
. Product
s cannot share their User
s
across them.
const prod = 'awesome.app' auth;
User
The core of a referral is in the users' interactions. Here are some key points
about a User
:
- only have one referrer (another
User
who refers), but many referrees (otherUser
s whom thisUser
refers to yourProduct
) - owns a unique referral URL and a related referral code (called moniker) per
Product
- owns a referral score that increments when a new
User
is created with his moniker OR when he is created as aUser
with a referral code of someone else (2-side rewarding)
Your user's referral URL has a destination URL that it redirects to. For instance,
you could set it to your signup form page i.e. https://awesome.app/signup
. When it
actually redirects to the destination URL, it adds the following query parameters
?from=916hqpB7&source=alphaseek&type=referral
Your signup form should design a hidden form field that grabs the referral code
from the from
field or use JavaScript to do so to create the User
const urlParams = windowlocationsearch; if urlParams === 'alphaseek' const from = urlParams; let user = 'john.smith@gmail.com' from product; user = await user;
Use cases
- 2-sided reward when a user signed up
- Successful purchase with "coupon" code
- Priority queue based on referrals
Referral and Destination URLs
You can set the destination URL where the referral URL will redirect to
by calling update
method on the User
.
You can't change the user's default referral URL.
user = await user;
Most of the time, you may want to set a default destination on the Product
either when
creating it or updating it instead of setting one for each User
.
// Createconst prod = 'awesome.app' auth redirectUrl: 'https://awesome.app/signup'; // Updateprod = await prod;