API Reference

Add participant

Adds a participant to the referral campaign.

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.

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, and lastName will be treated as metadata by GrowSurf.

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

Using Callbacks
Using Promises
// Email only using a Callback
growsurf.addParticipant('gavin@hooli.com', function(participant) {
// handle participant
});
// Object using a Callback
growsurf.addParticipant({
email: 'gavin@hooli.com',
firstName: 'Gavin',
lastName: 'Belson',
company: 'Hooli, Inc',
companySize: 10000
}, function(participant) {
// handle participant
});
// Email only using a Promise
growsurf.addParticipant('gavin@hooli.com').then(participant => {
// handle participant
});
// Object using a Promise
growsurf.addParticipant({
email: 'gavin@hooli.com',
firstName: 'Gavin',
lastName: 'Belson',
company: 'Hooli, Inc',
companySize: 10000
}).then(participant => {
// handle participant
});

Example response

{
"id": "kafewp",
"firstName": "Gavin",
"lastName": "Belson",
"referralCount": 0,
"shareUrl": "https://piedpiper.com?grsf=kafewp",
"rewards": []
}

Trigger referral

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.

growsurf.triggerReferral(data, callback)

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

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

Using Callbacks
Using Promises
// Email only using a Callback
growsurf.triggerReferral('gavin@hooli.com', function(participant) {
// handle participant
});
// Object using a Callback
growsurf.triggerReferral({
email: 'gavin@hooli.com',
firstName: 'Gavin',
lastName: 'Belson',
company: 'Hooli, Inc',
companySize: 10000
}, function(participant) {
// handle participant
});
// Email only using a Promise
growsurf.triggerReferral('gavin@hooli.com').then(participant => {
// handle participant
});
// Object using a Promise
growsurf.triggerReferral({
email: 'gavin@hooli.com',
firstName: 'Gavin',
lastName: 'Belson',
company: 'Hooli, Inc',
companySize: 10000
}).then(participant => {
// handle participant
});

Example response

{
"id": "kafewp",
"firstName": "Gavin",
"lastName": "Belson",
"referralCount": 0,
"shareUrl": "https://piedpiper.com?grsf=kafewp",
"rewards": []
}

Get campaign

Retrieves limited details of a campaign.

growsurf.getCampaign(callback)

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.

Example use

Using Callbacks
Using Promises
// Using a Callback
growsurf.getCampaign(function(campaign) {
// Handle Campaign
});
// Using a Promise
growsurf.getCampaign().then(campaign => {
// Handle Campaign
});

Example response

{
id: "bpsxg4",
name: "Middle-Out Compression Campaign",
participantCount: 41
}

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 campaign has participant authentication enabled, (2) there is no authentication cookie present on the participant's browser.

growsurf.getParticipantByEmail(participantEmail, callback)

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

Using Callbacks
Using Promises
// Using a callback
growsurf.getParticipantByEmail('gavin@hooli.com', function(participant) {
// Handle participant data
});
// Using a promise
growsurf.getParticipantByEmail('gavin@hooli.com').then(participant => {
// Handle participant data
});

Example response

{
"id": "kafewp",
"firstName": "Gavin",
"lastName": "Belson",
"referralCount": 0,
"shareUrl": "https://piedpiper.com?grsf=kafewp",
"rewards": []
}

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 campaign has participant authentication enabled, (2) there is no authentication cookie present on the participant's browser.

growsurf.getParticipantById(participantId, callback)

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

Using Callbacks
Using Promises
// Using a Callback
growsurf.getParticipantById('kafewp', function(participant) {
// Handle participant data
});
// Using a promise
growsurf.getParticipantById('kafewp').then(participant => {
// Handle participant data
});

Example response

{
"id": "kafewp",
"firstName": "Gavin",
"lastName": "Belson",
"referralCount": 0,
"shareUrl": "https://piedpiper.com?grsf=kafewp",
"rewards": []
}

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

growsurf.getReferrerId()

Example use

growsurf.getReferrerId();

Example response

"1h97da"

Open GrowSurf window

Opens the GrowSurf window.

growsurf.open(callback)

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

Using Callbacks
Using Promises
// Using a Callback
growsurf.open(function() {
// Do something here
});
// Using a Promise
growsurf.open().then(() => {
// Do something here
});

Close GrowSurf window

Closes the GrowSurf window.

growsurf.close(callback)

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

Using Callbacks
Using Promises
// Using a Callback
growsurf.close(function() {
// Do something here
});
// Using a Promise
growsurf.close().then(() => {
// Do something here
});

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.

growsurf.subscribe(eventType, callback)

Parameter

Data Type

Description

eventType

String

(Required) The event type to subscribe to.

These are the options:

  • signup

  • share

  • referral

callback

Function

The callback function that will be invoked when the event occurs.

Returns a Promise that resolves once complete.

Example use

Using Callbacks
Using Promises
// Using Callbacks
// Subscribe to a `signup` event type
growsurf.subscribe('signup', function(participant) {
// A participant was added
});
// Subscribe to a `share` event type
growsurf.subscribe('share', function(data) {
// A participant shared their unique referral url
});
// Subscribe to a `referral` event type
growsurf.subscribe('referral', function(participant) {
// A participant was referred
});
// Using Promises
// Subscribe to a `signup` event type
growsurf.subscribe('signup').then(participant => {
// A participant was added
});
// Subscribe to a `share` event type
growsurf.subscribe('share').then(data => {
// A participant shared their unique referral url
});
// Subscribe to a `referral` event type
growsurf.subscribe('referral').then(participant => {
// A participant was referred
});

Example response

Dispatched anytime a new participant is added to the campaign. The provided callback will be invoked with an Object containing the added participant data once the participant has been added successfully.

'signup' Event
'share'
'referral' Event
{
"id": "kafewp",
"firstName": "Gavin",
"lastName": "Belson",
"referralCount": 0,
"shareUrl": "https://piedpiper.com?grsf=kafewp",
"rewards": []
}
{
"participant": {
"id": "kafewp",
"firstName": "Gavin",
"lastName": "Belson",
"referralCount": 0,
"shareUrl": "https://piedpiper.com?grsf=kafewp",
"rewards": []
},
"type": "facebook"
}
{
"id": "kafewp",
"firstName": "Gavin",
"lastName": "Belson",
"referralCount": 0,
"shareUrl": "https://piedpiper.com?grsf=kafewp",
"rewards": []
}