Tracking lead source with UTM parameters

Anonymous
Not applicable

Tracking lead source with UTM parameters

I'm looking to track lead source through UTM parameters on our website. Basically, we send all of our traffic to our website, not to Marketo forms. When people land on our website and then click on a contact us button and fill out a form, we want to attribute that to our ads that brought them to the site. Is there a way to do this with UTM tracking? How can we have UTM parameters follow someone around our website? Is there another way to track leads coming from ads that go to our site first and then click from our website to fill out a form? Looking for any and all recommendations.

2 REPLIES 2
Diego_Lineros2
Level 7

Re: Tracking lead source with UTM parameters

If the people lands on contact us page with an utm and fills up the form, they would be redirected to a thank you page, at this point you can track the referral.

So you can create smarts campaigns as follow

pastedImage_1.png

Anonymous
Not applicable

Re: Tracking lead source with UTM parameters

Hi Melissa,

This script saves UTM parameters in your website cookie whenever there are any UTM parameters in the URL, even if it leads to a non-Marketo webpage and the user visits several other pages on your website before filling out a form


var utmCookie = {

  cookieNamePrefix: "",

  utmParams: [

  "utm_source",

  "utm_medium",

  "utm_campaign",

  "utm_term",

  "utm_content"

  ],

  cookieExpiryDays: 365,

  // From http://www.quirksmode.org/js/cookies.html

  createCookie: function (name, value, days) {

  if (days) {

  var date = new Date();

  date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));

  var expires = "; expires=" + date.toGMTString();

  } else

  var expires = "";

  document.cookie = this.cookieNamePrefix + name + "=" + value + expires + "; domain=.abilitynetwork.com; path=/";

  },

  readCookie: function (name) {

  var nameEQ = this.cookieNamePrefix + name + "=";

  var ca = document.cookie.split(';');

  for (var i = 0; i < ca.length; i++) {

  var c = ca[i];

  while (c.charAt(0) == ' ')

  c = c.substring(1, c.length);

  if (c.indexOf(nameEQ) == 0)

  return c.substring(nameEQ.length, c.length);

  }

  return null;

  },

  eraseCookie: function (name) {

  this.createCookie(name, "", -1);

  },

  getParameterByName: function (name) {

  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");

  console.log(name);

  var regexS = "[\\?&]" + name + "=([^&#]*)";

  var regex = new RegExp(regexS);

  var results = regex.exec(window.location.search);

  if (results == null) {

  return "";

  } else {

  return decodeURIComponent(results[1].replace(/\+/g, " "));

  }

  },

  utmPresentInUrl: function () {

  var present = false;

  for (var i = 0; i < this.utmParams.length; i++) {

  var param = this.utmParams[i];

  var value = this.getParameterByName(param);

  console.log(param + ' = ' + value);

  if (value != "" && value != undefined) {

  present = true;

  }

  }

  return present;

  },

  writeUtmCookieFromParams: function () {

  for (var i = 0; i < this.utmParams.length; i++) {

  var param = this.utmParams[i];

  var value = this.getParameterByName(param);

  this.writeCookieOnce(param, value)

  }

  },

  writeCookieOnce: function (name, value) {

  var existingValue = this.readCookie(name);

  if (!existingValue) {

  this.createCookie(name, value, this.cookieExpiryDays);

  }

  },

  writeReferrerOnce: function () {

  value = document.referrer;

  if (value === "" || value === undefined) {

  this.writeCookieOnce("referrer", "direct");

  } else {

  this.writeCookieOnce("referrer", value);

  }

  },

  referrer: function () {

  return this.readCookie("referrer");

  }

};

utmCookie.writeReferrerOnce();

if (utmCookie.utmPresentInUrl()) {

  utmCookie.writeUtmCookieFromParams();

}