Re: Sumbission of marketo forms showing as events in GA, preferably using GTM

Anonymous
Not applicable
I am just wanting to fire an event to GA on the submission of a form. What is the best way to do this?
If possible i would like to use Google Tag Manager to do it.
Tags (1)
24 REPLIES 24
SanfordWhiteman
Level 10 - Community Moderator
@James if you want to contact me directly we can work on it.
Anonymous
Not applicable
Does anyone have an idea about this one?
Anonymous
Not applicable

Were you ever able to figure out why your form wasn't showing up? I'm facing the same issue today.

Anonymous
Not applicable
Does anyone have an idea about this one?
Anonymous
Not applicable
No, its still not working, I cannot figure out for the life of me why not.....
SanfordWhiteman
Level 10 - Community Moderator
That looks right (I'm on my mobile, though, so I can't check the console). What do you see in the console when you submit now?
Anonymous
Not applicable
i have it in there, or is there an additional element that needs to go in?

<script src="//app-sj07.marketo.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_456"></form>
<script>MktoForms2.loadForm("//app-sj07.marketo.com", "801-TVW-591", 456, function(form){
 form.onSuccess(function(form){
     ga('send', 'event', {
      eventCategory: 'PDF',
      eventAction: 'Downloaded',
      eventLabel: 'PDF On HOw To Turn HR into a Profit Center Downloaded'
       });
     });
    return true;
  });
</script>
SanfordWhiteman
Level 10 - Community Moderator
On that page, I don't see any onSuccess handler.

I only see the default embed code:

<script>MktoForms2.loadForm("//app-sj07.marketo.com", "801-TVW-591", 456);</script>
Anonymous
Not applicable
the page we are running it on is this one:
http://www.recogniseeveryday.com.au/why-recognition/articles-videos/turning-hr-into-a-profit-centre-how-to-calculate-the-roi-of-your-recognition-program/
Anonymous
Not applicable
I have fixed it now so that the code is firing, however the event is not coming through in GA......

here is what i am using:
<script src="//app-sj07.marketo.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_456"></form>
<script>MktoForms2.loadForm("//app-sj07.marketo.com", "801-TVW-591", 456, function(form){
 form.onSuccess(function(form){
     ga('send', 'event', {
      eventCategory: 'PDF',
      eventAction: 'Downloaded',
      eventLabel: 'PDF On HOw To Turn HR into a Profit Center Downloaded'
       });
     });
    return true;
  });
</script>

 
SanfordWhiteman
Level 10 - Community Moderator
Well, you have an errrant "true;" in your code, so there's probably a syntax error.  I hope you're looking at your browser's console/developer tools to see such things.

The correct code is demoed here.  The onSuccess is called as expected.  However since that page doesn't have your GTM code, it fails (understandably) on the line that calls _gaq.push().  

If you post the actual URL of your page I could take another look.
Anonymous
Not applicable
this is what i have now but it still isnt letting the form submit...


<div class="FormLightbox">
<a class="btCloseLightbox" href="javascript:;"><span>X</span></a>
<h1>Tell us about yourself</h1>

<p>
This ebook is yours for free. Just enter your details below, and you'll have access to the entire RED resource library!</p>

<script src="//app-sj07.marketo.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_456"></form>
<script>MktoForms2.loadForm("//app-sj07.marketo.com", "801-TVW-591", 456, function(form){
    form.onSuccess(function(form){
        _gaq.push
 true;('_trackEvent' 
            , 'PDF' 
            , 'Downloaded' 
            , 'PDF On HOw To Turn HR into a Profit Center Downloaded');
        });
return true;
});
</script>

 
SanfordWhiteman
Level 10 - Community Moderator
You must still be leaving something out of the exact code. 🙂  Or you deleted the final </script>.

This is where you put return true; to tell Forms 2.0 to also redirect to the Thank You URL:

function(form){
    form.onSuccess(function(form){
        _gaq.push('_trackEvent' 
            , 'PDF' 
            , 'Downloaded' 
            , 'PDF On HOw To Turn HR into a Profit Center Downloaded');
        });
        return true;

});


 
Anonymous
Not applicable
its still not working for me,
I was not entirly sure what you meant by return true; , I am not very technical
I tried a few variations of what i thought you might mean but non worked. 

Here is the exact code I am trying: 
<div class="FormLightbox">
<a class="btCloseLightbox" href="javascript:;"><span>X</span></a>
<h1>Tell us about yourself</h1>

<p>
This ebook is yours for free. Just enter your details below, and you'll have access to the entire RED resource library!</p>

<script src="//app-sj07.marketo.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_456"></form>
<script>MktoForms2.loadForm("//app-sj07.marketo.com", "801-TVW-591", 456, function(form){
    form.onSuccess(function(form){
        _gaq.push.
 true;('_trackEvent' 
            , 'PDF' 
            , 'Downloaded' 
            , 'PDF On HOw To Turn HR into a Profit Center Downloaded');
        });
});
SanfordWhiteman
Level 10 - Community Moderator
Add return true; after the _gaq.push line.
Anonymous
Not applicable
Whoops, sorry about that.
I made the suggested alterations and the form appeared again. However now it is not not directing people to the follow up page that is in the settings. 

What do I need to do to bring back the follow up page in addition to the event tracking?
SanfordWhiteman
Level 10 - Community Moderator
Typo... "from" != "form"

Also, you may have mismatched braces:

MktoForms2.loadForm("//app-sj07.marketo.com", "801-TVW-591", 456, function(form){
    form.onSuccess(function(form){
        _gaq.push('_trackEvent' 
            , 'PDF' 
            , 'Downloaded' 
            , 'PDF On HOw To Turn HR into a Profit Center Downloaded');
        });
});
Anonymous
Not applicable
I have tried the exact code below but for some reason when I deploy it it stops the form from appearing. Any ideas of what is wrong with it?

<script src="//app-sj07.marketo.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_456"></form>
<script>MktoForms2.loadForm("//app-sj07.marketo.com", "801-TVW-591", 456, function(form){from.onSuccess(function(form){_gaq.push('_trackEvent' , 'PDF' , 'Downloaded' , 'PDF On HOw To Turn HR into a Profit Center Downloaded');});
</script>
SanfordWhiteman
Level 10 - Community Moderator
You should use onSuccess:

form.onSuccess(function(form){
    _gaq.push( ... );
});
Anonymous
Not applicable
I agree with Sanford that I only want to know when people have successfully submitted the form. 
So Sanford would you say i just need to change the embed code to be something like:

<script>MktoForms2.loadForm("//app-sjqe.marketo.com", "718-GIV-198", 621, function(form){
form.onSubmit(_gaq.push(['_trackEvent' , 'PDF' , 'Downloaded' , 'PDF On how to dowload(){
});
</script>