Re: GA Event for Marketo Form Submission

Anuja_Jadhav
Level 1

GA Event for Marketo Form Submission

Hello All,

I am aware that this topic is covered in a post but I am recreating a new thread since the solutions did not help me out.

What I am trying to achieve? - For every Marketo form with a landing page that is submitted I want to send an event to GA passing the form id.

What I am doing currently? - On the Marketo landing page I am writing this piece of code within an html box element.

<script src="//app-ab24.marketo.com/js/forms2/js/forms2.min.js"></script>

<form id="mktoForm_1234"></form>

<script>MktoForms2.loadForm("//app-ab24.marketo.com",

"123-XYZ-456",

1234,

function(form){

form.onSuccess(

function(values, thankYouUrl){

ga("send", {

hitType : "event",

hitCallback : function() {

document.location.href = thankYouUrl;

},

eventAction : "Submitted",

eventCategory : "Marketo Form",

eventLabel : form.getId()

}

);

}

);

}

);</script>

What is output am I seeing? - In GA I see a pageview for my landing page. No event is sent.

Can anyone suggest what modifications I can try to make this work?

Thanks in advance!

8 REPLIES 8
SanfordWhiteman
Level 10 - Community Moderator

Re: GA Event for Marketo Form Submission

Please highlight your code so it's readable.

https://s3.amazonaws.com/blog-images-teknkl-com/syntax_highlighter.gif

SanfordWhiteman
Level 10 - Community Moderator

Re: GA Event for Marketo Form Submission

Please add a comment once you've made the code readable, so I know to check back.

You should also include a link to your page so I can check that you've deployed the code properly.

Anuja_Jadhav
Level 1

Re: GA Event for Marketo Form Submission

Sanford Whiteman

I have highlighted the code and here is my page link: https://go.takarabio.com/jadhavaTestCampaign_test.html

SanfordWhiteman
Level 10 - Community Moderator

Re: GA Event for Marketo Form Submission

Please note the console error:

pastedImage_0.png

That's because you don't have GA loaded on the page. As a result, the onSuccess listener errors out (never gets a chance to return), and the default success action proceeds.

Anuja_Jadhav
Level 1

Re: GA Event for Marketo Form Submission

Sanford Whiteman

I am not seeing this error. For me GA loads and using Google Analytics Debugger I am able to see all the parameters.

But if I see this error, what can be the workaround for it?

Regards,

Anuja

SanfordWhiteman
Level 10 - Community Moderator

Re: GA Event for Marketo Form Submission

You're not getting the difference between a GTM-loaded GA and the ga object. Please read up on this, it's fundamental to using Google's analytics API(s) properly.

It's clear, if you look that the Dev Tools console, that your code isn't firing because ga is not in scope.

Anuja_Jadhav
Level 1

Re: GA Event for Marketo Form Submission

Sanford Whiteman​ I am still unable to figure out how I can resolve this and get ga in scope.

From some articles that I read I tried following:

1. Added ga code within script tag into my original code pasted here - did not work

2. Used __ga_tracker instead of just ga - did not work

Can you suggest anything? or share any links that can help out?

Regards,

Anuja

SanfordWhiteman
Level 10 - Community Moderator

Re: GA Event for Marketo Form Submission

ga is now in scope and you are sending events.

pastedImage_0.png