Skip to content

Instantly share code, notes, and snippets.

View derekcavaliero's full-sized avatar
🫠

Derek Cavaliero derekcavaliero

🫠
View GitHub Profile
@derekcavaliero
derekcavaliero / slate-custom-form-loader.html
Created May 20, 2025 20:20
Slate Embedded Form Custom Loader
<div id="form_[FORM_ID]">Loading...</div>
<script>
(function(l,o,a,d,e,r){
var formId = "[FORM_ID]";
e=o.createElement(a);e.onload=d(formId);
e.src="https://[SLATE_HOST]/register/?id=" + formId + "&div=form_" + formId + "&output=embed";
r=o.getElementsByTagName(a)[0];r.parentNode.insertBefore(e,r);
})(window, document, 'script', function(formId) {
const targetNode = document.querySelector(`#form_${formId}`);
@derekcavaliero
derekcavaliero / parseGa4SessionId.js
Last active May 13, 2025 19:05
GA4 Session ID Parsing Function
const parseGa4SessionId = (str) => {
let value;
const parts = str.split('.');
const parser = {
v1: (str) => {
let parsed = {};
const data = str.split('.').slice(2);
@derekcavaliero
derekcavaliero / goto.bash
Created April 3, 2025 14:46
Bash `goto` shortcut/alias.
goToFolder() {
local primary_directory="Sites"
# Default base - change to whatever default folder you want to use inside the primary_directory
local base="Level"
local client=""
# Check if argument contains a slash
if [[ "$1" == */* ]]; then
@derekcavaliero
derekcavaliero / hubspot-form-embed-with-custom-css.html
Created February 26, 2025 15:04
HubSpot form Embed with Custom CSS (and no iframe)
<style>
/**
* Start Custom HubSpot form CSS
*/
[data-hs-forms-root] {
--form-col-gap: 0.75rem;
--form-row-gap: 1rem;
--form-input-padding-y: 0.75rem;
--form-input-padding-x: 1rem;
:root {
--font-import-uri: 'https://fonts.googleapis.com/css2?family=Schibsted+Grotesk:ital,wght@0,400..900;1,400..900&display=swap';
--font-family: 'Schibsted Grotesk', sans-serif;
--lvl-pacing-green: #d9ead3;
--lvl-pacing-purple: #d9d2e9;
--lvl-pacing-yellow: #fff2cc;
}
@import url(var(--font-import-uri));
@derekcavaliero
derekcavaliero / hubspot-form-a11y-polyfill.js
Last active June 1, 2025 15:40
HubSpot Embedded Form Accessibility Polyfills
/**
* HubSpot Embedded Form Accessibility Pollyfills
*
* This script fixes the HubSpot HTML blunders that make their embedded forms inaccessible for assistive technology.
* - Replaces/removes improper use of <fieldset>, <legend>, <label>, and role attributes.
* - Note - this can cause forms configured for mulitple column field layouts to break - you will need to adjust your CSS accordingly.
**/
hubspotFormA11y = {
@derekcavaliero
derekcavaliero / hubspot-embedded-video-gtm-datalayer-adapter.js
Last active June 21, 2023 10:44
HubSpot - Embedded Video GTM dataLayer Adapter
/**
* You'll want to add this to GTM using an "All Pages" trigger -
* Note - make sure you set it to only fire "once per-page" to prevent issues with re-registering the listener on SPAs
**/
window.addEventListener('message', function(message){
if (message.origin != 'https://play.hubspotvideo.com') return;
/*
@derekcavaliero
derekcavaliero / gforms-hidden-field-class-markup.php
Created December 10, 2021 21:30
Gravity Forms - Add CSS Class to Hidden Input Using Input Name
<?php
add_filter( 'gform_field_input', function ( $input, $field, $value, $lead_id, $form_id ) {
if ( $field->inputName !== '' && $field->type == 'hidden' ) {
$input = "<input type='hidden' name='input_{$field->id}' class='{$field->inputName}' value='{$value}'>";
}
return $input;
}, 10, 5 );
@derekcavaliero
derekcavaliero / pardot-form-submission-postmessage-event
Last active April 1, 2021 17:02
Push a window.postMessage event to the parent window for iframed Pardot forms. You can then intercept this message via Google Tag Manager (see: X) for an example.
<script>
if ( window.parent.postMessage ) {
window.parent.postMessage({
'event': 'Form Submission', // Never change this
'form_id': '1234', // The Pardot form ID (you can get this from the form edit page URL)
'form_label': '[Whitepaper] - The 2020 State of Digital Accessibility', // This can really be whatever you want.. but make sure its descriptive
'form_action': 'Gated Resource Download' // See suggested Form Actions
}, '*');
}
</script>
@derekcavaliero
derekcavaliero / hubspot-global-form-submit-event-example
Created July 24, 2020 15:09
HubSpot - Global Form Submit Event Example
<script>
(function() {
var dataArrayToObject = function(data) {
var fields = {};
for ( var i = 0; i < data.length; i++ ) {
fields[data[i].name] = data[i].value;
}