1.3.5 • Published 11 months ago

eleventy-plugin-hubspot v1.3.5

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

eleventy-plugin-hubspot

npm npm license

An Eleventy shortcode that generates HubSpot forms or Meetings Calendar.

Installation

Install the plugin from npm:

npm install eleventy-plugin-hubspot --save-dev

Add it to your Eleventy Config file:

const eleventyPluginHubspot = require('eleventy-plugin-hubspot');

module.exports = function (eleventyConfig) {
    eleventyConfig.addPlugin(eleventyPluginHubspot, {
        portalId: 1234567
    });
};

Advanced usage:

const eleventyPluginHubspot = require('eleventy-plugin-hubspot');

module.exports = function (eleventyConfig) {
    eleventyConfig.addPlugin(eleventyPluginHubspot, {
        portalId: 1234567,
        locale: "en",
        loadingMode: "default",
        cssRequired: "",
        cssClass: "",
        translations: {
            en: {
                invalidEmail: "Please enter a valid business email."
            },
        },
        onBeforeFormInit: function($form) {
            console.log('onBeforeFormInit formID:', $form.data.id);
        },
        onFormReady: function($form) {
            console.log('onFormReady formID:', $form.data.id);
        },
        onFormSubmit: function($form) {
            console.log('onFormSubmit formID:', $form.data.id);
        },
        onFormSubmitted: function($form) {
            console.log('onFormSubmitted formID:', $form.data.id);
        }
    });
};

What does it do?

The plugin turns 11ty shortcodes like this:

{% hubspotForm "e3595481-9ab1-4d00-a98d-1a96a50058ad" %}

and

{% hubspotMeetings "https://meetings.hubspot.com/alex-zappa" %}

into HTML code like this:

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/embed/v2.js"></script>
<script data-hubspot-rendered="true">hbspt.forms.create({"portalId":1234567,"locale":"en","translations":{"en":{"invalidEmail":"Please enter a valid business email."}},"formId":"e3595481-9ab1-4d00-a98d-1a96a50058ad"});</script>

and

<div class="meetings-iframe-container" data-src="https://meetings.hubspot.com/alex-zappa?embed=true"></div>
<script charset="utf-8" type="text/javascript" src="//static.hsappstatic.net/MeetingsEmbed/ex/MeetingsEmbedCode.js"></script>

Custom Usage

{% hubspotForm "e3595481-9ab1-4d00-a98d-1a96a50058ad", {
    portalId: 1234567,
    locale: "en",
    loadingMode: "lazy",
    cssRequired: "",
    cssClass: ""
} %}

Configuration options

Type legend:

R - (required) This attribute must be provided for the embed code to work properly.
I - (internal) Used internally by a HubSpot tool. Use with caution, as it will likely affect how this form behaves or how the submission data is processed.
O - (optional) Optional form customization attribute intended for use by end-users.
C - (callback) A callback function that will be executed at various points in the form's lifecycle.
AttributeTypesDescription
loadingModeOThe loading mode for the form. Options are default, eager, interact and lazy. Default is default.
loadingSpinnerOShow a loading spinner while the form is loading. Defaults to inline built-in spinner. Could be set to false to disable the spinner, or a custom spinner HTML.
portalIdR, IUser's portal ID
formIdR, IUnique ID of the form you wish to build
targetOjQuery style selector specifying an existing element on the page into which the form will be placed once built. NOTE: If you're including multiple forms on the page, it is strongly recommended that you include a separate, specific target for each form.
redirectUrlO, IURL to which the form will redirect upon a successful form completion. Cannot be used with inlineMessage.
inlineMessageO, IInline message to display in place of the form upon a successful form completion. Cannot be used with redirectUrl.
pageIdO, IID of the landing page on which the form exists. This must be the content ID of a landing page built in HubSpot.
cssRequiredO, ICSS string specific to validation error messages and form styling. Empty string == no style. Note: when setting/declaring this field in the embed code, elements of your form will no longer have default HubSpot styling applied.
cssClassOCSS class that will be applied to the form.
submitButtonClassO, ICSS class that will be applied to the submit input instead of the default .hs-button.primary.large.
errorClassO, ICSS class that will be applied to inputs with validation errors instead of the default .invalid.error.
errorMessageClassO, ICSS class that will be applied to error messages instead of the default .hs-error-msgs.inputs-list.
groupErrorsOShow all errors at once inside a single container. Defaults to true, otherwise only shows the first error for each field.
localeOLocale for the form, used to customize language for form errors and the date picker. See Add internationalized error messages below.
translationsOAn object containing additional translation languages or to override field labels or messages for existing languages. See Customize internationalization below.
manuallyBlockedEmailDomainO, IArray of domains to block in email inputs.
formInstanceIdO, IWhen embedding the same form on the same page twice, provide this Id for each identical form embed. The Id value is arbitrary, so long as it is not the same between forms.
onBeforeFormInitO, CCallback that executes before the form builds, takes form configuration object as single argument: onBeforeFormInit(ctx)
onFormReadyO, CCallback that executes after form is built, placed in the DOM, and validation has been initialized. This is perfect for any logic that needs to execute when the form is on the page. Takes the jQuery form object as the argument: onFormReady($form)
onFormSubmitO, CCallback that executes after form is validated, just before the data is actually sent. This is for any logic that needs to execute during the submit. Any changes will not be validated. Takes the jQuery form object as the argument: onFormSubmit($form). Note: Performing a browser redirect in this callback is not recommended and could prevent the form submission
onFormSubmittedO, CCallback the data is actually sent.This allows you to perform an action when the submission is fully complete, such as displaying a confirmation or thank you message.

Loading modes

  • default - The form will load when the page loads (Like you use HubSpot code directly).
  • eager - The form will load when DOMContentLoaded event is fired.
  • interact - The form will load when the user makes first interaction with the page. (best for performance)
  • lazy - The form will load when it is in the viewport. (check the note below)

Note: if you place HubSpot form below the fold, lazy loading mode may have some effect on the form conversion rate, since HubSpot tracking script and form itself will be not loaded on the page until user scrolls to the form.

Contributing

If you notice an issue, feel free to open an issue.

  1. Fork this repo
  2. Clone git clone git@github.com:reatlat/eleventy-plugin-hubspot.git
  3. Install dependencies npm install
  4. Build npm run build
  5. Serve locally npm run dev

License

The code is available under the MIT license.

May the 4th be with you

1.3.5

11 months ago

1.3.4

11 months ago

1.3.3

11 months ago

1.3.2

11 months ago

1.3.1

11 months ago

1.2.2

11 months ago

1.3.0

11 months ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

2 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago