SOLVED

Referring someone new via a Marketo form (and attributing that referral to the person who submitted the form)

Go to solution
MarianoAdunseCO
Level 2

Hi all,

 

As the title suggests, I would like a functionality that will allow users to submit a form referring a new person. When the form is submitted, a new record will be created within Marketo. Ideally I would like to do this without the use of JavaScript hacks (ideally I would prefer a webhook). I've searched, but I can't find any topics specifically covering this (I don't need to do anything more complicated than simply submitting a form that creates a new record (referee) and updates an existing one (referrer)). Is this possible at all?

 

Thanks!

Tags (1)
2 ACCEPTED SOLUTIONS
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

@MarianoAdunseCO wrote:

I see @Darshil_Shah1 . So in the example, you provided, the "FA's Email" populates to a hidden form field (on the same form) when the form is submitted to the visible form field value that corresponds to it (in the hidden field)? Just so I'm understanding this correctly (I believe I am but would like to verify). 

 

In Sandy's script the "FA's Email" field's value is not appended to any hidden field during the referrer's form submission (i.e., during the form submission 1), but this can be easily done with the formObject.setValues() function (we would need the API name of the field(s) to which the referee's email and/or other details need to be added during referrer form submission).

 

 

In which case, If I needed to add a First Name, Last Name, Country and Company for the referee, I would need to do this:

 

'Email': originalValues['Email_Address_2__c'],

'FirstName': OriginalValues['Email_Address_2__c'],

'ComapnyName': OriginalValues['Email_Address_2__c'],

 

You need to replace the 'Email_Address_2__c' with the actual fields' API names being used in the form - you can find the API names of the fields from the field management, read about it here.

 


 

Finally, I'm a little in the dark about this other aspect of the script... What do these numbers need to be populated with?:

 

MktoForms2.loadForm("//app-sj01.marketo.com", "410-XOR-673", 441);

 


Well, these are not just random characters - these are the baseUrl, munchkinId, and formId, respectively you can look for these values in the Embed Form code - go to Marketo > Navigate to and select the Marketo form you're gonna use for this project > Select Form Actions in the right Pane > Click on the Embed Code - A dialog box will appear with the script to embed the form - this script will have MktoForms2.loadForm("<baseUrl>", "<MunchkinId>", <formId>) - you need to plug values you see here into the actual script. 

 

 

And apologies to ask another set of questions - but what other aspects of the script need to be customised with values unique to your own form and LP?

 

Is that correct? And I'd assume the scripts would sit at layout template level...


This is a starter script with the recipe for the multiple form submissions, clearing cookies after first submission, assigning apt referrer and referee data during each of the form submissions - you need to update the API names of the fields you're using in the form, instance base URL, munchkin-id, form-id, and the form-js script address.

 

This can be added at the LP/webpage level unless all the LPs you're gonna create from the template need to reference this script.

View solution in original post

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

You would want the  '_mkt_trk': '' in the on Success method, I was rather talking about below line from the code snippet's snapshot you posted in your earlier comment. 

 

Darshil_Shah1_1-1650875017664.png

 

I made one test submission - I didn't see any errors and also did see the 2 success (200 OK) calls to the save endpoint. Do you see the records at your end?

 

View solution in original post

25 REPLIES 25
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Well, it's pretty straight fwd if you do via JS - you can build a form that let's the referrer add data about themselves and also the referee - you can clear the referee details during the first form POST in the onSubmit() function (thereby submitting the referrer data only in form post 1), and in the onSuccess() function set the form field values for the referee and make an another POST (i.e., form submission for submitting the referee data). You can use hidden field(s) to add data about the referee while submitting the form for referrer - for attribution.

 

Just to clarify, both the form submissions are regular/usual Marketo form submissions - i.e., a new lead will be created if not already present in the database, else an existing lead with the matching email address will be updated.

 

Before submitting the form again for the referee - JS can take care of clearing out the previously created cookie as well, as per this Marketo dev page.

 

You can refer Sandy's sample script to pull this off here (it's pretty sleek and straight fwd).

MarianoAdunseCO
Level 2

