Learn how to clear Marketo Munchkin cookies on Marketo form submit. This guide provides code snippets and step-by-step instructions to help you prevent unintended tracking and pre-filling of forms.
In this post, we teach you how to clear the Marketo Munchkin cookie after a user submits a Marketo form.
There are a few blog posts and code snippets floating around the web that address this topic, but we wanted to share our learnings after adapting the code for our needs.
Let’s get started! 👇
You can check this post from way back in 2014 that explains what is happening.
“Forms 1.0 contained the value for the Munchkin tracking cookie as a field in the DOM. This was submitted along with all of the other inputs. Forms 2.0 omits this field, and dynamically populates the value upon submission rather than on form load.
While this is generally acceptable, it does create a class of use cases, which require the tracking cookie be cleared to avoid unintended tracking and prefilling.“
Sanford also has a great post that gets into the weeds on what is happening behind the scenes. For most use cases, we’ve found our updated snippet to be highly effective in accomplishing the goal.
Marketo is a marketing automation platform that helps businesses automate and measure marketing engagement, tasks, and workflows.
This part is totally business logic dependent, but there are a few use cases in particular that come to mind.
Referral Programs
Often, users refer new customers using the same Marketo form. This is great for efficiency, but the data often ends up associated with the contact record from the contact submitting the form and not to a new contact record for the referral. Using our script, this solves the problem!
Events Forms
This can occur at a tradeshow or event where a Marketo customer is using the same form on the same device, and getting contact information from multiple people. The form is dynamically populating the old value and thus we need to clear the cookie on form submission.
Here is the code that you need to add to you Marketo form logic. Keep in mind it might be best to target a particular Marketo Form ID so you don’t apply this logic to all forms.
In our case, we only apply the below code on forms 1234 and 1235.
MktoForms2.whenReady(function(form){let formid = form.getFormElem()[0]?.getAttribute("data-formid");if ( 1234 == formid || 1235 == formid ) {form.addHiddenFields({"_mkt_trk": "", "mkt_tok": ""});}form.onSubmit( function(form){let formid = form.getFormElem()[0]?.getAttribute("data-formid");if ( 1234 == formid || 1235 == formid ) {form.vals({"_mkt_trk": "", "mkt_tok": ""});document.cookie = '_mkt_trk=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT;';document.cookie = 'mkt_tok=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT;';}})});
This tutorial is brought to you by Backpack Works. Backpack Works is a full-stack design and development agency that builds pixel-perfect corporate marketing sites, web apps, and mobile apps.
The Backpack team is also the brains behind the React Starter Themes templates. Need any design help for your website, web app, or mobile app? We’ve got you covered.
Simply send us a note via our contact form and we will get back to you with next steps.
Receive the latest and video insights in your inbox.
By clicking the "Subscribe" button, you agree to receive email updates.
Get in touch with us today to jumpstart your marketing machine. We are available for short and long term contracts in addition to our theme customizations.