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 14, 2024 13:29
HubSpot <> Google Tag Manager Custom Event
//Trigger on pages and customize as needed.
<script>
window.addEventListener('message', function(event) {
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady') {
dataLayer.push({'event':'hubspot-form-ready','hubspot-form-id':event.data.id});
}
//Form Submission #1
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {
dataLayer.push({'event':'hubspot-form-submission','hubspot-form-id':event.data.id});

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

@ianhoyte
ianhoyte / blog-pagination.html
Last active November 22, 2021 22:21
Better HubSpot Pagination. This pagination snippet has been taken and modified from Jason Rosa's "Numbered Blog Pagination" snippet: https://designers.hubspot.com/code-gallery/entry/us/dontgojasonwaterfalls-blog-numbered-pagination
{% if contents.total_page_count > 1 %}
<div class="blog-pagination">
{% set page_list = [-2, -1, 0, 1, 2] %}
{% if contents.total_page_count - current_page_num == 1 %}{% set offset = -1 %}
{% elif contents.total_page_count - current_page_num == 0 %}{% set offset = -2 %}
{% elif current_page_num == 2 %}{% set offset = 1 %}
{% elif current_page_num == 1 %}{% set offset = 2 %}
{% else %}{% set offset = 0 %}{% endif %}
@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",