Forms 2.0 Fix for Capturing Search Engine and PPC info on Landing Pages

Anonymous
Not applicable

Forms 2.0 Fix for Capturing Search Engine and PPC info on Landing Pages

This discussion is an update for those of you who have written javascript code to capture PPC and search information into Marketo
(see article at https://community.marketo.com/MarketoResource?id=kA650000000GsPJCA).  

This javascript will NOT work for a world where you have Forms 2.0 forms on registration pages.   Forms 2.0 forms are implemented in a very different manner than Forms 1.0 forms.  (Take a look at the page source to see the difference).   In Forms 2.0, you can no longer get directly to the fields using the field API names.   Thus, if you have upgraded your Form 1.0 to Form 2.0 without changing the javascript, you won't be storing all of those nice cookied values on form completion.

Because I like to have my PPC and search javascript on all of my Marketo landing pages, I put the javascript in the landing page templates.  That meant that I had to find a solution that would work regardless of whether there was a Forms 1.0 or Forms 2.0 form on the page.   To do this, I turned to the Forms 2.0 apis (http://developers.marketo.com/documentation/websites/forms-2-0/).

The changes to your original javascript are fairly minor:

1)  You need to add an addition javascript library reference to support your calls to the Forms 2.0 apis:   

<script language="JavaScript" src="/js/forms2/js/forms2.min.js" type="text/javascript"></script>

2) Prior to storing the cookied values in the Marketo fields in your javascript, you need to determine whether the form is a Forms 1.0 or  2.0 form

Use the MktoForms2.allForms() api to determine whether any Forms 2.0 forms are on the page.  (This is why you need the forms2 library script shown above.)

If no forms are returned, then you can assume that you have a Forms 1.0 form on the page and use your existing code to pull the cookie values into the fields.

If a form is returned, then you use the form.setValues(vals) api to put the cookie values into the fields.   This api requires a set of name : value pairs.   The name is the Marketo field api name.   The value is the string value from the cookie.

That is all there is to it.   When you make these changes to your javascript, you don't have to worry about whether you are using a Forms 1.0 or 2.0 form on the landing page.  

Let me know if there are any questions.   I have written and tested a solution built this way in an environment that has workspaces.   It works like a charm.
 
-Pam
Tags (1)
2 REPLIES 2
Edward_Masson
Level 10

Re: Forms 2.0 Fix for Capturing Search Engine and PPC info on Landing Pages

Nicely done Pam!
Anonymous
Not applicable

Re: Forms 2.0 Fix for Capturing Search Engine and PPC info on Landing Pages

Hi,
could someone help me?
I cant find the jQueries with is necessary for PPC:
[<script src="/js/jquery.cookie.js" type="text/javascript"></script> 
<script src="/js/jQueryString-2.0.2-Min.js" type="text/javascript"></script>] 
Is this jQuesry somewhere on CDN or on web for download?

Brgds
Ondrej W.