Web Studio is here! An enhanced experience to make it easier to create, preview, and collaborate on your website contentLearn More
The Hubspot app for Agility helps you to bring your Hubspot Forms into your Agility content.
HubSpot is a full-service platform for marketing, sales, customer service and CRM software. Amongst many other things, you can use HubSpot Forms to start learning more about your visitors.
Your Forms on HubSpot integrate with your contacts database, so you can keep track of your leads and turn them into customers.
To get started with HubSpot, sign up for a Free Account.
When you're logged into HubSpot, create a new Free Form under Marketing.
Choose the Embedded Form Type.
For this example, we'll use the Contact Form template.
We'll want to add our HubSpot form to an Agility CMS powered website. Sign up for a Free Agility CMS Account. Once you have an account, you'll be able to select a starter and create an Instance.
Getting Started with Agility CMS
To allow your app to establish a connection with HubSpot, you need to get your account's access token.
Once the private app is created, you should a View access token link like the screenshot below.
In order to use an App in Agility CMS, you need to install it in your instance. You can do this from the Settings | Apps section.
After Installing the HubSpot App add the HubSpot custom field to a Page Module.
Drag the field type into your Module, add a field label, and save the Module.
Make sure the custom field is highlighted and the HubSpot app is selected under the field
Now that we have created the HubSpot form module we then need to attach it to a page.
Create a new page and hit Add. On the Module Selection panel you should see the HubSpot module we just created.
After adding the new module, click on it and you should be able to see a select box populated with the forms you have on HubSpot.
Once you've installed and applied the app as custom field to your page, you can then use the script below to run a dynamically embedded form from the data sent by your app.
For this example we are using the Agility CMS NextJS starter (https://github.com/agility/agilitycms-nextjs-starter)
Please see the above README on how to consume pages and modules.
Typescript
import React from "react";
import Script from "next/script";
import { ModuleWithInit, } from "@agility/nextjs";
// Typescript
interface IHubspotFormProps{
hubspotForm: string | undefined
}
const HubspotForm: ModuleWithInit<IHubspotFormProps> = ({ module }) => {
const {fields: {hubspotForm}} = module;
if(!hubspotForm) return null;
const {portalId, formId} = JSON.parse(hubspotForm);
const divID = form_${formId};
return (
<div style={{ width: "600px", margin: "auto" }}>
<Script
{...{
type: "text/javascript",
strategy: "lazyOnload",
src: "//js.hsforms.net/forms/embed/v2.js",
onReady: () => {
// @ts-ignore
hbspt.forms.create({
region: "na1",
portalId,
formId,
target: #${divID},
});
},
}}
/>
<div id={divID}></div>
</div>
);
}
Javascript
import React from "react";
import Script from "next/script";
import { ModuleWithInit, } from "@agility/nextjs";
// JSX
const HubspotForm = ({ module }) => {
const {
fields: { hubspotForm = undefined },
} = module;
if (!hubspotForm) return null;
const { portalId, formId } = JSON.parse(hubspotForm);
const divID = form_${formId};
return (
<div style={{ width: "600px", margin: "auto" }}>
<Script
{...{
type: "text/javascript",
strategy: "lazyOnload",
src: "//js.hsforms.net/forms/embed/v2.js",
onReady: () => {
hbspt.forms.create({
region: "na1",
portalId,
formId,
target: #${divID},
});
},
}}
/>
<div id={divID}></div>
</div>
);
};
export default HubspotForm;