GA event tracking for onSuccess

Anonymous
Not applicable

I am trying to figure out what's wrong with my landing page. I am trying to keep the on-page thank you message and send a GA event. I have the thank you working as expected, but the GA event is not firing.

Here is the code that I'm using:

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

<script>

MktoForms2.whenReady(function (form){

//Add an onSuccess handler

form.onSuccess(function(values, followUpUrl){

//GA event trigger

if ( 'YES' == '${z-TriggerGAEvent}') {

ga('send','event','${z-GAEventCategory}','${z-GAEventAction}','marketo');       

              }

//get the form's jQuery element and hide it

form.getFormElem().hide();

    document.getElementById('confirmform').style.visibility = 'visible';

    //return false to prevent the submission handler from taking the lead to the follow up url.

    return false;

  });

});

</script>

The landing page lives here.

Any suggestions are much appreciated.

Thanks,

Thomas

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

The reason this isn't working doesn't have to do with Marketo. It's because you're using the gtag.js library, not the core GA library. The equivalent gtag syntax is:

gtag('event', 'beacon-submit', {

  event_category: 'form',

  event_label: 'marketo'

});

In the future, please use the Advanced Editor's syntax highlighter for JS, keeps me saner:

pastedImage_2.png