Hi,
We’re logging some GA4 events to the dataLayer when a form is submitted using the forms API guide here: https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options
Like so:
window.hbspt.forms.create({
// ...
onFormSubmitted: () => {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
// ...
});
},
});
I noticed though that this is a legacy API, is it therefore deprecated and likely to removed in the future?
If so, is there a replacement for this API, or a suitable method to log events like this? I couldn’t find anything in the newer docs
Thanks
KenF
July 31, 2024, 11:51pm
2
Here’s a link to the latest Forms API v3. Although it says it’s currently in development, it is the most current method to create a form through the Hubspot API.
Example:
const FormDefinitionCreateRequestBase = { formType: "hubspot", name: "string", createdAt: "2024-07-31T23:46:17.606Z", updatedAt: "2024-07-31T23:46:17.606Z", archived: true, archivedAt: "2024-07-31T23:46:17.606Z", fieldGroups: [{"groupType":"default_group","richTextType":"text","richText":"string","fields":[]}], configuration, displayOptions, legalConsentOptions };const apiResponse = await hubspotClient.marketing.forms.formsApi.create(FormDefinitionCreateRequestBase);
Thanks @KenF , I’m not actually trying to create a form though - just set some options when its rendered.
There doesn’t seem to be any equivolent for the article I linked in the new documentation
KenF
August 1, 2024, 5:51pm
4
Ahh I see, you’re right there isn’t anything in the current Forms API that captures the submit event.
Hopefully they will come out with some new Form event handling before they do any deprecation of the legacy Form API.