Skip to content

Commit

Permalink
Admin bar: Track clicks on the launch button (#41425)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Jan 30, 2025
1 parent 6d324b4 commit 4d871c7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Tracking clicks on the admin bar launch button
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { wpcomTrackEvent } from '../../common/tracks';

document.addEventListener( 'DOMContentLoaded', () => {
const launchButton = document.querySelector( '#wpadminbar .launch-site' );
if ( ! launchButton ) {
return;
}
launchButton.addEventListener( 'click', () => {
wpcomTrackEvent( 'wpcom_adminbar_launch_site' );
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* @package automattic/jetpack-mu-wpcom
*/

use Automattic\Jetpack\Jetpack_Mu_Wpcom;
use Automattic\Jetpack\Jetpack_Mu_Wpcom\Common;

/**
* Adds a "launch site" button to the admin bar.
*
Expand Down Expand Up @@ -58,6 +61,15 @@ function wpcom_enqueue_launch_button_styles() {
}
$version = filemtime( __DIR__ . '/style.css' );
wp_enqueue_style( 'launch-banner', plugins_url( 'style.css', __FILE__ ), array(), $version );
$asset_file = include Jetpack_Mu_Wpcom::BASE_DIR . 'build/adminbar-launch-button/adminbar-launch-button.asset.php';
wp_enqueue_script(
'adminbar-launch-button',
plugins_url( 'build/adminbar-launch-button/adminbar-launch-button.js', Jetpack_Mu_Wpcom::BASE_FILE ),
$asset_file['dependencies'] ?? array(),
$asset_file['version'] ?? filemtime( Jetpack_Mu_Wpcom::BASE_DIR . 'build/adminbar-launch-button/adminbar-launch-button.js' ),
true
);
Common\wpcom_enqueue_tracking_scripts( 'adminbar-launch-button' );
}

add_action( 'admin_bar_menu', 'wpcom_add_launch_button_to_admin_bar', 500 );
Expand Down
1 change: 1 addition & 0 deletions projects/packages/jetpack-mu-wpcom/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module.exports = [
'starter-page-templates': './src/features/starter-page-templates/index.tsx',
'removed-calypso-screen-notice':
'./src/features/wpcom-admin-interface/removed-calypso-screen-notice.tsx',
'adminbar-launch-button': './src/features/launch-button/index.js',
},
mode: jetpackWebpackConfig.mode,
devtool: jetpackWebpackConfig.devtool,
Expand Down

0 comments on commit 4d871c7

Please sign in to comment.