-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrating the tracks-callables.js file to the Tracking package. (#19551)
* Adding the tracks-callables.js file to the Tracking package. Related: Automattic/jetpack#15929 * Adding changelog entry. * Removing the calls to wp_register_script() for the tracks-callable.js file. Removing the jp-tracks-functions slug from the array of script slugs. * Adding changelog entry. * Reverting the changes to class.jetpack.php. It seems we'll still need to enqueue the scripts here. * Adding the register_tracks_scripts() method. This will handle calling the wp_register_script() function for the tracks-callables.js file. In the class.jetpack.php file, replacing the call to the wp_register_script() function with the $tracking->register_tracks_scripts() method. * Calling the $tracking->register_tracks_scripts() method in the search widget. * Register jp-tracks dependency when registering jp-tracks-functions. Rename register function to destinguish it from the jptracks used in enqueue. Update register function to static to not instantiate class. Update dependencies to simplify only needed entries. * Update changelogger entry so Jetpack has changelog entry. * Update the register function to optionally enqueue. Necessary when other packages rely on the script but shouldn't be aware of file location details. * reverse conditional so more intuitive. Co-authored-by: Matthew Denton <matt@mdbitz.com> Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/814434312
- Loading branch information
Showing
6 changed files
with
127 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
79 changes: 79 additions & 0 deletions
79
vendor/automattic/jetpack-tracking/src/js/tracks-callables.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* 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 || []; | ||
|
||
var _user; | ||
var debug = console.error; // eslint-disable-line no-console | ||
|
||
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' ] ); | ||
}, | ||
}; |