Skip to content

Instantly share code, notes, and snippets.

View NickDeckerDevs's full-sized avatar

nicholas decker NickDeckerDevs

View GitHub Profile
@justingivens
justingivens / custom-html.html
Last active August 13, 2025 21:55
HubSpot <> Google Tag Manager Custom Event
<!-- Trigger on pages and customize as needed. -->
<script>
//v4 Forms
window.addEventListener('hs-form-event:on-submission:success', function(event){
const { formId, instanceId } = event.detail;
dataLayer.push({'event':'hubspot-form-submission','hubspot-form-id':formId});
});
//Legacy Forms
window.addEventListener('message', function(event) {

Sometimes, a customer might have data being loaded programmatically into a page and want that data to write to form fields. Because HubSpot Forms are generated programmatically with React, there need to be two considerations in your code that make setting fields programmatically more difficult:

  1. The data must be inserted after the form has finished loading
  2. Data that is inserted programmatically must have a js "change" event fired on the field in order to propagate the change into the React data layer

These two considerations are handled separately.

Inserting form data after form load

There are two methods to handle this - one including jQuery and one using vanilla javascript

@lukebussey
lukebussey / hubspot_schema.html
Last active May 20, 2021 20:36
HubSpot Blog Schema.org Markup
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"@id": "#organization",
"name": "Outlyer",
"url": "https://www.outlyer.com/",
"sameAs": [
"https://github.com/outlyerapp",
"https://twitter.com/outlyer",