API Reference

This reference documents the GrowSurf JavaScript SDK, including all available public methods and examples of each.

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.

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 Callback
growsurf.addParticipant('[email protected]', (participant) => {
  // handle participant
});

// Object using a Callback
growsurf.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
});

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.

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.

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.

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).

Example use

Example response

Note: You can verify that the referrer ID is valid by calling growsurf.getParticipantById()


Get participant 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.

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.

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.

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).

Alternatively, you can use growsurf.markNotificationsAsRead() to clear the unread notifications badge.

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: rewards commissions payouts If no type is provided, then all unread notification badges will be initialized.

Example use

CSS Alternative:


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.

Alternatively, you can use the growsurf.initUnreadNotificationsBadge() method for displaying the unread notifications count as a badge on a target element.

Parameter
Data Type
Description

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.

Parameter
Data Type
Description

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 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

Returns a Promise that resolves once complete.

Example use

CSS Alternative:


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


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.

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.

Last updated

Was this helpful?