diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2017-11-20 16:50:38 -0500 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2017-11-20 16:50:38 -0500 |
commit | 159ec5c8052e1d061a430893a4525629849e2589 (patch) | |
tree | 6613f22dab82e5c683141f53b1281e18510896ef /plugins/jetpack/_inc/lib/tracks/tracks-ajax.js | |
parent | Update akismet 4.0.1 (diff) | |
download | blogs-gentoo-159ec5c8052e1d061a430893a4525629849e2589.tar.gz blogs-gentoo-159ec5c8052e1d061a430893a4525629849e2589.tar.bz2 blogs-gentoo-159ec5c8052e1d061a430893a4525629849e2589.zip |
Update jetpack 5.5
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'plugins/jetpack/_inc/lib/tracks/tracks-ajax.js')
-rw-r--r-- | plugins/jetpack/_inc/lib/tracks/tracks-ajax.js | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/plugins/jetpack/_inc/lib/tracks/tracks-ajax.js b/plugins/jetpack/_inc/lib/tracks/tracks-ajax.js index 316aef44..a49aebe5 100644 --- a/plugins/jetpack/_inc/lib/tracks/tracks-ajax.js +++ b/plugins/jetpack/_inc/lib/tracks/tracks-ajax.js @@ -1,26 +1,37 @@ /* global jpTracksAJAX, jQuery */ (function( $, jpTracksAJAX ) { + window.jpTracksAJAX = window.jpTracksAJAX || {}; + + window.jpTracksAJAX.record_ajax_event = function ( eventName, eventType, eventProp ) { + var data = { + tracksNonce: jpTracksAJAX.jpTracksAJAX_nonce, + action: 'jetpack_tracks', + tracksEventType: eventType, + tracksEventName: eventName, + tracksEventProp: eventProp || false + }; + + return $.ajax( { + type: 'POST', + url: jpTracksAJAX.ajaxurl, + data: data + } ); + }; $( document ).ready( function () { $( 'body' ).on( 'click', '.jptracks a, a.jptracks', function( event ) { - // We know that the jptracks element is either this, or its ancestor var $jptracks = $( this ).closest( '.jptracks' ); - var data = { - tracksNonce: jpTracksAJAX.jpTracksAJAX_nonce, - action: 'jetpack_tracks', - tracksEventType: 'click', - tracksEventName: $jptracks.attr( 'data-jptracks-name' ), - tracksEventProp: $jptracks.attr( 'data-jptracks-prop' ) || false - }; - // We need an event name at least - if ( undefined === data.tracksEventName ) { + var eventName = $jptracks.attr( 'data-jptracks-name' ); + if ( undefined === eventName ) { return; } + var eventProp = $jptracks.attr( 'data-jptracks-prop' ) || false; + var url = $( this ).attr( 'href' ); var target = $( this ).get( 0 ).target; if ( url && target && '_self' !== target ) { @@ -29,11 +40,7 @@ event.preventDefault(); - $.ajax( { - type: 'POST', - url: jpTracksAJAX.ajaxurl, - data: data - } ).always( function() { + window.jpTracksAJAX.record_ajax_event( eventName, 'click', eventProp ).always( function() { // Continue on to whatever url they were trying to get to. if ( url ) { if ( newTabWindow ) { @@ -43,7 +50,7 @@ window.location = url; } } ); - }); - }); + } ); + } ); -})( jQuery, jpTracksAJAX ); +} )( jQuery, jpTracksAJAX ); |