Conversion Tracking With Marketo Forms 2.0

Marketo Forms 2.0 allows you to create forms and embed them on any website or landing page. This functionality can also be extended by using a JavaScript API in order to improve user-experience.

One of the most common examples in which the JavaScript API can be used to improve the user experience is by hiding the web form and showing a thank-you message after a successful form submission, instead of redirecting the user to a thank-you page.

This short guide is meant for users with basic programming knowledge and provides an example on how to trigger Oktopost conversions programmatically using Marketo's JavaScript API.

Getting Started

To get started, you will need to make sure the Oktopost tracking code is available on the web page that the form is embedded on.

Once the code is embedded on the web page you're working on, you will have access to the _oktrk JavaScript API. Generally, in order to trigger an Oktopost conversion with JavaScript you would have to trigger the following code:

<script>
_oktrk('send', { 
	tag: 'TAG_NAME'
});
</script>

This code will create a conversion in Oktopost, assuming that the user had previously clicked on an okt.to link. The TAG_NAME can be replaced according to the conversion type you wish to track e.g. Download, Signup etc.

Putting It All Together

To use the code above with Marketo Forms 2.0 JavaScript API you will need to make sure the web form is submitted first using the onSuccess() callback.

By triggering the conversion following a form submission you're enabling Oktopost to capture the lead information entered within the form and associate it with the conversion. Here's a full example:

<script src="//app-xxxx.marketo.com/js/forms2/js/forms2.js"></script>
<form id="mktoForm_1001"></form>
<script>
MktoForms2.loadForm("//app-sjst.marketo.com", "000-XXX-000", 1001, function (form) {
	form.onSuccess(function (values, followUpUrl) {
		_oktrk('send', { 
			tag: 'TAG_NAME'
		});

		return false;
	}
});
</script>

Note that if the conversion code is used without a prior form submission it would result in anonymous conversions in your Oktopost account.

Feedback and Knowledge Base