SOLVED

UTM parameters not populating into utm fields

Go to solution
Julz_James
Level 10 - Champion

Re: UTM parameters not populating into utm fields

Thank you so much for the lovely feedback!  It's was nothing to do with the fields (i'd already checked all the fields), it was some old javascript that was hidden.  Thanks to Sanford Whiteman​ he found the code and now I'm working on getting it removed.

Sant_Singh_Rath
Level 7

Re: UTM parameters not populating into utm fields

Hi Laura,

We have been using 'URL Parameter' instead of Cookie value and it's working fine for us as of now.

Dan_Stevens_
Level 10 - Champion Alumni

Re: UTM parameters not populating into utm fields

This is fine if you’re sure the user will be submitting the form with the hidden UTM fields on the first page they visit. After that, those parameters are lost. The reason cookies (or even LocalStorage (https://blog.teknkl.com/quick-and-dirty-utm-forwarder/ )) are a better approach is it keeps the last set of parameters persistent. For example, when a person (anonymous or known) navigates multiple pages of your site before ultimately converting. Or even multiple sessions.

Conor_Fitzpatri
Level 6

Re: UTM parameters not populating into utm fields

Sanford, I am running into issues similar to Laura and am testing out your approach (that Dan referenced above). I'm working with native Marketo landing pages and am wondering how I can place the forwarding script in between the forms2.min.js and MktoForms2.loadForm scripts.

SanfordWhiteman
Level 10 - Community Moderator

Re: UTM parameters not populating into utm fields

On a Marketo LP, you can add another remote <script> that loads forms2.min.js to the <head>. Follow that directly by the forwarder code.

<script src="/js/forms2/js/forms2.min.js"></script>

<script>

// UTM forwarder goes here

</script>

Conor_Fitzpatri
Level 6

Re: UTM parameters not populating into utm fields

You're awesome, thanks!

Jina_Watson
Level 1

Re: UTM parameters not populating into utm fields

I'm not someone that uses Javascript. For the instructions of inserting your code into the Marketo embedded form code, how does it drop in exactly?

 

Like this:

 

<script src="//app-lon07.marketo.com/js/forms2/js/forms2.min.js"></script>
<script>(function(opts){
  var current = {
        state : document.location.href,
        query : document.location.search.substring(1),
        time : new Date().getTime()
      },
      storage = {
        area : window.localStorage,
        key : 'last_utm_query'
      },
      restored, 
      updated = {};

  if (/(^|&)utm_/.test(current.query)) {
    storage.area[storage.key] = JSON.stringify({ time:current.time, query:current.query });
  } else if (restored = JSON.parse(storage.area[storage.key] || '""')) {    
    if ( window.MktoForms2 && ( current.time - restored.time <= opts.expireDays * 864E5 ) ) {
      updated.state = document.createElement('a');
      updated.state.href = current.state;
      updated.state.search += (updated.state.search ? '&' : '') + restored.query + '&restored=' + restored.time;
      history.replaceState('', {}, updated.state);
    }
  }
})({
  expireDays : 30
});</script>
<form id="mktoForm_1043"></form>
<script>MktoForms2.loadForm("//app-lon07.marketo.com", "041-BQO-927", 1043);</script>

 

 

Or like this:

 

<script src="//app-lon07.marketo.com/js/forms2/js/forms2.min.js">(function(opts){
  var current = {
        state : document.location.href,
        query : document.location.search.substring(1),
        time : new Date().getTime()
      },
      storage = {
        area : window.localStorage,
        key : 'last_utm_query'
      },
      restored, 
      updated = {};

  if (/(^|&)utm_/.test(current.query)) {
    storage.area[storage.key] = JSON.stringify({ time:current.time, query:current.query });
  } else if (restored = JSON.parse(storage.area[storage.key] || '""')) {    
    if ( window.MktoForms2 && ( current.time - restored.time <= opts.expireDays * 864E5 ) ) {
      updated.state = document.createElement('a');
      updated.state.href = current.state;
      updated.state.search += (updated.state.search ? '&' : '') + restored.query + '&restored=' + restored.time;
      history.replaceState('', {}, updated.state);
    }
  }
})({
  expireDays : 30
});</script>
<form id="mktoForm_1043"></form>
<script>(function(opts){
  var current = {
        state : document.location.href,
        query : document.location.search.substring(1),
        time : new Date().getTime()
      },
      storage = {
        area : window.localStorage,
        key : 'last_utm_query'
      },
      restored, 
      updated = {};

  if (/(^|&)utm_/.test(current.query)) {
    storage.area[storage.key] = JSON.stringify({ time:current.time, query:current.query });
  } else if (restored = JSON.parse(storage.area[storage.key] || '""')) {    
    if ( window.MktoForms2 && ( current.time - restored.time <= opts.expireDays * 864E5 ) ) {
      updated.state = document.createElement('a');
      updated.state.href = current.state;
      updated.state.search += (updated.state.search ? '&' : '') + restored.query + '&restored=' + restored.time;
      history.replaceState('', {}, updated.state);
    }
  }
})({
  expireDays : 30
});
MktoForms2.loadForm("//app-lon07.marketo.com", "041-BQO-927", 1043);</script>

 

SanfordWhiteman
Level 10 - Community Moderator

Re: UTM parameters not populating into utm fields

The former.

Inga_Romanoff
Level 3 - Champion Alumni

Re: UTM parameters not populating into utm fields

I am a little late to the party here... we developed a solution (with someone's help on this thread!) which we used to distribute open source. It's now a one-time affordable install fee and includes a workshop on taxonomy / tracking utm parameters.

Yes-without a special code, you are lucky to capture Last Touch, but only and only if the lead landing on the web page fills out the form right away. If they flipped through a couple of pages and came back to fill out the form, they will inevitably lose all utm parameters. We utilize javascript to capture this information and then, it's automatically disseminated into marketo fields. (But our solution will record both First Touch and Last Touch; First Touch is especially useful to those in tradition B2B models as the lead lifecycle is longer).

Check the solution out on our site or on Launchpoint or let me know if you have any questions!

http://romanoff.live/solutions

tracking marketing attribution - ConversionPath » Marketo LaunchPoint®

Anonymous
Not applicable

Re: UTM parameters not populating into utm fields

Also late to the party, but for about a year now, I have been using this code from this Digital Pi article ​with zero problems.

It creates a cookie that stores a visitor's UTM parameters (you can also change the parameters to be any custom parameters - just make sure that what you put in the urls matches what the script is looking for), and those values persist for 365 days or until new values overwrite them. This is important for people who click a link to a landing page, but subsequently navigate around to other pages or maybe come back during separate session.

One word of caution there: if you send someone a link with an incomplete set of parameters (say you just input medium, source, campaign, but left term and content blank) the new values will overwrite, but the old values will stay the same, meaning when that visitor submits a form you'll have inaccurate information on the content + term.

The instructions are pretty clear around setting up your form and implementing the code, but just make sure you're loading the script in the body below the form and swapping out the domain (if you want to use on subdomains and main site, you'll need to use ".yoursite.com") or custom parameter names that you want to use.

Also, its easy to overlook the link to the actual code in that article, which is here.