Javascript SDK
Learn how to use FlockSDK via a script tag to power referrals on your site.
Getting Started with FlockSDK
FlockSDK makes it simple to embed referral experiences on your website. This guide walks through the two main flows:
- Referrer β the customer who sees and interacts with the referral widget.
- Invitee β the visitor who lands on your site with a referral code.
FlockSDK is available via CDN, so you can add it to any webpage with just a script tag.
π§© Installation
Add the following to your HTML page:
Make sure this is loaded before you interact with FlockSDK
in your scripts.
π₯ Use Case: Referrer Setup
The referrer is your existing customer. The main flow here is:
- Initialize the SDK
- Identify the customer
- Render the referral widget
Example
π identify(...)
This step registers your user with Flock and retrieves their referral code.
You must call identify()
before renderWidget()
.
πͺ renderWidget()
Once the user is identified and a campaign is loaded, the SDK injects the referral widget into the page.
π± Use Case: Invitee Setup
The invitee is a visitor referred by someone else. The flow here is:
- Capture referral code from the URL
- Validate the referral
- Create the referral when the invitee signs up
Example
β
validateReferralCode(code, options)
This method checks if the referral code is valid and stores the metadata in the specified storage.
The options parameter supports:
storage
: Where to store the referral metadata'localStorage'
(default) - Persists in the browserβs local storage, can only be accessed by the same domain.'cookie'
- Useful for cross-subdomain scenarios.
When using cross-subdomain referrals, make sure to use the cookie
storage option. This allows the referral data to be shared between subdomains of the same root domain.
Note: Cookies only work for subdomains of the same root domain. They wonβt work across completely different domains (e.g., example.com β another.com).
π createReferral()
After the invitee signs up and is identified:
Or you can pass it explicitly:
π§ Tips
- Always call
identify()
beforerenderWidget()
orcreateReferral()
.
β Recap
Role | Key Methods |
---|---|
Referrer | identify() , renderWidget() |
Invitee | validateReferralCode() , createReferral() |
With these tools, you can power robust referral experiences in just a few lines of code.
Happy referring! π