I see @Darshil_Shah1 . So in the example, you provided, the "FA's Email" populates to a hidden form field (on the same form) when the form is submitted to the visible form field value that corresponds to it (in the hidden field)? Just so I'm understanding this correctly (I believe I am but would like to verify). 

 

In which case, If I needed to add a First Name, Last Name, Country and Company for the referee, I would need to do this:

 

'Email': originalValues['Email_Address_2__c'],

'FirstName': OriginalValues['Email_Address_2__c'],

'ComapnyName': OriginalValues['Email_Address_2__c'],

 

Finally, I'm a little in the dark about this other aspect of the script... What do these numbers need to be populated with?:

 

MktoForms2.loadForm("//app-sj01.marketo.com", "410-XOR-673", 441);

 

And apologies to ask another set of questions - but what other aspects of the script need to be customised with values unique to your own form and LP?

 

Is that correct? And I'd assume the scripts would sit at layout template level...

SanfordWhiteman
Level 10 - Community Moderator

FYI much newer and improved code is at

MktoForms2 :: Referral v2.0.2

 

MarianoAdunseCO
Level 2

This has worked brilliantly @Darshil_Shah1 @SanfordWhiteman 

 

Thank you both. 

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Awesome, very cool!

MarianoAdunseCO
Level 2

Hey @Darshil_Shah1 , as it turns out, I was wrong - the code didn't actually work. I (without my realisation) actually completed the form twice - so in fact, it didn't work as perfectly as I expected....

Here's a screenshot of the exact code I used. I've annotated the bits I changed (relevant to my own form). I'm really not sure what I'm missing here? I put this code in the layout template (after the body tag) - sorry to point out the obvious, just want to make my process clear.

 

Also ideally I would like to be able to use the form at the template level instead of adding it to the landing page (by adding the form in the LP wizard) (the first red annotation in the screenshot). Can I simply strip that code out? I know you said I can do this, but when I use the code as it is below (and then create a landing page based on the template), the form is invisible. And this is even after I moved the form tag to the body of the HTML (in the template).

Hopefully this has been descriptive enough! Sorry about the confusion. The code's just driving me nuts. Could you perhaps add some comments to the original code you provided on what to do to make this work? Also - I'm not sure why but the field for "Email" isn't showing up twice on the landing page (one for referrer and one for referee)..

I know I'm screwing up somewhere really obvious so I really appreciate your patience with this.

 

Javascript.png

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Thank you for describing your issue in detail - this certainly helps a lot (having a clear understanding of problem most of time translates to winning half of the battle)!

 

Well, you need to have a separate field to capture the Email Address of the referee  - in Sandy's example the referee's email address is captured in the "FA's Email" field which is different from the "Your Email" field used to capture the referrer email address - you would need to add two different fields on the form for one for referee's and the other for referrer's email address.

 

I added comments for your reference in the whenReady function:

 

MktoForms2.whenReady(function(form) {
    var originalValues;
    
    form.addHiddenFields({'_mkt_trk':''});

    form.onSubmit(function(form) {
/* First form submission when visitor clicks submit button on form - form submitted for the referrer lead*/

      originalValues = form.getValues();
      form.setValues({
        'Email_Address_2__c': '' 
/* Replace 'Email_Address_2__c' with the API name of the Referee's Email Address field. Also, if you would like this field's value to appear on the Referrer's record in Marketo for the purpose of attribution - you can omit this line of code, and the setValues function too, if you're not resetting any of the fields on referrer form submit*/

      });
    })

    form.onSuccess(function(vals, thankYouURL) {
      this.onSuccess(); // clear onSuccess for 2nd run
      this.setValues({
        'LastName': '',
        'FirstName': '',
        '_mkt_trk': '',
        'Email': originalValues['Email_Address_2__c'] 
/*Replace the API name of the Referrer's email address field in the Key (Email) and Referee's email address field in the value, i.e., replace 'Email_Address_2__c' with the referee email field's API name in the originalValues['Email_Address_2__c']*/

      });
      this.submit(); // send it again - this will submit the data for the referee
    }.bind(form));

  });

 


 

