Skip to content

Instantly share code, notes, and snippets.

@lukebussey
Last active February 8, 2016 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukebussey/c1aeb4113e90c519d522 to your computer and use it in GitHub Desktop.
Save lukebussey/c1aeb4113e90c519d522 to your computer and use it in GitHub Desktop.
$(document).ready(function () {
var getCookieForMarketo = function (name) {
if (arguments.length === 0 && typeof opts !== 'string') {
return;
}
var match = document.cookie.match('(?:^|; )' + name + '=([^;]+)');
if (match) {
return match[1];
} else {
return 'NULL';
}
};
if (typeof MktoForms2 === 'object') {
MktoForms2.whenReady(function (form) {
// Add hidden fields
form.addHiddenFields({
UTMCampaign: getCookieForMarketo('utm_campaign'),
UTMSource: getCookieForMarketo('utm_source'),
UTMMedium: getCookieForMarketo('utm_medium'),
UTMTerm: getCookieForMarketo('utm_term'),
UTMContent: getCookieForMarketo('utm_content')
});
// Send an event to GA then redirect to destination URL after 200ms
form.onSuccess(function (form, url) {
ga('send', 'event', 'Landing Pages', 'Form Filled', 'Name of Landing Page', {
hitCallback: function () {
window.location.href = url;
}
});
return false;
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment