Skip to content

Instantly share code, notes, and snippets.

@atwellpub
Created July 19, 2014 20:04
Show Gist options
  • Save atwellpub/3b845b3b6dc09bf07427 to your computer and use it in GitHub Desktop.
Save atwellpub/3b845b3b6dc09bf07427 to your computer and use it in GitHub Desktop.
Call to Action link tracking support for LeadBoxes Plugin
<?php
/**
* Call to Action Support for LeadBoxes
* adds click tracking listeners to call to action links containing the 'leadbox-track-me' class id.
*/
add_action('wp_footer' , 'inbound_cta_leadboxes_tracking');
function inbound_cta_leadboxes_tracking() {
?>
<script type='text/javascript'>
jQuery( document ).ready( function() {
jQuery("body").on('click', '.leadbox-track-me', function (e) {
var cta_id = jQuery(this).attr("data-event-id");
var vid = jQuery(this).attr("data-cta-variation");
e.preventDefault(); // halt normal form
jQuery.ajax({
type: 'POST',
url: ajaxurl,
timeout: 10000,
data: {
action: 'wp_cta_record_conversion',
cta_id: cta_id,
variation_id: vid
},
success: function(data){
return true;
},
error: function(MLHttpRequest, textStatus, errorThrown){
return true;
}
});
});
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment