How do I add GA tracking to an embedded Marketo form? | Community
Skip to main content
July 14, 2015
Question

How do I add GA tracking to an embedded Marketo form?

  • July 14, 2015
  • 3 replies
  • 5829 views

I have used embed code to add a Marketo (newsletter sign-up) form to my main website.

I would like to track in Google Analytics each time it is submitted. Is this something I need to do with Google Tag Manager?

Does anyone have instructions/a sample of how to do this?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

SanfordWhiteman
Level 10
July 14, 2015

Every (Forms 2.0) form has an onSuccess handler that allows you to plug in JS code that'll run when the form is successfully submitted.

So add whatever extra tracking code you want inside the onSuccess (people who've followed me may note I've started to use the universal MktoForms2::whenReady for forms demos instead of the embedded-only ::onReady, but you can refactor as appropriate).  Like so:

MktoForms2.whenReady(function(form){

     form.onSuccess(function(vals,thankYouURL){

          // call the GA tracker here

     });

});

(GTM is just a wrapper.  Anything you can do with GTM you can do with GA directly, and I find it far, far easier to control event order using GA alone.)

July 23, 2015

How would you incorporate this into the standard form script? Can you show me what a finished example looks like? I am sorry but I need a little hand holding, but I offer donuts in exchange for assistance.

SanfordWhiteman
Level 10
July 23, 2015

This form runs ga::send() to log the page visit only after the form has been successfully submitted (using the onSuccess event of the Forms 2.0 API):

MktoForms2 :: Lightbox :: GA onSuccess

You can run any other ga::<method> in the same way.

Ulf_Deeg
Level 3
July 14, 2015

I gotta admit, I haven't used GTM with Marketo forms, yet. However I would go for a tag management solution to use global form tracking to push GA events. It's far more manageable - all in one place. Also works with all forms.

In GTM it is just one Tag and one or two Lookup Tables.

  1. Pull in the form ID and/or Page URI and do a lookup table to get meaningful event action and event label values in GA.
  2. Then define GA Goals based on the "Form Submit" event to track GA conversion for lead generation.

You probably want to exclude Onsite search boxes and CMS login forms.

SanfordWhiteman
Level 10
July 14, 2015

The reason a dumb, global "tag manager" will never be 100% reliable is that it cannot be aware of a form's internal events. Only the form object will be aware that it has created and successfully submitted form data via Ajax. An external library cannot know this, and it will send erroneous data when the form has not been validated (but has been "submitted" as far as global HTML events go) and also when the form has been "submitted" but has actually encountered a server error. Only in the Forms 2.0 onSuccess handler can you be sure that Marketo has successfully received data. Anywhere else and what you're logging is simply the intent to submit, not the submit.

I believe we should strive to control for as many errors as possible in our code, since network conditions and user/browser behavior already make web analytics fuzzy enough!

Ulf_Deeg
Level 3
July 14, 2015

Yes, you are right. That's the trade off. There's no 100% reliability.

August 24, 2015

I just recently completed a project where I integrated Marketo and Google Analytics. I published an article and accompanying cheat sheet, both are available from Google Analytics-Marketo End-to-End Integration​ - I cover the form tracking extensively - you will get the step-by-step instructions on how to do it. 

September 15, 2015

Hi Stephane

I have tried a couple of times to download the cheat sheet on Google Analytics-Marketo End-to-End Integration  but it never came through to my inbox!

Lee

September 15, 2015

Hi Lee - some people reported an issue with the form subscription - being a freelancer, I couldn't afford to use Marketo to do it...

But if you email me at shamel@immeria.net I will send it directly to you.