Add upstream

This commit is contained in:
root
2019-10-24 00:12:05 +02:00
parent 85d41e4216
commit ac980f592c
3504 changed files with 1049983 additions and 29971 deletions

View File

@@ -0,0 +1,5 @@
<?php
/**
* Deprecated file since 7.5 - Jetpack_Tracks_Client is now autoloaded from 'vendor/automattic/jetpack-tracking/legacy/class.tracks-client.php'
*/
_deprecated_file( basename( __FILE__ ), 'jetpack-7.5' );

View File

@@ -0,0 +1,5 @@
<?php
/**
* Deprecated since 7.5
*/
_deprecated_file( basename( __FILE__ ), 'jetpack-7.5' );

View File

@@ -0,0 +1,5 @@
<?php
/**
* Deprecated file since 7.5 - Jetpack_Tracks_Client is now autoloaded from 'vendor/automattic/jetpack-tracking/legacy/class.tracks-client.php'
*/
_deprecated_file( basename( __FILE__ ), 'jetpack-7.5' );

View File

@@ -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 );

View File

@@ -0,0 +1,76 @@
/**
* This was abstracted from wp-calypso's analytics lib: https://github.com/Automattic/wp-calypso/blob/master/client/lib/analytics/README.md
* Some stuff was removed like GA tracking and other things not necessary for Jetpack tracking.
*
* This library should only be used and loaded if the Jetpack site is connected.
*/
// Load tracking scripts
window._tkq = window._tkq || [];
function buildQuerystring( group, name ) {
var uriComponent = '';
if ( 'object' === typeof group ) {
for ( var key in group ) {
uriComponent += '&x_' + encodeURIComponent( key ) + '=' + encodeURIComponent( group[ key ] );
}
} else {
uriComponent = '&x_' + encodeURIComponent( group ) + '=' + encodeURIComponent( name );
}
return uriComponent;
}
var analytics = {
initialize: function( userId, username ) {
analytics.setUser( userId, username );
analytics.identifyUser();
},
mc: {
bumpStat: function( group, name ) {
var uriComponent = buildQuerystring( group, name ); // prints debug info
new Image().src =
document.location.protocol +
'//pixel.wp.com/g.gif?v=wpcom-no-pv' +
uriComponent +
'&t=' +
Math.random();
},
},
tracks: {
recordEvent: function( eventName, eventProperties ) {
eventProperties = eventProperties || {};
if ( eventName.indexOf( 'jetpack_' ) !== 0 ) {
debug( '- Event name must be prefixed by "jetpack_"' );
return;
}
window._tkq.push( [ 'recordEvent', eventName, eventProperties ] );
},
recordPageView: function( urlPath ) {
analytics.tracks.recordEvent( 'jetpack_page_view', {
path: urlPath,
} );
},
},
setUser: function( userId, username ) {
_user = { ID: userId, username: username };
},
identifyUser: function() {
// Don't identify the user if we don't have one
if ( _user ) {
window._tkq.push( [ 'identifyUser', _user.ID, _user.username ] );
}
},
clearedIdentity: function() {
window._tkq.push( [ 'clearIdentity' ] );
},
};