ConvertFlow Javascript API examples

Once you've placed ConvertFlow's script on your website, you can access ConvertFlow's client-side API.

How to access a visitor's personalization data

Once ConvertFlow's script has finished loading, you can access a visitor's data after the cfReady event has fired, by calling convertflow.person

jQuery(document).on('cfReady', function() {
   console.log(convertflow.person);
});

Don't want to use jQuery? ConvertFlow fires plain javascript events too.

window.addEventListener("cfReady", function() {
   console.log(convertflow.person);
});

How to help ConvertFlow identify contacts on your website

If you already have collected the email address of your visitor (example: you're using ConvertFlow for logged in users in an app), you can tell ConvertFlow who the person is using the identify function.

Here's a snippet you can use, just replace  EMAIL_ADDRESS_HERE with a string of your contact's email address.

The option "override" can be set to  false if you want ConvertFlow to identify someone, if the visitor isn't already tracked as a contact.

Make sure to run this after the cfReady event by wrapping it with the given event listener.

jQuery(document).on('cfReady', function() {
   convertflow.identify({email: 'EMAIL_ADDRESS_HERE', override: true});
});

How to access contact fields after a form submission

If you need to access the fields collected by ConvertFlow forms upon submission, you access the latest contact data by calling convertflow.person after the cfSubmit event fires.

jQuery(document).on('cfSubmit', function() {
   console.log(convertflow.person);
});

How to initiate ConvertFlow with Javascript (for one-page apps)

If you use ConvertFlow in a one-page application, where navigating the app doesn't initiate an entire page load, you can manually initiate ConvertFlow's campaign targeting logic by calling convertflow.start()

For example, if you use Ruby on Rails, where Turbolinks is used to load only certain parts of pages upon page navigation, you can trigger ConvertFlow's campaign targeting logic to run on page change navigation in the page Turbolinks callback, like so...

jQuery(document).on('page:change', function() {
   convertflow.start()
});