diff options
author | Yury German <blueknight@gentoo.org> | 2019-05-22 01:01:36 -0400 |
---|---|---|
committer | Yury German <blueknight@gentoo.org> | 2019-05-22 01:01:36 -0400 |
commit | 0914c92da22824025992c368c745546e41fbeb84 (patch) | |
tree | 965f6adf3b725e56d559fe4a93eff02281499dcc /plugins/jetpack/_inc/lib/tracks/tracks-ajax.js | |
parent | Deleting plugins for update (diff) | |
download | blogs-gentoo-0914c92da22824025992c368c745546e41fbeb84.tar.gz blogs-gentoo-0914c92da22824025992c368c745546e41fbeb84.tar.bz2 blogs-gentoo-0914c92da22824025992c368c745546e41fbeb84.zip |
Adding Plugins
Updating the following
akismet.4.1.2, google-authenticator.0.52, jetpack.7.3.1
Signed-off-by: Yury German <blueknight@gentoo.org>
Diffstat (limited to 'plugins/jetpack/_inc/lib/tracks/tracks-ajax.js')
-rw-r--r-- | plugins/jetpack/_inc/lib/tracks/tracks-ajax.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/plugins/jetpack/_inc/lib/tracks/tracks-ajax.js b/plugins/jetpack/_inc/lib/tracks/tracks-ajax.js new file mode 100644 index 00000000..911275bd --- /dev/null +++ b/plugins/jetpack/_inc/lib/tracks/tracks-ajax.js @@ -0,0 +1,62 @@ +/* global jpTracksAJAX, jQuery */ +( function( $, jpTracksAJAX ) { + window.jpTracksAJAX = window.jpTracksAJAX || {}; + const debugSet = localStorage.getItem( 'debug' ) === 'dops:analytics'; + + 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, + success: function( response ) { + if ( debugSet ) { + // eslint-disable-next-line + console.log( 'AJAX tracks event recorded: ', data, response ); + } + }, + } ); + }; + + $( document ).ready( function() { + $( 'body' ).on( 'click', '.jptracks a, a.jptracks', function( event ) { + var $this = $( event.target ); + // We know that the jptracks element is either this, or its ancestor + var $jptracks = $this.closest( '.jptracks' ); + // We need an event name at least + 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 ) { + var newTabWindow = window.open( '', target ); + newTabWindow.opener = null; + } + + event.preventDefault(); + + window.jpTracksAJAX.record_ajax_event( eventName, 'click', eventProp ).always( function() { + // Continue on to whatever url they were trying to get to. + if ( url && ! $this.hasClass( 'thickbox' ) ) { + if ( newTabWindow ) { + newTabWindow.location = url; + return; + } + window.location = url; + } + } ); + } ); + } ); +} )( jQuery, jpTracksAJAX ); |