Explore the functionality of givetly’s JavaScript API designed to enhance your fundraising process.

Notice something off? Want more details? Hard to follow? Give us your feedback

Overview

The JavaScript API is an efficient tool developed for organizations to optimize their fundraising processes and engage more effectively with donors. It consists of two primary methods:

  • Open Checkout: Triggers the checkout based on various events or conditions, with pre-set information such as donation amounts or supporter details.
  • Event Handler Registration: Enables tracking of conversion events within external applications and systems not inherently supported.

Each method, along with its parameters, is outlined in the sections that follow.

Details on each method

Open Checkout Method

Method: Givetly.openCheckout

This method provides the capability for the checkout to open based on multiple triggers or events. This allows for dynamic interaction, such as auto-filling donor details or the donation amount when users reach a specific part of your website or finish engaging with a media piece.

Parameters like supporter details, donation amount, and currency can be pre-filled. Below is the example spread of parameters.

Givetly.openCheckout(campaignId: string, options?: GivetlyOpenCheckoutOptions)

Note: Ensure your installation code is updated to the latest version to utilize the openCheckout method. Organizations onboarding post-September 30, 2024, are exempt from this requirement.

Parameters

ParameterDescriptionExampleType
supporter.firstNameFirst name of the supporter.DawesString
supporter.lastNameLast name of the supporter.CaseString
supporter.emailEmail of the supporter.[email protected]String
donation.amountDonation amount.150Number
donation.currencyDonation currency (ISO 4217 code).USDString
donation.recurringFrequency of the donation.monthlyString
tribute.honoreeName for tribute donation.Mom and DadString
designations.idDonation designation by ID.EHHJ9R36String
customFieldsAdditional tracking fields.notes: VolunteeringString
config.modifyAmountAllow modification of donation amount.trueBoolean
config.modifyDesignationAllow modification of designation.trueBoolean

Example Usage

Givetly.openCheckout("FUNTFERHMEC", {

  donation: {

    amount: 10,

    currency: "EUR",

    recurring: "monthly",

  },

  supporter: {

    firstName: "Emily",

    lastName: "Smith",

    email: "[email protected]",

  },

  tribute: {

    honoree: "Mom and Dad",

  },

  designations: [{ id: "EHHJ9R36" }],

  customFields: {

    test: "value",

    code: "some-code",

    referralSource: "Social Media",

    campaignName: "Spring Fundraiser",

    notes: "This is a recurring donation.",

    preferredContactMethod: "email",

  },

  config: {

    modifyAmount: true,

    modifyDesignation: true,

  },

});

Event Handling

With the JavaScript API, organizations can track and manage conversion events in analytics tools and marketing platforms by utilizing the Event Handler Registration method.

Event Handler Registration Method

Method: Givetly.on

This method is designed to monitor conversion events across external applications. It can be used to capture events triggered from user interaction with the Checkout modal and Campaign Page.

Givetly.on(eventName: string, callback: Function)

Integrate this method with conversion events for tracking and structuring custom triggers through systems like Google Analytics or Tag Manager. Push events to marketing platforms for optimized ad strategies.

Explore further: JavaScript API playground

Events

For the Checkout modal, we track:

  • checkoutOpen
  • checkoutClose
  • donationComplete

For the Campaign Page, we push:

  • checkoutOpen
  • donationComplete

These events and their payloads are detailed further in their respective sections.

checkoutOpen

This event triggers whenever a Checkout modal or Campaign Page is opened.

{

  "customFields": {

    "fiscal_year": "fy2023",

    "form": "DonateNow"

  },

  "livemode": true,

  "campaign": {

    "id": "FUNCPJTZZQR",

    "code": "C-INT-0000",

    "name": "General Donations"

  },

  "utm": {

    "source": "",

    "campaign": "",

    "medium": "",

    "content": "",

    "term": ""

  },

  "element": {

    "id": "XTGWFZFR",

    "type": "Donate Button",

    "name": "Header Nav - Donate"

  }

}

Parameters

ParameterTypeDescription
customfields.[parameters]StringNames and values for any custom fields added to the campaign.
livemodeBooleanIndicates if test mode was not used for the donation.
campaign.idStringUnique campaign ID.
campaign.codeStringThe code assigned to the campaign.
campaign.nameStringThe campaign name.
utm.sourceStringSource parameter if included in the URL that launched Checkout.
utm.campaignStringCampaign parameter if included in the URL that launched Checkout.
utm.mediumStringMedium parameter if included in the URL that launched Checkout.
utm.contentStringContent parameter if included in the URL that launched Checkout.
utm.termStringTerm parameter if included in the URL that launched Checkout.
element.idStringUnique ID of the Elements component used to launch Checkout.
element.typeStringType of Elements component (e.g., Donate Button).
element.nameStringName of the Elements component used to launch Checkout.

