36

Marketo Form Listener for Google Tag Manager (GTM)

 1 year ago
source link: https://gist.github.com/keithws/c3a93663da38630be0cf00924fdbbbe4
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Marketo Form Listener for Google Tag Manager (GTM)

So how do I build the front end in tag manager to grab the data?

Author

keithws commented on Jun 8, 2018

You can create data layer type variables in GTM to expose this data to other tags and triggers.

For example, to expose the Marketo From ID to other tags and triggers:

  1. Choose New Variable
  2. Name the variable Marketo Form ID
  3. Choose variable type: Data Layer in the Page Variables section
  4. Input data layer variable name mkto.form.id

Or, to expose Marketo form field values to other tags and triggers:

  1. Choose New Variable
  2. Name the variable Marketo Form Email
  3. Choose variable type: Data Layer in the Page Variables section
  4. Input data layer variable name mkto.form.values.Email

Note, Marketo form field names are case-sensitive.

Author

keithws commented on Aug 30, 2018

By the way, you probably want to create new GTM triggers for the Marketo events. I recommend the following:

Trigger Type Event Name Trigger Name
Custom Event mkto.form.rendered Marketo Form Rendered
Custom Event mkto.form.ready Marketo Form Ready
Custom Event mkto.form.validate Marketo Form Validate
Custom Event mkto.form.submit Marketo Form Submit
Custom Event mkto.form.success Marketo Form Success
Custom Event mkto.form.error Marketo Form Error

We are using two forms(with different form IDs) on one page. We have implemented all the steps which you have mentioned but on button click we are getting Marketo Form ID for only one form.

Author

keithws commented on Mar 14, 2019

edited

In my experience, Marketo does not support multiple forms on one page. ¯\(ツ)

This gist gets the Market Form ID by calling the Marketo Forms 2 API method getId() on the form object passed as the first argument to the callback function for each event listener provided by the Marketo Forms 2 API.

Author

keithws commented on Mar 14, 2019

I updated this code to work even when the Marketo Forms 2 JavaScript is loaded after GTM. It works by polling for the existence of the MktoForm2 global variable. Don't worry, the polling has an exponential decay, so it won't slow down pages that do not load Marketo. Also, a new custom event, mkto.form.js, is pushed into the GTM data layer when the MktoForm2 global variable is detected.

Thank you so much for this!! I'm new to Marketo but comfortable enough with GTM and GA that this makes sense to me. Really looking forward to trying it out.

Ideal, Keith. Cheers for the work here

Thanks Keith I think this is exactly what I've been looking for!!
However I'm not a developer, more a technical marketer, so forgive me but I have a couple of questions...

  • I'm assuming this is implemented as a Custom HTML Tag via GTM, and fired on Pageview?
  • It looks like your code automatically adds the callback parameter described in the marketo API documentation here? https://developers.marketo.com/javascript-api/forms/ - meaning I don't need to do anything to the marketo form code, right?
  • You've already mentioned that code won't slow down pages that do not load Marketo - but what impact does it have on the speed of the pages that do load Marketo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK