Keeping the Marketo forms Referrer value (_mktoReferrer) updated on SPAs

Level 10 - Community Moderator
Level 10 - Community Moderator

You may not have noticed this in your travels, but the _mktoReferrer hidden field is cached when forms2.min.js is loaded — before forms themselves are loaded — and all forms use that cached value.


The _mktoReferrer becomes the important Referrer constraint in Smart Lists. That’s how we know the page someone was on when they submitted an embedded form.


For a multi-page site — I’d guess 85%+ of corporate brochure sites are multi-page, not sure though! — caching is fine, because a new main document loads when you navigate. Thus forms2.min.js reloads and reads the new document.location.href.


But single-page applications (SPAs), by definition, change content and update the Location bar without loading a new document. In this case, forms2.min.js will not load again.


With an SPA, the displayed and business-logical URL can change from to to but the Referrer for all forms will be This can affect attribution efforts, although of course it doesn’t affect UTM params or any custom tracking fields.


(It’s confusing to troubleshoot, too. If someone clicks the browser’s reload ⟳ button when on, that becomes the new main document and the Referrer changes accordingly. That’s how you get reports like “It randomly doesn’t work” when it’s not random, except in the sense that across a wide audience, end users do fundamentally different things!)


Get the code

It’s easily fixed with a little JS:

   const nativeGetValues = readyForm.getValues;
      submittingForm.getValues = function(){
         const values = nativeGetValues();
         Object.defineProperty(values, "_mktoReferrer", { value: document.location.href, enumerable: true });
         return values;