API Reference
This reference documents the GrowSurf JavaScript Web API, including all available public methods and examples of each.
Last updated
This reference documents the GrowSurf JavaScript Web API, including all available public methods and examples of each.
Last updated
Adds a participant to the referral campaign. Use this method for the following use-cases:
Add referral tracking to your current signup form (GrowSurf uses cookies to detect if a referral link was used)
Generate referral links for your signed-in users on the fly (or return existing data if they are an existing participant)
Note: A 401
error will be returned if the following conditions are met: (1) the campaign 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.
Returns a Promise that resolves with an Object containing limited participant data.
Triggers a referral, awarding referral credit to the referrer of an existing or new participant. If the campaign 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 campaign 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.
Returns a Promise that resolves with an Object containing limited participant data.
Retrieves limited details of a campaign.
Returns a Promise that resolves with an Object containing limited campaign data.
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 campaign 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 the participant data. If the participant does not exist in the campaign, then undefined
is returned.
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 campaign 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 the participant data. If the participant does not exist in the campaign, then undefined
is returned.
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 program from your website. Calling this method will return aj7auu1
(which is the participant ID).
Example response
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.
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.
Logs the participant out of the browser (clear's the participant's GrowSurf browser cookie and local storage).
Initializes or reinitializes the window.growsurf
Object.
The method is useful if you have set participant authentication as required for your campaign and you would like to automatically authenticate your participants after they log in.
Example use
Opens the GrowSurf window.
Returns a Promise that resolves once complete.
Closes the GrowSurf window.
Returns a Promise that resolves 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.
Dispatched anytime an event happens. The provided callback will be invoked with an Object containing data relevant to the event.
The 'signup' Event returns limited data of the newly added participant.
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
, and lastName
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.
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.
Parameter
Data Type
Description
callback
Function
(Optional) A callback function that will be invoked with the campaign data.
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.
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.
Parameter
Data Type
Description
type
String
(Required) The social share type to update.
These are the options:
email
facebook
twitter
threads
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.
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.
Parameter
Data Type
Description
settings
Object
(Optional) The settings GrowSurf should use when initializing or reinitializing.
campaignId
- Provide this to initialize another campaign
email
- The email of the participant you wish to auto authenticate (only applies if authentication is enabled for your campaign).
hash
- The hash token generated by your server. Used to auto authenticate a participant (only applies if authentication is enabled for your campaign).
Parameter
Data Type
Description
callback
Function
(Optional) A callback function that will be invoked once complete
Parameter
Data Type
Description
callback
Function
(Optional) A callback function that will be invoked once complete
Parameter
Data Type
Description
eventType
String
(Required) The event type to subscribe to.
These are the options:
signup
share
referral
invite
callback
Function
The callback function that will be invoked when the event occurs.