This reference documents the GrowSurf JavaScript SDK, including all available public methods and examples of each.
If you're using an AI tool such as Cursor, ChatGPT Codex, or Claude Code to help you implement GrowSurf, we recommend utilizing our MCP server.
Add participant
Adds a participant to the referral/affiliate program. Use this method for the following use-cases:
Add referral tracking to your current signup form. If a referral link was used, GrowSurf automatically submits the referrer ID behind the scenes. (We recommend adding only referred participants — view this tutorial for more info)
Generate referral links for your signed-in users on the fly (or return existing data if they are an existing participant)
Tips: Though they are optional, we recommend passing in the fields firstName and lastName . These fields are used for anti-fraud purposes and they show up in referred friend motivator elements, if enabled. Behind the scenes, this method also passes in other properties like IP address and fingerprint, which will also be used for anti-fraud purposes.
Note: A 401 error will be returned if the following conditions are met: (1) the program has participant authentication enabled, (2) there is no authentication cookie present on the participant's browser, (3) the given email is the same as an existing participant.
growsurf.addParticipant(data, callback);
Parameter
Data Type
Description
data
String or Object
(Required)A String containing the participant email or an Object containing the participant email and any other data to include for the participant.
If providing an Object, any Object keys other than email, firstName, lastName , and gdprAgreements will be treated as metadata by GrowSurf.
For more information about metadata please see our API Guidelines.
callback
Function
(Optional) A callback function that will be invoked with the added participant data if successful.
Returns a Promise that resolves with an Object containing limited participant data.
Example use
// Email only using a Callbackgrowsurf.addParticipant('[email protected]', (participant) => {// handle participant});// Object using a Callbackgrowsurf.addParticipant({ email:'[email protected]', firstName:'Gavin',// optional, but recommended for anti-fraud purposes lastName:'Belson',// optional, but recommended for anti-fraud purposes company:'Hooli, Inc',// Fields that are not email, firstName, or lastName will be saved as custom metadata companySize:10000// Fields that are not email, firstName, or lastName will be saved as custom metadata}, (participant) => {// handle participant});
// Email only using a Promisegrowsurf.addParticipant('[email protected]').then(participant => {// handle participant});// Object using a Promisegrowsurf.addParticipant({ email:'[email protected]', firstName:'Gavin',// optional, but recommended for anti-fraud purposes lastName:'Belson',// optional, but recommended for anti-fraud purposes company:'Hooli, Inc',// Fields that are not email, firstName, or lastName will be saved as custom metadata companySize:10000// Fields that are not email, firstName, or lastName will be saved as custom metadata}).then(participant => {// handle participant});
Example response
Trigger referral
Referral programs only
Triggers a referral, awarding referral credit to the referrer of an existing or new participant. If the program participant does not exist, they will be newly added.
Note: A 401 error will be returned but the referral will still be triggered if the following conditions are met: (1) the program has participant authentication enabled, (2) there is no authentication cookie present on the participant's browser, (3) the given email is the same as an existing participant.
Parameter
Data Type
Description
data
String or Object
(Optional) A String containing the participant email or an Object containing the participant email and any other data to include for the participant.
If providing an Object, any Object keys other than email, firstName, and lastName will be treated as metadata by GrowSurf.
*This parameter is only optional if the participant has already signed up for the campaign and GrowSurf is able to determine they are a participant (does not include participants imported or manually added using the dashboard). For more information about metadata please see our API Guidelines.
callback
Function
(Optional) A callback function that will be invoked with the added or updated participant data if successful.
Returns a Promise that resolves with an Object containing limited participant data.
Example use
Example response
Get campaign
Retrieves limited details of a campaign.
Parameter
Data Type
Description
callback
Function
(Optional) A callback function that will be invoked with the campaign data.
Returns a Promise that resolves with an Object containing limited campaign data of id and rewards.
Example use
Example response
Get participant by email
Retrieves limited details of an existing participant. You will need to supply the unique email of the participant.
Note: A 403 error will be returned if the following conditions are met: (1) the program has participant authentication enabled, (2) there is no authentication cookie present on the participant's browser.
Parameter
Data Type
Description
participantEmail
String
(Required)The email of the participant to retrieve.
callback
Function
(Optional) A callback function that will be invoked with the participant data if successful or undefined if the participant does not exist.
Returns a Promise that resolves with an Object containing the participant data.If the participant does not exist in the campaign, then undefined is returned.
Example use
Example response
Get participant by ID
Retrieves limited details of an existing participant. You will need to supply the GrowSurf unique identifier that was returned upon participant creation.
Note: A 403 error will be returned if the following conditions are met: (1) the program has participant authentication enabled, (2) there is no authentication cookie present on the participant's browser.
Parameter
Data Type
Description
participantId
String
(Required)The GrowSurf identifier of the participant to retrieve.
callback
Function
(Optional) A callback function that will be invoked with the participant data if successful or undefined if the participant does not exist.
Returns a Promise that resolves with an Object containing the participant data.If the participant does not exist in the campaign, then undefined is returned.
Example use
Example response
Get referrer ID
Returns the ID of the participant that referred the visitor or null if the visitor was not referred. This method will first check to see if a grsf URL parameter exists, then will check for the presence of a referrer ID as a browser cookie (which was set from the initial visit).
Example: Someone refers their friend, and the friend visits http://yoursite.com?grsf=1h97da. Calling this method will return 1h97da (which is the referrer ID).
Returns the ID of the authenticated participant or null if there is no participant authentication cookie present.
Example: Someone signed up as a participant in your referral/affiliate program from your website. Calling this method will return aj7auu1 (which is the participant ID).
Example use
Example response
Get affiliate summary
Affiliate programs only
Returns affiliate summary statistics for the currently logged-in participant.
Note: A 401 error will be returned if the following conditions are met: (1) the program has participant authentication enabled, (2) there is no authentication cookie present on the participant's browser
Returns a Promise that resolves with an Object containing limited commissions data.
Example use
Example response
Get commissions
Affiliate programs only
Returns a paginated list of commissions for the logged-in participant.
Note: A 401 error will be returned if the following conditions are met: (1) the program has participant authentication enabled, (2) there is no authentication cookie present on the participant's browser
Parameter
Data Type
Description
options
Object
(Optional) An object containing pagination options.
options.limit
Number
(Optional) The number of commissions to return per page. Defaults to 20.
options.nextId
String
(Optional) The ID of the commission to start the next result set with. This can be used to skip through the list or to page the list results. Each response will provide a nextId value if there are more commissions otherwise the nextId value will be null.
Returns a Promise that resolves with an Object containing limited commissions data.
Example use
Example response
Get payouts
Affiliate programs only
Returns a paginated list of payouts for the logged-in participant.
Note: A 401 error will be returned if the following conditions are met: (1) the program has participant authentication enabled, (2) there is no authentication cookie present on the participant's browser
Parameter
Data Type
Description
options
Object
(Optional) An object containing pagination options.
options.limit
Number
(Optional) The number of payouts to return per page. Defaults to 20.
options.nextId
String
(Optional) The ID of the payout to start the next result set with. This can be used to skip through the list or to page the list results. Each response will provide a nextId value if there are more payouts otherwise the nextId value will be null.
Returns a Promise that resolves with an Object containing limited payouts data.
Example use
Example response
Initialize unread notifications badge
This method will inject an unread notifications badge onto a target element.
The unread badge will be injected into your target element
This method is useful for highlighting an unread notifications badge to your users from within your own user portal.
We recommend that the target element be a button that opens the GrowSurf window (via growsurf.open()), because the unread notifications badge will be cleared when the participant views the respective section in the GrowSurf window (rewards section for referral programs; commissions or payouts sections for affiliate programs).
If a participant cookie doesn't exist, the badge will not be displayed on the target element.
Parameter
Data Type
Description
targetElement
String
(Required) The target element
Example: .my-button
type
String
(Optional) Available options:
rewardscommissionspayouts
If no type is provided, then all unread notification badges will be initialized.
Example use
CSS Alternative:
Instead of using the JavaScript method growsurf.initUnreadNotificationsBadge(), you can simply add a CSS class growsurf-unread-notifications-badge to your target element. This will also inject the unread badge without requiring JavaScript.
Here is an example:
Important Note: Notification counts will not appear if you have certain sections disabled within the Program Editor > 2. Design > Rewards section. For example:
For referral programs, if you have the rewards section hidden (see image below), the notification counts will not appear.
For affiliate programs, if you have the commissions or payouts sections hidden (see image below), the notification counts will only reflect the sections that are enabled.
Get unread notifications count
Returns the number of unread notifications (rewards for referral programs; commissions and payouts for affiliate programs) of the authenticated participant or null if there is no participant authentication cookie present. This method is useful for highlighting an unread notifications badge to your users from within your own user portal.
(Optional) Available options:
rewardscommissionspayouts
If no type is provided, then all unread notification counts will be returned.
Example use
Example response
Important Note: Notification counts will not appear if you have certain sections disabled within the Program Editor > 2. Design > Rewards section. For example:
For referral programs, if you have the rewards section hidden (see image below), the notification counts will not appear.
For affiliate programs, if you have the commissions or payouts sections hidden (see image below), the notification counts will only reflect the sections that are enabled.
Mark notifications as read
Mark unread notifications of the authenticated participant. This method is useful if you are using growsurf.initUnreadNotificationsBadge() instead of the GrowSurf window to show your users their unread notifications count and want to clear out the unread badge.
Parameter
Data Type
Description
type
String
(Optional) Available options:
rewardscommissionspayouts
If no type is provided, then all unread notifications will be marked as read.
Returns a Promise that resolves with an Object with a success response.
Example use
Example response
Update social share message
Updates the pre-populated social share message for the given share type (e.g, email, Facebook, Twitter). This method will update all social share buttons in GrowSurf embedded elements and the GrowSurf window.
Example: This method is useful for optimizing referral asks when your participants complete an "aha moment". You would present your participant with the GrowSurf Embedded Form element and then call this method to update social share message(s) to be specific to the "aha moment". See this tutorial for an example.
Parameter
Data Type
Description
type
String
(Required) The social share type to update.
These are the options:
email
facebook
twitter
threads
bluesky
pinterest
sms
whatsapp
reddit
tumblr
message
String
(Required) The new pre-populated social share message.
Use {{shareUrl}} to reference the participant's referral link.
subjectLine
String
(Optional) The new pre-populated subject line (only applies when type is email).
Use {{shareUrl}} to reference the participant's referral link.
Example use
Update email invite message
Updates the pre-populated email invite message. This method will only apply updates to GrowSurf Embedded Invite elements (the email invite section within the GrowSurf window will not be updated).
Example: This method is useful for optimizing referral asks when your participants complete an "aha moment". You would present your participant with the GrowSurf Embedded Invite element and then call this method to update the email invite message to be specific to the "aha moment". See this tutorial for an example.
Parameter
Data Type
Description
message
String
(Required) The new pre-populated email invite message.
Use {{shareUrl}} to reference the participant's referral link.
subjectLine
String
(Optional) The new pre-populated subject line.
Use {{shareUrl}} to reference the participant's referral link.
Example use
Log out
Logs the participant out of the browser (clears the participant's GrowSurf browser cookie and local storage).
Example use
Initialize / Reinitialize GrowSurf
Initializes or reinitializes the window.growsurf Object.
The method is useful for the following use-cases:
If you have participant authentication enabled for your program and you would like to automatically authenticate your participants after they log in within your own user portal.
Load multiple programs on a single webpage depending on where the traffic is coming from. View a tutorial here.
Example use
Parameter
Data Type
Description
settings
Object
(Optional) The settings GrowSurf should use when initializing or reinitializing.
campaignId- Provide this to initialize another program
email- The email of the participant you wish to auto authenticate (only applies if authentication is enabled for your program).
hash- The hash token generated by your server. Used to auto authenticate a participant (only applies if authentication is enabled for your program).
Open GrowSurf window
Opens the GrowSurf window.
Parameter
Data Type
Description
callback
Function
(Optional) A callback function that will be invoked once complete
Adds an event subscription of the given event type. When an event of the given type occurs, the given callback will be invoked. Below are detailed descriptions of each event type.
Parameter
Data Type
Description
eventType
String
(Required) The event type to subscribe to.
These are the options:
referral
referralTrigger
signup
share
invite
callback
Function
The callback function that will be invoked when the event occurs.
Example use
Example response
Dispatched anytime an event happens. The provided callback will be invoked with an Object containing data relevant to the event.
The 'referral' event returns limited data of the new referred participant. The referredBy key represents the referring participant's unique ID.
The 'referralTrigger' Event returns limited data of the referred participant that triggered a referral (which means they completed a qualifying action).
Note: This event happens when calling growsurf.triggerReferral(). If you are looking for the referred signup event, use the 'referral' Event that contains a referredBy property.
The 'signup' Event returns limited data of the new non-referred participant.
The 'share' Event returns limited data of the participant and the share type.
The shareType value will either be a social network (e.g., linkedin, reddit) or copyLink if the participant copied their link to share (e.g., they clicked "Copy Link").
The 'invite' Event returns limited data of the participant and the number of invites sent.
If your campaign is set up for email invites to be sent by participants, invitesAttempted will always match invitesSent. If email invites are sent by your company, invitesSent will only count successfully delivered emails confirmed by our server. Learn more here.
// Email only using a Callback
growsurf.triggerReferral('[email protected]', (participant) => {
// handle participant
});
// Object using a Callback
growsurf.triggerReferral({
email: '[email protected]',
firstName: 'Gavin', // optional, but recommended for anti-fraud purposes
lastName: 'Belson', // optional, but recommended for anti-fraud purposes
company: 'Hooli, Inc', // Fields that are not email, firstName, or lastName will be saved as custom metadata
companySize: 10000 // Fields that are not email, firstName, or lastName will be saved as custom metadata
}, (participant) => {
// handle participant
});
// Email only using a Promise
growsurf.triggerReferral('[email protected]').then(participant => {
// handle participant
});
// Object using a Promise
growsurf.triggerReferral({
email: '[email protected]',
firstName: 'Gavin',
lastName: 'Belson',
company: 'Hooli, Inc',
companySize: 10000
}).then(participant => {
// handle participant
});
// Using a Callback
growsurf.getAffiliateSummary({}, (summary) => {
console.log('Affiliate Summary:', summary);
});
// Using a Promise
const summary = await growsurf.getAffiliateSummary();
console.log(summary);
{
"referralRevenue": 2500000, // Total revenue generated from referrals (in minor currency units, e.g., cents)
"totalPaidOut": 1500000, // Total commissions paid out to the affiliate (in minor currency units)
"upcomingPayout": 500000, // Pending commissions to be paid out (in minor currency units)
"referrals": 23, // Number of successful referrals
"leads": 45, // Number of pending referrals (leads)
"clicks": 23000, // Number of unique visitors from the affiliate's referral link (aka unique impressions)
"currencyISO": "USD" // The ISO 4217 currency code of the campaign (e.g., "USD")
}
growsurf.getCommissions(options, callback);
// Using a Callback - First page
growsurf.getCommissions({ limit: 10 }, (result) => {
console.log(result.commissions); // Array of commission objects
console.log(result.summary); // Summary of commissions by status
console.log(result.hasMore); // Boolean indicating if more results are available
console.log(result.nextId); // Cursor ID for next page (undefined if no more results)
});
// Fetching the next page
growsurf.getCommissions({ limit: 10, nextId: 'comm_abc123' }, (result) => {
console.log(result.commissions); // Next page of results
});
// Using a Promise - First page
const result = await growsurf.getCommissions({ limit: 10 });
console.log(result.commissions); // Array of commission objects
console.log(result.summary); // Summary of commissions by status
// Fetching additional pages
if (result.hasMore) {
const nextPage = await growsurf.getCommissions({ limit: 10, nextId: result.nextId });
console.log(nextPage.commissions); // Next page of results
}
// Using a Callback - First page
growsurf.getPayouts({ limit: 10 }, (result) => {
console.log(result.payouts); // Array of payout objects
console.log(result.summary); // Summary of payouts by status
console.log(result.hasMore); // Boolean indicating if more results are available
console.log(result.nextId); // Cursor ID for next page (undefined if no more results)
});
// Fetching the next page
growsurf.getPayouts({ limit: 10, nextId: 'payout_xyz' }, (result) => {
console.log(result.payouts); // Next page of results
});
// Using a Promise - First page
const result = await growsurf.getPayouts({ limit: 10 });
console.log(result.payouts); // Array of payout objects
console.log(result.summary); // Summary of commissions by status
// Fetching additional pages
if (result.hasMore) {
const nextPage = await growsurf.getPayouts({ limit: 10, nextId: result.nextId });
console.log(nextPage.payouts); // Next page of results
}
const message = "I have saved 1,540 hours using this service. Highly recommend! {{shareUrl}}";
const subjectLine = "Check this out!";
// Update the pre-populated email social share message
growsurf.updateSocialShareMessage('email', message, subjectLine);
// Update the pre-populated Facebook social share message
growsurf.updateSocialShareMessage('facebook', message);
// Update the pre-populated Twitter social share message
growsurf.updateSocialShareMessage('twitter', message);
// Update the pre-populated Threads social share message
growsurf.updateSocialShareMessage('threads', message);
// Update the pre-populated Bluesky social share message
growsurf.updateSocialShareMessage('bluesky', message);
// Update the pre-populated Pinterest social share message
growsurf.updateSocialShareMessage('pinterest', message);
// Update the pre-populated SMS social share message
growsurf.updateSocialShareMessage('sms', message);
// Update the pre-populated WhatsApp social share message
growsurf.updateSocialShareMessage('whatsapp', message);
// Update the pre-populated Reddit social share message
growsurf.updateSocialShareMessage('reddit', message);
// Update the pre-populated Tumblr social share message
growsurf.updateSocialShareMessage('tumblr', message);
const message = "I have saved 1,540 hours using this service. Highly recommend! {{shareUrl}}";
const subjectLine = "Check this out!";
// Update the pre-populated email invite message and subject line
growsurf.updateEmailInviteMessage(message, subjectLine);
growsurf.logout();
growsurf.logout();
growsurf.init(settings);
// Using a Callback
growsurf.init({ email: "[email protected]", hash: "HASH_VALUE" }, () => {
// GrowSurf is Ready
});
// Using a promise
growsurf.init({ email: "[email protected]", hash: "HASH_VALUE" }).then(() => {
// GrowSurf is Ready
});
growsurf.open(callback);
// Using a Callback
growsurf.open(function() {
// Do something here
});
// Using a Promise
growsurf.open().then(() => {
// Do something here
});
<a class="growsurf-open-window">
Refer and Earn
</a>
growsurf.close(callback);
// Using a Callback
growsurf.close(() => {
// Do something here
});
// Using a Promise
growsurf.close().then(() => {
// Do something here
});
growsurf.subscribe(eventType, callback);
/**
* REFERRED FRIEND EVENTS
*/
// Subscribe to a `referral` event type
growsurf.subscribe('referral', (participant) => {
// A new participant was referred
});
// Subscribe to a `referralTrigger` event type
growsurf.subscribe('referralTrigger', (participant) => {
// A referred participant triggered a referral (AKA they completed the qualifying action)
});
/**
* REFERRER EVENTS
*/
// Subscribe to a `signup` event type
growsurf.subscribe('signup', (participant) => {
// A new participant was added (only non-referred signups)
});
// Subscribe to a `share` event type
growsurf.subscribe('share', (data) => {
// A participant shared their unique referral URL by clicking a social share button
});
// Subscribe to an `invite` event type
growsurf.subscribe('invite', (participant) => {
// A participant sent out an invite
});