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

Thai_Luong
Level 2

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

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!

Tags (2)
4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

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

Pls syntax-highlight *all* the code blocks.

Thai_Luong
Level 2

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

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 - Community Moderator

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

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

Thai_Luong
Level 2

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

I guess to start off, I'd like the form to open a new tab after a user provides their info. Here is the test landing page: Cadence 

Please excuse the coding....I know it's terrible and I was not responsible for creating our templates.

Again, thanks and I really appreciate any assistance!!