Skip to content

Instantly share code, notes, and snippets.

@haydenbbickerton
Created January 3, 2016 21:29
Show Gist options
  • Save haydenbbickerton/044df302f4d483617de5 to your computer and use it in GitHub Desktop.
Save haydenbbickerton/044df302f4d483617de5 to your computer and use it in GitHub Desktop.
Ninja Forms ajax submission to AdWords conversion
/*
Put the Google Conversion Code here
*/
/*
Run our conversion logic after form submissions.
I'm using js-cookie(https://github.com/js-cookie/js-cookie)
to handle the cookie, use whatever you want.
*/
jQuery("form[id*='ninja_forms']").on('submitResponse', function(e, response)
{
// Make sure there are no errors, and form went through
if (response.errors == false)
{
/*
We don't want to count 2 conversions if a single person submitted 2 forms, so
we'll set/get a cookie to know who's already been counted
*/
if (typeof Cookies.get('converted') === 'undefined')
{
// Set cookie for this domain, expires in 1 day
Cookies.set('converted', 'true',
{
expires: 1,
domain: 'example.com'
});
// Run our conversion
goog_report_conversion();
}
else
{
// Nothing, they've already been counted
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment