API Reference
This reference documents the GrowSurf JavaScript SDK, including all available public methods and examples of each.
Use this page to look up individual GrowSurf JavaScript SDK methods. All asynchronous methods support both callback and Promise styles unless otherwise noted.
SDK LIFECYCLE ↓
Initialize / Reinitialize GrowSurf
Initializes or reinitializes the window.growsurf Object.
growsurf.init(settings);Example use
// Using a Callback
growsurf.init({ email: "participant@email.com", hash: "HASH_VALUE" }, () => {
// GrowSurf is Ready
});// Using a promise
growsurf.init({ email: "participant@email.com", hash: "HASH_VALUE" }).then(() => {
// GrowSurf is Ready
});settings
Object
(Optional) The settings GrowSurf should use when initializing or reinitializing.
campaignId- Provide this to initialize another programemail- 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).language- The language code to show your program in, such ases(only applies if the language is turned on in Options > Languages). While it is set, participants cannot change their language on the page. Learn more.
Get participant ID
Returns the ID of the authenticated participant or null if there is no participant authentication cookie present.
Example use
Example response
Log out
Logs the participant out of the browser (clears the participant's GrowSurf browser cookie and local storage).
Example use
CAMPAIGNS ↓
Get campaign
Retrieves limited details of your program.
callback
Function
(Optional) A callback function that will be invoked with the program data.
Returns a Promise that resolves with an Objectcontaining limited program data of id and rewards.
Example use
Example response
GROWSURF WINDOW ↓
Open GrowSurf window
Opens the GrowSurf window.
Parameter
Data Type
Description
callback
Function
(Optional) A callback function that will be invoked once complete
Returns a Promise that resolves once complete.
Example use
Close GrowSurf window
Closes the GrowSurf window.
Parameter
Data Type
Description
callback
Function
(Optional) A callback function that will be invoked once complete
Returns a Promise that resolves once complete.
Example use
REFERRERS ↓
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 use
Example response
Validate referrer
Checks whether a referrer (participant) exists in the program. Returns true if the referrer exists, false otherwise. Unlike getParticipantById(), this method needs no participant authentication and returns no participant data.
referrerId
String
(Optional) The GrowSurf referrer ID to validate. If omitted, the referrer ID is automatically resolved from the grsf URL parameter or browser cookie.
callback
Function
(Optional) A callback function that will be invoked with true if the referrer exists or false if the referrer does not exist.
Returns a Promise that resolves with a Boolean. Returns true if the referrer exists as a participant in the program, false otherwise.
Example use
Example response
PARTICIPANTS ↓
Add referred participant
Adds a participant only when the current visitor has a valid referrer. Use this method when you want to track referred signups.
GrowSurf uses signed visit receipts to apply the program’s first-click or last-click setting. If no usable receipt is available, it validates the explicit referredBy value or the referrer ID from the grsf URL parameter or browser cookie. If no valid referral can be verified, no participant is added (see notAddedReason).
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, referredBy is optional and replaces the automatically detected code. A verified visit receipt can take precedence according to the program’s attribution setting. Any Object keys other than email, firstName, lastName, referredBy, referredAt, and gdprAgreements will be treated as metadata by GrowSurf.
callback
Function
(Optional) A callback function that will be invoked with the result.
Returns a Promise that resolves with a result object.
Example use
Example response
If no participant is added, notAddedReason will be one of no_referrer, invalid_referrer, or participant_already_exists.
Add participant
Adds a participant to the referral/affiliate program. Use this method for the following use-cases:
Add every signup to your GrowSurf program. If a referral link was used, GrowSurf automatically submits the referrer ID behind the scenes.
Generate referral links for your signed-in users on the fly (or return existing data if they are an existing participant)
For referral-only signup tracking, use growsurf.addReferredParticipant() instead.
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 Objectcontaining limited participant data.
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.
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 Objectcontaining the participant data. If the participant does not exist in the program, 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.
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 Objectcontaining the participant data. If the participant does not exist in the program, then undefined is returned.
Example use
Example response
REFERRALS AND INVITES ↓
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.
type
String
(Required) The social share type to update.
These are the options:
emailfacebooktwitterthreadsblueskypinterestsmswhatsappreddittumblr
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).
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
REFERRAL PROGRAMS ↓
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.
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 program 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 Objectcontaining limited participant data.
Example use
Example response
Get upfront discount
Referral programs only
Use this method when you want to apply an upfront discount to a referred friend (e.g., "Get 20% off your first invoice").
Returns the upfront discount promotion code and coupon ID for the current referred visitor. Returns null if the visitor was not referred, if no upfront discount is enabled, or if the program has ended.
integrationType
String
(Optional) One of 'stripe', 'chargebee', or 'recurly'. If omitted, returns the first available upfront discount across all integrations.
Returns an Object or null.
Example use
Example response
Get referral summary
Referral programs only
Returns referral summary statistics for the currently logged-in participant.
Returns a Promise that resolves with an Object containing the participant's referral summary stats.
Example use
Example response
AFFILIATE PROGRAMS ↓
Get commissions
Affiliate programs only
Returns a paginated list of commissions for the logged-in participant.
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 Objectcontaining limited commissions data.
Example use
Example response
Get payouts
Affiliate programs only
Returns a paginated list of payouts for the logged-in participant.
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 Objectcontaining limited payouts data.
Example use
Example response
Once a payout has been paid, it includes a paymentMethod showing how it was sent: PAYPAL, WISE, ACH, WIRE, CHECK, GIFT_CARD, CARD, WALLET, or OTHER. Payouts that have not been paid yet return paymentMethod: null.
Get affiliate summary
Affiliate programs only
Returns affiliate summary statistics for the currently logged-in participant.
Returns a Promise that resolves with an Objectcontaining the participant's affiliate summary stats.
Example use
Example response
NOTIFICATIONS ↓
Initialize unread notifications badge
This method will inject an unread notifications badge onto a 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.
targetElement
String
(Required) The target element
Example: .my-button
type
String
(Optional) Available options:
rewards
commissions
payouts
If no type is provided, then all unread notification badges will be initialized.
Example use
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.
type
String
(Optional) Available options:
rewards
commissions
payouts
If no type is provided, then all unread notification counts will be returned.
Example use
Example response
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.
type
String
(Optional) Available options:
rewards
commissions
payouts
If no type is provided, then all unread notifications will be marked as read.
Returns a Promise that resolves with an Objectwith a success response.
Example use
Example response
EVENTS ↓
Subscribe to event
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.
eventType
String
(Required) The event type to subscribe to.
These are the options:
referralreferralTriggersignupshareinvite
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 program 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.
Last updated
Was this helpful?

