Forked from thomasgriffin/gist:62689c45fa4bf7b6cb31
Last active
August 29, 2015 14:15
-
-
Save ericakfranz/d481791053c8eb3c9625 to your computer and use it in GitHub Desktop.
Custom action hook for custom conversion tracking in Canvas in OptinMonster.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($){ | |
$(document).on('click', '.om-custom-html-form a button', function(e){ | |
// Prepare variables. | |
var $this = $(this), | |
optin = $this.closest('.optin-monster-overlay').attr('id').replace('om-', '').replace('-', '_'); | |
if ( ! window[optin] ) { | |
return; | |
} | |
// Send ajax request to track the optin. | |
var data = { | |
optin_monster_ajax_action: 'track_optinmonster_custom', | |
id: window[optin].getProp('id') | |
}; | |
$.post(window[optin].getProp('ajax'), data, function(res){}, 'json'); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'optin_monster_ajax_action', 'tgm_om_custom_tracker', 10, 2 ); | |
function tgm_om_custom_tracker( $action, $data ) { | |
// If not our action, do nothing. | |
if ( 'track_optinmonster_custom' !== $action ) { | |
return; | |
} | |
// If our ID is not passed, do nothing. | |
if ( empty( $data['id'] ) ) { | |
return; | |
} | |
// Load our interfaces and track the conversion. | |
if ( ! class_exists( 'Optin_Monster_Track_Datastore' ) ) { | |
require plugin_dir_path( Optin_Monster::get_instance()->file ) . 'includes/global/track-datastore.php'; | |
} | |
$track = new Optin_Monster_Track_Datastore( absint( $data['id'] ) ); | |
$track->save( 'conversion' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment