Re: Google Analytics Pageview Form OnSubmit

Not applicable

Google Analytics Pageview Form OnSubmit

Hi everyone,

I have configured my marketo forms to bring users directly to a pdf when they submit the form.  Doing so has caused my google analytics goal tracking not to work because it reliese on a page being loaded with "thank-you" in the url which no longer happens.

So I wrote some Javascript to trigger a false pageview in GA that would cause the goal to trigger but I dont see this showing up at all in GA and I don't get any javascript errors when completing the form:

  <script type="text/javascript">

     MktoForms2.whenReady(function (form){

      //Add an onSuccess handler

   form.onSuccess(function() {

        //fire off thank you page goal in analytics

        ga('send', 'pageview', '/marketo-thank-you');

        //Trigger adwords conversion


        // Take the lead to a different page on successful submit, ignoring the form's configured followUpUrl

        location.href = "https://{{my.GBL Link To Asset}}";

        // Return false to prevent the submission handler continuing with its own processing

        return false;




Any ideas as to why this is happening here is a sample page with the code on it: Content Delivery Network (CDN) and Cloud Computing Services Provider | Akamai



Not applicable

Re: Google Analytics Pageview Form OnSubmit

Nevermind I got it to work I had to call the ga(create function first for some reason.

Level 10 - Community Moderator

Re: Google Analytics Pageview Form OnSubmit

That's still not the correct way to do it as your code has a race condition, and you will lose hits as a result.

You must use the Hit Callback function of Google Analytics.  Only run your location.href inside the hitCallback.

ga('send', 'pageview', {
'page': '/marketo-thank-you',
'hitCallback': function() {
    location.href = "https://{{my.GBL Link To Asset}}";