checkoutClose

This event triggers every time the Checkout modal is closed, regardless of whether a donation was completed. Supporter information such as name and email is captured even if the checkout is closed before completing a donation.

After a Successful Donation

{

  "customFields": {

    "fiscal_year": "fy2023",

    "form": "DonateNow"

  },

  "livemode": true,

  "campaign": {

    "id": "FUNCPJTZZQR",

    "code": "C-INT-0000",

    "name": "General Donations"

  },

  "utm": {

    "source": "",

    "campaign": "",

    "medium": "",

    "content": "",

    "term": ""

  },

  "element": {

    "id": "XTGWFZFR",

    "type": "Donate Button",

    "name": "Header Nav - Donate"

  },

  "supporter": {

    "id": "SBLQMBBU",

    "email": "[email protected]",

    "firstName": "Caractacus",

    "lastName": "Potts",

    "anonymous": false,

    "mailingListSubscribed": false,

    "employer": null,

    "onBehalfOf": null

  },

  "donation": {

    "id": "DNNLGBJF",

    "paymentMethod": "CreditCard",

    "amount": 25,

    "feesCovered": 1.5,

    "currency": "USD",

    "recurring": false,

    "frequency": "once"

  },

  "designation": {

    "id": "EXVNFMNX",

    "name": "food for the hungry",

    "code": "F-INT-0014"

  },

  "tribute": null,

  "recurring": {

    "id": "RNXGXWWR"

  },

  "comment": null

}

Without a Successful Donation

{

  "customFields": {

    "fiscal_year": "fy2023",

    "form": "DonateNow"

  },

  "livemode": true,

  "campaign": {

    "id": "FUNCPJTZZQR",

    "code": "C-INT-0000",

    "name": "General Donations"

  },

  "utm": {

    "source": "",

    "campaign": "",

    "medium": "",

    "content": "",

    "term": ""

  },

  "element": {

    "id": "XTGWFZFR",

    "type": "Donate Button",

    "name": "Header Nav - Donate"

  },

  "supporter": {

    "id": null,

    "email": "[email protected]",

    "firstName": "Caractacus",

    "lastName": "Potts",

    "anonymous": false,

    "mailingListSubscribed": false,

    "employer": null,

    "onBehalfOf": null

  },

  "donation": null,

  "designation": null,

  "tribute": null,

  "recurring": null,

  "comment": null

}

Parameters

ParameterTypeDescription
customfields.[parameters]StringNames and values for any custom fields added to the campaign.
livemodeBooleanIndicates if test mode was not used for the donation.
campaign.idStringUnique campaign ID.
campaign.codeStringThe code assigned to the campaign.
campaign.nameStringThe campaign name.
utm.sourceStringSource parameter if included in the URL that launched Checkout.
utm.campaignStringCampaign parameter if included in the URL that launched Checkout.
utm.mediumStringMedium parameter if included in the URL that launched Checkout.
utm.contentStringContent parameter if included in the URL that launched Checkout.
utm.termStringTerm parameter if included in the URL that launched Checkout.
element.idStringUnique ID of the Elements component used to launch Checkout.
element.typeStringType of Elements component (e.g., Donate Button).
element.nameStringName of the Elements component used to launch Checkout.
supporter.idStringUnique supporter ID.
supporter.emailStringSupporter’s email address.
supporter.firstNameStringSupporter’s first name.
supporter.lastNameStringSupporter’s last name.
supporter.anonymousBooleanIndicates if the “Donate anonymously” option was selected.
supporter.mailingListSubscribedBooleanIf mailing list is enabled, this shows if the option was selected.
supporter.employerStringIf company matching is enabled and a value is entered, it gets stored, otherwise it is null.
supporter.onBehalfOfStringIf donating on behalf of an organization is enabled and a value is entered, it gets stored, otherwise it is null.
donation.idStringUnique donation ID.
donation.paymentMethodStringPayment method used at checkout (e.g., CreditCard, PayPal).
donation.amountNumberTotal donation amount including transaction fees.
donation.feesCoveredNumberFee amount assessed for the donation.
donation.currencyStringCurrency selected at checkout.
donation.recurringBooleanIndicates if a recurring donation was made.
donation.frequencyStringDonation frequency selected at checkout.
designation.idStringUnique designation ID.
designation.nameStringName of the designation selected at checkout.
designation.codeStringCode of the designation selected at checkout.
tribute.typeBooleanIf tribute feature is enabled, reflects if the option was selected.
commentStringAny comment entered during the checkout process.

