Squarespace
Squarespace Form Blocks build their submission from internal state, so values written into the page's inputs never reach the submission. What the Form Block does send, when the visitor clicks the button, is one request carrying every field. So the install is two scripts: the tag, plus a small companion that writes the attribution into that request's Hidden fields as it goes out — no URL parameters and no reload.
Add the tag to your site
In Squarespace, open Settings → Advanced → Code Injection (on newer plans: Settings → Developer Tools → Code Injection), paste the loader into Header, and save.
<script src="https://attr.boggsmtk.com/v1/tag.js?k=YOUR_LICENSE_KEY"></script>
Swap YOUR_LICENSE_KEYfor the client's key from the dashboard. Code Injection requires a plan with code injection enabled (Business or higher).
Put it in the <head> directly, not in Google Tag Manager. When GTM is blocked — an ad blocker, a privacy browser, a consent banner the visitor never accepts — nothing inside the container fires, and a tag that lives in GTM never loads. That lead arrives with empty attribution fields. Loaded straight from the <head>, the tag runs whether or not GTM does. A GTM Custom HTML tag on all pages still works if the <head> is genuinely off-limits, but treat it as the fallback, and expect to lose the leads whose browser blocks the container.
Add the companion script
On the same Code Injection screen, paste this into Footer and save. Nothing to configure: it fills whichever Hidden fields you add, from whatever the tag resolves, so a field the platform gains later needs no edit here. To keep a value off Squarespace, list it in EXCLUDE.
<!-- MTK Attribution Squarespace Companion Script -->
<script>
(function () {
// Installed twice (Code Injection plus a page header) would wrap the
// request twice; once is enough.
if (window.mtkSquarespaceCompanion) return;
window.mtkSquarespaceCompanion = 2;
// Values to keep OUT. The first two are long enough to crowd a URL past
// its ceiling on their own, and everything inside them already rides
// along in the individual fields. Add any field you don't want on the
// platform — each one you drop frees room for the rest.
var EXCLUDE = [
'mtk_journey_json',
'mtk_attribution_summary',
// Squarespace rejects the submit once this value carries a long journey ("Review the following information: Journey String").
'mtk_journey_string'
];
// Only when the platform's key has to differ from the field name.
var RENAME = {
// 'mtk_first_channel': 'first_channel'
};
// The tag also publishes each value under its retired spelling so older
// client forms keep filling. That is for forms, not for us — carrying both
// would double the payload for nothing.
var LEGACY_PREFIXES = ['mtk_ft_', 'mtk_lt_'];
var LEGACY_NAMES = [
'mtk_time_since_paid',
'mtk_conversion_timestamp',
'mtk_summary',
'mtk_touch_path',
'mtk_touch_path_json'
];
// Titles the generic rule can't produce (click IDs stay lowercase).
var TITLE_EXCEPTIONS = {"mtk_gclid":"gclid","mtk_gbraid":"gbraid","mtk_wbraid":"wbraid","mtk_msclkid":"msclkid","mtk_page_url":"Page URL","mtk_os":"OS","mtk_fbclid":"fbclid","mtk_fbc":"fbc","mtk_fbp":"fbp"};
function isLegacy(key) {
for (var i = 0; i < LEGACY_PREFIXES.length; i++) {
if (key.indexOf(LEGACY_PREFIXES[i]) === 0) return true;
}
return LEGACY_NAMES.indexOf(key) > -1;
}
// 'mtk_first_channel' -> 'First Channel', matching the Field Name the
// dashboard shows for that row.
function titleOf(key) {
if (TITLE_EXCEPTIONS[key]) return TITLE_EXCEPTIONS[key];
var words = key.replace(/^mtk_/, '').split('_');
var out = [];
for (var i = 0; i < words.length; i++) {
if (!words[i]) continue;
out.push(
words[i] === 'json'
? 'JSON'
: words[i].charAt(0).toUpperCase() + words[i].slice(1)
);
}
return out.join(' ');
}
// Order values are added in, which on a length-capped platform is also
// drop priority: what a lead is worth least without goes last. Anything
// not listed (a custom field, a new default) sorts after these, so a drop
// is predictable rather than whatever order the event happened to be in.
var PRIORITY = [
'mtk_last_channel', 'mtk_last_source', 'mtk_last_medium', 'mtk_last_campaign',
'mtk_gclid', 'mtk_gbraid', 'mtk_wbraid', 'mtk_msclkid',
'mtk_first_channel', 'mtk_first_source', 'mtk_first_medium', 'mtk_first_campaign',
'mtk_page_path', 'mtk_page_url',
'mtk_conversion_unix', 'mtk_conversion_datetime', 'mtk_custom_conversion_time',
'mtk_fbclid', 'mtk_fbc', 'mtk_fbp',
'mtk_last_landing_page', 'mtk_last_landing_page_group', 'mtk_first_landing_page',
'mtk_session_count', 'mtk_pageview_count', 'mtk_paid_touch_count',
'mtk_last_paid_touch', 'mtk_time_since_last_paid_touch', 'mtk_time_to_conversion',
'mtk_journey_string',
'mtk_browser', 'mtk_os', 'mtk_device'
];
// Every mtk_* value the event carries, minus the excluded and the retired.
function keysFrom(data) {
var out = [];
for (var key in data) {
if (!data.hasOwnProperty(key)) continue;
if (key.indexOf('mtk_') !== 0) continue;
if (isLegacy(key)) continue;
if (EXCLUDE.indexOf(key) > -1) continue;
out.push(key);
}
out.sort(function (a, b) {
var ia = PRIORITY.indexOf(a), ib = PRIORITY.indexOf(b);
if (ia === -1 && ib === -1) return a < b ? -1 : a > b ? 1 : 0;
if (ia === -1) return 1;
if (ib === -1) return -1;
return ia - ib;
});
return out;
}
// Longest value written into one field. Squarespace refuses the whole
// submission when a Hidden field is too long, so a runaway value is cut
// here instead of costing the lead. Normal values (click IDs, UTMs, a
// landing query) stay far below it.
var MAX_LENGTH = 500;
// The current attribution: resolved live by the tag (conversion time,
// tracking health), or its page-load dataLayer event on an older tag.
function attributionData() {
try {
if (typeof window.mtkValues === 'function') return window.mtkValues();
} catch (e) { /* fall back to the event */ }
var dl = window.dataLayer || [];
for (var i = dl.length - 1; i >= 0; i--) {
if (dl[i] && dl[i].event === 'mtk_attribution') return dl[i];
}
return null;
}
// Squarespace's name for a Hidden field: SQF_ + its Field Name,
// uppercased with spaces as underscores. Used to match fields to values.
function sqfName(title) {
return 'SQF_' + String(title).toUpperCase().replace(/ /g, '_');
}
// SQF_ name -> the attribution key that fills it. Readable titles from
// keysFrom() (so EXCLUDE and RENAME apply), plus every raw mtk_ key the
// tag published, so a field titled with the raw or retired name
// (mtk_first_source, mtk_ft_source) fills too.
function fieldKeys(data) {
var map = {};
for (var k in data) {
if (!data.hasOwnProperty(k) || k.indexOf('mtk_') !== 0) continue;
if (EXCLUDE.indexOf(k) > -1) continue;
map[sqfName(k)] = k;
}
var keys = keysFrom(data);
for (var i = 0; i < keys.length; i++) map[sqfName(RENAME[keys[i]] || titleOf(keys[i]))] = keys[i];
return map;
}
function valueOf(data, key) {
var v = data[key] === null || data[key] === undefined ? '' : String(data[key]);
return v.length > MAX_LENGTH ? v.slice(0, MAX_LENGTH) : v;
}
// The Hidden fields of every Form Block on the page, from Squarespace's
// own form definitions — so a form inside a lightbox counts before it
// opens. Optionally just the form with the given id.
function hiddenFields(formId) {
var out = [];
var defs = document.querySelectorAll('script[id^="form-context-"]');
for (var i = 0; i < defs.length; i++) {
var def;
try { def = JSON.parse(defs[i].textContent); } catch (e) { continue; }
if (!def || !def.formFields) continue;
if (formId && def.formId !== formId) continue;
for (var j = 0; j < def.formFields.length; j++) {
var f = def.formFields[j];
if (!f || f.type !== 'hidden' || !f.id) continue;
out.push({ id: f.id, sqf: f.key || sqfName(f.title || '') });
}
}
return out;
}
// Writes the current attribution into a submission body. Returns the
// body unchanged whenever anything about it is unexpected.
function rewrite(body) {
try {
var outer = JSON.parse(body);
if (!outer || typeof outer.form !== 'string' || !outer.formId) return body;
var form = JSON.parse(outer.form);
var fields = hiddenFields(outer.formId);
var data = attributionData();
if (!fields.length || !data) return body;
var keys = fieldKeys(data);
var wrote = 0;
for (var i = 0; i < fields.length; i++) {
var key = keys[fields[i].sqf];
if (!key) continue; // not an attribution field: leave it be
form[fields[i].id] = valueOf(data, key);
wrote++;
}
if (!wrote) return body;
outer.form = JSON.stringify(form);
return JSON.stringify(outer);
} catch (e) {
return body;
}
}
var SUBMIT_URL = /\/api\/form\/SaveFormSubmission/;
// Squarespace sends the submission with XMLHttpRequest today.
var xhrOpen = XMLHttpRequest.prototype.open;
var xhrSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.open = function (method, url) {
this.mtkSubmit = SUBMIT_URL.test(String(url || ''));
return xhrOpen.apply(this, arguments);
};
XMLHttpRequest.prototype.send = function (body) {
if (this.mtkSubmit && typeof body === 'string') body = rewrite(body);
return xhrSend.call(this, body);
};
// And with fetch, should Squarespace switch to it.
if (typeof window.fetch === 'function') {
var nativeFetch = window.fetch;
window.fetch = function (input, init) {
try {
var url = typeof input === 'string' ? input : (input && input.url) || '';
if (SUBMIT_URL.test(String(url)) && init && typeof init.body === 'string') {
var copy = {};
for (var k in init) if (init.hasOwnProperty(k)) copy[k] = init[k];
copy.body = rewrite(init.body);
return nativeFetch.call(this, input, copy);
}
} catch (e) { /* send it untouched */ }
return nativeFetch.apply(this, arguments);
};
}
// The address the earlier version reloaded to carried every value as an
// SQF_ parameter, stamped mtk_sqf, and browsers remember it. Arriving on
// one, drop those parameters so they never reach a copied link or
// analytics; the submission gets this visitor's values regardless.
(function cleanRememberedUrl() {
if (!/[?&]mtk_sqf=/.test(window.location.search)) return;
var parts = window.location.search.replace(/^\?/, '').split('&');
var kept = [];
for (var i = 0; i < parts.length; i++) {
var name = parts[i].split('=')[0];
if (!parts[i] || name === 'mtk_sqf' || /^SQF_/i.test(name)) continue;
kept.push(parts[i]);
}
if (window.history && history.replaceState) {
history.replaceState(history.state, '', window.location.pathname +
(kept.length ? '?' + kept.join('&') : '') + window.location.hash);
}
})();
// Also shows the values in the rendered Hidden inputs, so DevTools and the
// MTK extension display what will be sent. Squarespace ignores these —
// the submission above is what counts.
// Returns how many inputs it filled, so the wait below can tell "no data
// yet" and "form not rendered yet" from done.
function mirror() {
var data = attributionData();
if (!data) return 0;
var keys = fieldKeys(data);
var inputs = document.querySelectorAll('form input[type="hidden"][name^="SQF_"]');
var filled = 0;
for (var i = 0; i < inputs.length; i++) {
var key = keys[inputs[i].name];
if (!key) continue;
inputs[i].value = valueOf(data, key);
filled++;
}
return filled;
}
// The Form Block renders, then React hydrates and re-renders it after
// this script runs, resetting the inputs — so re-apply for the first
// ~20s rather than stopping at the first success. Pages without a Form
// Block that has Hidden fields skip this entirely.
if (hiddenFields().length) {
var passes = 0;
var timer = setInterval(function () {
mirror();
if (++passes >= 40) clearInterval(timer);
}, 500);
}
// A lightbox form renders its inputs only when it opens.
document.addEventListener('focusin', function (e) {
if (e.target && e.target.form) mirror();
}, true);
})();
</script>
<!-- End MTK Attribution Squarespace Companion Script -->When the visitor clicks Send, it reads the attribution the tag resolves at that moment — so conversion time, time to conversion and tracking health describe the submission, not the page load — and writes each value into the matching Hidden field of the request the Form Block is sending. Fields that aren't attribution fields are never touched. Each value is capped at 500 characters, because Squarespace refuses the whole submission over one overlong Hidden field. The values also show in the page's hidden inputs, so DevTools and the MTK extension display what will be sent.
Keep it in Code Injection, not GTM.The companion is ES5-safe and would run as a GTM Custom HTML tag, but it depends on the tag's data, and moving either script into GTM means a blocked container loses both. Code Injection loads on every Squarespace page regardless of what happens to GTM.
Edit Form Fields and add a Hidden field
Edit the page with your form, click the Form Block, then open Edit Form Fields and add a Hidden field. Name it exactly the Field Name from your field map (e.g. Last Channel) — that name is how Squarespace connects the field to the companion's URL parameter (Last Channel → SQF_LAST_CHANNEL), so it has to match character-for-character (capitals and spaces aside). Leave the field's value empty — the companion fills it on send. Don't paste [mtk:…] tokens as the value: Squarespace never replaces them, and any visitor whose ad blocker stops the tag submits the literal token text into your lead record. An empty field fails clean.
Repeat for each field, then save
Add one hidden field per value you want to capture, each named to its Field Name exactly as the field map shows it — that name is how the companion finds the field. Then save the form and the page.
?utm_source=googleads&utm_medium=cpc, submit, and check the values in the form's storage or notification email.SQF_…URL parameters and reloaded the page. Browsers remembered that address, and a visitor who later opened it before their journey was stored banked the whole thing as their First Query — long enough that Squarespace refused the form (“Form submission failed. Review the following information: First Query”). Replace the Footer script with the one above; the hidden fields stay exactly as they are. It also cleans those parameters off a remembered address on arrival, and the tag (v7.3 and later) repairs any First Query already stored that way.Attribution Summary and Journey String— Squarespace rejects the submit once either carries a long value (“Form submission failed. Review the following information: Journey String”), and a journey string grows with every session. And Journey JSON, which is longer still. The companion above already excludes all three, so don't add hidden fields for them. Everything they contain already arrives through the individual fields: first and last touch, Session Count, Last Paid Touch, and Paid Touch Count.SQF_parameters, which costs an extra pageview and leaves those addresses in browser history — and where both fill the same field, the companion's value overwrites it on send anyway.mtk_attribution event in window.dataLayer means the tag itself was blocked (usually an ad blocker). window.mtkSquarespaceCompanion undefined means the companion is missing; a page that still reloads with SQF_parameters means it is the old version — re-paste the current script from this page. With both in place, the form's hidden inputs show their values a moment after load; one that stays empty means that field's name doesn't match its Field Name. To see exactly what was sent, open the Network tab, submit, and check the SaveFormSubmission request. If every hidden field arrives empty while the inputs show values, Squarespace has changed how its forms send — the lead still arrives, and the companion needs an update.