SOLVED

Pixel Tracking on a Marketo Form and not have a follow up URL.

Go to solution
Michael_Bollig
Level 2

Pixel Tracking on a Marketo Form and not have a follow up URL.

Hello,

I saw the discussion about getting pixel tracking to work on the submit button correctly here. and down below:

 

MktoForms2.whenReady(function(form){
  var liPixelsrc="https://dc.ads.linkedin.com/whatever/the/img/url/is";
  form.onSuccess(function(vals,thankYouURL){
    var liPixel = new Image();
    liPixel.onload = function(e){
      document.location.href = thankYouURL;
    };
    liPixel.src=liPixelSrc;
    return false;
  });
});

 

 

I've applied this the best way I could to my current landing page. The only difference is I added a Marketo variable to the tracking URL and I also don't want a follow up/thank you URL. I just want to hide the form and have some text come up.

This worked before I applied the tracking pixel method in there. I also moved a few things around. I have some basic knowledge of JS but am still not understanding what's going on wrong... Now when I fill out the form it seems that the page just refreshes instead of giving a thank you message on the current page. This is what I have now:

 

MktoForms2.whenReady(function (form){
                //Add an onSuccess handler
                var liPixelsrc="${pixelTracking}";
                form.onSuccess(function(values, followUpUrl){
                  var liPixel = new Image();
                  liPixel.onload = function(e){
                  };
                  //get the form's jQuery element and hide it
                  liPixel.src=liPixelSrc;
                  form.getFormElem().hide();
                  document.getElementById('confirmform').style.display = 'block';
                  //return false to prevent the submission handler from taking the lead to the follow up url.
                  return false;
                });
              });
              });

 

 

Thank you for the help ahead of time! 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Pixel Tracking on a Marketo Form and not have a follow up URL.

Because you have a syntax error (you would see this in the browser console).  You also don't need the onload if you're not waiting for the pixel.

MktoForms2.whenReady(function (form) {
  var liPixelsrc="${pixelTracking}";
  
  form.onSuccess(function (values, followUpUrl) {
    var liPixel = new Image();
    liPixel.src=liPixelSrc;
    
    form.getFormElem().hide();
    document.getElementById("confirmform").style.display = "block";
    
    return false;
  });
});

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Pixel Tracking on a Marketo Form and not have a follow up URL.

Because you have a syntax error (you would see this in the browser console).  You also don't need the onload if you're not waiting for the pixel.

MktoForms2.whenReady(function (form) {
  var liPixelsrc="${pixelTracking}";
  
  form.onSuccess(function (values, followUpUrl) {
    var liPixel = new Image();
    liPixel.src=liPixelSrc;
    
    form.getFormElem().hide();
    document.getElementById("confirmform").style.display = "block";
    
    return false;
  });
});
Michael_Bollig
Level 2

Re: Pixel Tracking on a Marketo Form and not have a follow up URL.

@SanfordWhiteman Thank you for that catch!

 

I really need to brush up on my troubleshooting haha! 

 

When I click submit, It's now not processing the form...

Michael_Bollig_0-1602867178884.png

Could this be because of the Marketo variable I'm using for the pixel tracking?

 

Edit: I'm currently embedding this into a landing page template. The problem I have with that is I use this landing page template for many of our webinars and they mostly don't use pixel tracking. Would this affect those pages? That's why I wanted to have the Marketo variable to change what the URL was inside the LP editor instead of making a new template just for one webinar

 

Also, My form is submitting on the backend. I'm receiving the confirmation email, but the page itself doesn't let me know that.

Michael_Bollig
Level 2

Re: Pixel Tracking on a Marketo Form and not have a follow up URL.

@SanfordWhiteman 

Sorry for all the replies. I think I found my issue. I had too many closing braces at the end. " }); "

 

I'm still curious if it's okay to have the ${pixeltracking} in JS. will that URL still pull in there?

SanfordWhiteman
Level 10 - Community Moderator

Re: Pixel Tracking on a Marketo Form and not have a follow up URL.


I'm still curious if it's okay to have the ${pixeltracking} in JS. will that URL still pull in there?

That's fine as long as it's a Marketo LP and the variable is a properly JS-encoded URL, i.e. a URL suitable for being output directly inside double quotes.