Also ideally I would like to be able to use the form at the template level instead of adding it to the landing page (by adding the form in the LP wizard) (the first red annotation in the screenshot). Can I simply strip that code out?

Well, the <form id="mktoForm_<insert-form-id>"></form> is essentially the container for the form - if you remove this you won't have any container to load the form on the web-page and that is the reason you didn't see the form when you removed it - put the form element (i.e., <form id="mktoForm_<insert-form-id>"></form>) where you would like to show / display the form on the webpage. I don't think I said to remove the form container.

 

Also. if haven't already, I would suggest changing the base-url in the script with your Marketo instance's - you can find the base url in the embed form script of the form that you referred for the form-id and Munchkin-id. If you see my earlier comment - I've added a skinny about the base-url.

 

Let us know how it goes, or in case if you have questions. 🙂

MarianoAdunseCO
Level 2

Thank you @Darshil_Shah1  and @SanfordWhiteman ! I  do have a follow-up question and this pertains to attribution:

 

How would I create attribution in the sense of, if one person referred to multiple people? How would the referee details (the email addresses) be associated with that referrer record? Say, if a person fills out a form 10 times, to refer 10 different people? 

 

And finally, it appears the form cannot be submitted more than once (more than one referrer, whether it's the same referrer or not (with a new referee)).

 

I've tried submitting the form using a different IP address as well - still, the new submission isn't working. I run a Smart List looking at the form submissions, and it only shows the two initial submissions (referrer and referee). Is the script somehow limited to one submission?

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Well, you can have a text field to store all the referees’ email address, you can append referee’s email address to this text field each time a referrer fills out the form. Also, you would not want to clear the referee email address while making the 1st POST request in the script- use the data in referee email address field to append to a separate text area field (you can create a campaign to do this). 

Also, script does not restrict a referrer from submitting the form multiple times - all the script does is Post referrer form data - Map data for the referee form submission - Post  referee form data.

 

If you share the script you’re using (consider white labelling form - id/munchkin id/base url) with us, we can help look as to why a referrer isn’t allowed to submit form multiple times.

MarianoAdunseCO
Level 2

How do I prevent the Referee email address field from clearing whilst making the first post @Darshil_Shah1 ? Do you mind posting a code snippet, please?

 

I quite like the idea of using a Smart Campaign to append the referee emails to a text field, @Darshil_Shah1 . I assume I'd use some simple logic to handle this, right? I.e. Fills out Form > Change Data Value (text field >> {{referee.referee field}}). Is this correct? Or will Change Data Value update the text field with a new value every time...? I'm thinking it will...?

 

The form is now submitting new data too by the way! There had to be some delay in the Smart List updating for some reason.

 

@Darshil_Shah1  I found this article for appending data to a text field.. This is correct, right? Also - does it have to be a free text field? Or can it be a simple string? Thank you!

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

@MarianoAdunseCO wrote:

How do I prevent the Referee email address field from clearing whilst making the first post @Darshil_Shah1 ? Do you mind posting a code snippet, please?

 


Well, it's pretty straight forward - just remove the setValues method from the referrer's form post - and clear out the value of the referee's email address field used on the form during the form post 2, i.e., during the referee's form post. Refer below:

 

 MktoForms2.whenReady(function(form) {
    var originalValues;
    form.addHiddenFields({'_mkt_trk':''});
    form.onSubmit(function(form) {
      originalValues = form.getValues();
    })
    form.onSuccess(function(vals, thankYouURL) {
      this.onSuccess(); // clear onSuccess for 2nd run
      this.setValues({
        'LastName': '',
        'FirstName': '',
        'Email_Address_2__c':'', //Replace 'Email_Address_2__c' with the API name of the Referee's email field
        '_mkt_trk': '',
        'Email': originalValues['Email_Address_2__c'] 
/* Add the API name of the Email Address in the Key ('Email') and Referee's email address field in the value, i.e., replace 'Email_Address_2__c' with the referee email field's API name in the originalValues['Email_Address_2__c']*/

      });
      this.submit(); // send it again
    }.bind(form));
  });

 


I quite like the idea of using a Smart Campaign to append the referee emails to a text field, @Darshil_Shah1 . I assume I'd use some simple logic to handle this, right? I.e. Fills out Form > Change Data Value (text field >> {{referee.referee field}}). Is this correct? Or will Change Data Value update the text field with a new value every time...? I'm thinking it will...?

 

 


 Yeah - you would want to trigger on the fills out form activity, in the flow I would recommend clearing out the data from referee's email address field, after appending the data to the text area field - you can add in the filter in the SL to check for the non-empty values for the Referee's email address field. Your smart campaign should look something like below (I've used the placeholder field/form names - change them as per your setup).

Darshil_Shah1_0-1650731016658.png

Darshil_Shah1_0-1650732118290.png

 

If required, you can add a condition in the 1st change data value flow step to ensure that you do not end up re-adding the same referee email address field in case the referrer refers the same person more than once. The flow in that case would look something like below:

Darshil_Shah1_2-1650731558469.png

Also, make sure you update the campaign qualification rules to allow people to run through the campaign multiple times.

 


@Darshil_Shah1  I found this article for appending data to a text field.. This is correct, right? Also - does it have to be a free text field? Or can it be a simple string? Thank you!


 Well, string field has a character limit of 255 chars - data beyond the 255th char will get truncated thereby limiting the number of email addresses that you can store in the field. The text area field enjoys much higher character limit of 65535 chars when updated via GUI/API - which should be sufficient for storing quite a lot of email addresses (at least much more  than a typical referrer would refer).

MarianoAdunseCO
Level 2

@Darshil_Shah1  That worked, thank you! The data is feeding correctly - and I've triple-checked with multiple submissions. Thanks again, you're an asset to the community, along with @SanfordWhiteman !

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

That is awesome, @MarianoAdunseCO! Glad to be able to help. 

MarianoAdunseCO
Level 2

@Darshil_Shah1  I'm not entirely sure why, but I'm using the same code - in a different instance (making sure I've changed the relevant munching code and URLs etc), but for some reason, the second post isn't going through. I'm getting a message that flashes on the submit button that says "Submission failed, Please try again later." (indicating the second post failed) before the follow-up page then loads..

 

Do you know the reason this might be happening? One variation is, I'm using the GET method in this second instance as opposed to POST... 

 

Also, I've loaded forms 2 right before this - I just clipped it from the screenshot.

 

Finally, the troubleshooting article I found on the error message in Community states that the reason for this is that there are two conflicting instance URLs on the page. I am positive that there aren't, because I searched the entire source code in the template and can't find any others!

 

Failed.png

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Well the form submit is always a POST request to Marketo (triggers on form submit).

Also, is there any reason that you're setting a empty key in the line before the 'mkto_trk':'' line in the onSuccess method while making the referee's form submission? I hope you're loading all the forms on your LP using the same domains / instance base-URLs.

 

Lastly, can you share the webpage's URL where you've deployed this? It'll  help us diagnose the problem better.

MarianoAdunseCO
Level 2

the empty "mkt_trk" was an omission on my part @Darshil_Shah1 . Could that be causing issues? I wouldn't think so, but I will strip it out just to be sure.

 

Here's the web page:

 

Just editing out the web page for the sake of censorship!

 

Also I'm definitely using all the URLs as far as I can see. I may have missed something, though.

 

Also please feel free to run a test on the form.

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

You would want the  '_mkt_trk': '' in the on Success method, I was rather talking about below line from the code snippet's snapshot you posted in your earlier comment. 

 

Darshil_Shah1_1-1650875017664.png

 

I made one test submission - I didn't see any errors and also did see the 2 success (200 OK) calls to the save endpoint. Do you see the records at your end?

 

MarianoAdunseCO
Level 2

Yes, indeed I do see the records! Thank you so much again @Darshil_Shah1 !!

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

That's awesome!

 

 

SanfordWhiteman
Level 10 - Community Moderator

Strongly recommend the newer code in my CodePen as it provides a much smoother UX thanks to the "freeze" feature.