donationComplete

This event is triggered when a donation is successfully finalized in Checkout.

{

  "customFields": {

    "fiscal_year": "fy2023",

    "form": "DonateNow",

    "hs_preview": "UvMjiRBY-66781953082"

  },

  "livemode": true,

  "campaign": {

    "id": "FUNCPJTZZQR",

    "code": "C-INT-0000",

    "name": "General Donations"

  },

  "utm": {

    "source": "",

    "campaign": "",

    "medium": "",

    "content": "",

    "term": ""

  },

  "element": {

    "id": "XTGWFZFR",

    "type": "Donate Button",

    "name": "Header Nav - Donate"

  },

  "supporter": {

    "id": "STMNACDG",

    "email": "[email protected]",

    "firstName": "Tulsi",

    "lastName": "Lattimer",

    "anonymous": false,

    "mailingListSubscribed": false,

    "employer": null,

    "onBehalfOf": null

  },

  "donation": {

    "id": "DPPSCTFU",

    "paymentMethod": "CreditCard",

    "amount": 5.6,

    "feesCovered": 0.6,

    "currency": "USD",

    "recurring": false,

    "frequency": "once"

  },

  "designation": {

    "id": "EHHJ9R36",

    "name": "the greatest need",

    "code": "F-INT-0001"

  },

  "tribute": null,

  "recurring": {

    "id": "RNXGXWWR"

  },

  "comment": null

}

Parameters

ParameterTypeDescription
customFields.[parameters]StringAn array containing names and values for any custom fields added to the campaign
livemodeBooleantrue indicates the donation was not made in test mode.
campaign.idStringThe campaign’s unique ID
campaign.codeStringCode assigned to the campaign
campaign.nameStringName of the campaign
utm.sourceStringSource parameter value included in the URL, if any
utm.campaignStringCampaign parameter value included in the URL, if any
utm.mediumStringMedium parameter value included in the URL, if any
utm.contentStringContent parameter value included in the URL, if any
utm.termStringTerm parameter value included in the URL, if any
element.idStringID of the Elements component that triggered Checkout
element.typeStringType of Elements component used (like Donate Button)
element.nameStringName of the Elements component used
supporter.idStringAlphanumeric supporter ID
supporter.emailStringEmail address of the supporter
supporter.firstNameStringFirst name of the supporter
supporter.lastNameStringLast name of the supporter
supporter.anonymousBooleantrue if the “Donate anonymously” option was selected
supporter.mailingListSubscribedBooleantrue if subscribed to mailing list when enabled at Checkout
supporter.employerStringStores entered employer information if company matching is enabled at Checkout, otherwise null
supporter.onBehalfOfStringStores information if donating on behalf of an organization, otherwise null
donation.idStringUnique alphanumeric donation ID
donation.paymentMethodStringPayment method used (e.g., CreditCard, PayPal)
donation.amountNumberTotal donation amount with transaction fees
donation.feesCoveredNumberFees covered by the donation
donation.currencyStringCurrency selected for the donation
donation.recurringBooleantrue if recurring, false for one-time donation
donation.frequencyStringDonation frequency (e.g., once, Monthly, Annual)
designation.idStringDesignation ID, if provided
designation.nameStringName of the designation, if provided
designation.codeStringDesignation code, if provided
tribute.typeBooleanNo assigned value if tribute feature is selected, null otherwise
commentStringComment provided in the Checkout modal or Campaign page, null if not provided

Custom Fields

Custom fields within a Campaign appear in event payloads, as seen in the donationComplete event that can handle custom field values such as fund, appeal, and source.

Givetly.on("donationComplete", function (details) {

  var fund = details.customFields.fund || "";

  var appeal = details.customFields.appeal || "";

  var source = details.customFields.source || "";

});

Debugging and Testing

To test or debug events, use your browser’s console to log parameters of the checkoutOpen event:

Givetly.on("checkoutOpen", function (details) {

  console.log(details);

});

Platform Guides

Learn to integrate the JavaScript API with various platforms.

Analytics

Monitor Checkout events and develop custom triggers for analytics purposes.

Marketing

Utilize Checkout event data in marketing pixels for audience targeting and ad campaigns.

Found a mistake? Missing something? Hard to grasp? Share your insights with us.