Skip to main content
Thai_Luong
Level 2
January 10, 2020
Question

How can I have a new page open after form completion and track via GTM?

  • January 10, 2020
  • 1 reply
  • 3040 views

Hey Marketo Nation ( and @Sanford Whiteman), 

I've seen some threads about tracking forms via GTM and would like some clarification. Before getting some clarification, here is my problem I'm trying to solve.

I have marketo landing page with a form on it and once completed, a user receives the ebook they requested. When trying to track via GTM, I'm trying to create a datalayer.push to see what I can use to create a tag. But I can't even figure that out yet because when I'm testing, the page doesn't open up a new tab and I'm unable to see what data is being pushed in GTM's debug mode.

So my first problem is, how can I have a form completion open up a new tab? Do I embed this script in the HTML?

<script>
MktoForms2.loadForm("//app-sj11.marketo.com", xxx-xxx-xxx", 3949);
MktoForms2.whenReady(function(form) {

var thankYouWindow;

MktoForms2.lightbox(form).show();

form.onSubmit(function(form) {
thankYouWindow = window.open('');
});

form.onSuccess(function(vals,followUpUrl) {
thankYouWindow.document.location = followUpUrl;
return false;
});

</script>

If yes, is there a recommended spot to place it?

Secondly, once that's working should I create a data layer push like this (for example):


<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'event:'marketo_form_submit': [{
'email': '@',
'name': 'T-Shirt',
'category': 'Apparel',
'price': 11.99,
'quantity': 1
},{
'sku': 'AA1243544',
'name': 'Socks',
'category': 'Apparel',
'price': 9.99,
'quantity': 2
}]
});
</script>

OR have a script like this (that's either on the page or fired through GTM):

MktoForms2.whenReady(function(form) {
  form.onSuccess(function(vals, tyURL) {
    gtag("event", "Conversion", {
      event_category: "Marketo",
        event_label: "mkto.form.id",
        event_callback: function(){
          document.location.href = tyURL;
        }
     );
    return false;
  });
});

Thanks in advance!

1 reply

SanfordWhiteman
Level 10
January 10, 2020

Pls syntax-highlight *all* the code blocks.

Thai_Luong
Level 2
January 13, 2020

Hi Sanford....thanks for getting back to me and apologize for the dumb question, but what do you mean by "Pls syntax-highlight *all* the code blocks."?

SanfordWhiteman
Level 10
January 13, 2020

I mean you highlighted the 3rd bit of code (the onSuccess) but not the other 2. Please make them all readable.