Skip to content

Commit

Permalink
Post list: Add track events for quick links and stats
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanUngureanu committed Jan 9, 2025
1 parent 9a36c92 commit 2c3c821
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added
Comment: Adds tracking for post list quick links and post stats for WPCOM


Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public static function load_wpcom_user_features() {
require_once __DIR__ . '/features/help-center/class-help-center.php';
}
require_once __DIR__ . '/features/pages/pages.php';
require_once __DIR__ . '/features/posts/posts.php';
require_once __DIR__ . '/features/replace-site-visibility/replace-site-visibility.php';
require_once __DIR__ . '/features/wpcom-admin-bar/wpcom-admin-bar.php';
require_once __DIR__ . '/features/wpcom-admin-interface/wpcom-admin-interface.php';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* Post list tracking.
*
* @package automattic/jetpack-mu-wpcom
*/

/**
* Add tracking for the post list quick links.
*
* @return void
*/
function wpcom_add_tracking_for_posts_lists() {
global $post_type;

?>
<script>
document.querySelectorAll( '.column-primary .row-actions span' ).forEach( ( span ) => {
span.addEventListener( 'click', (event) => {
let name = event.currentTarget.className;

// Classic editor sets the class to "0".
if ( '0' === name ) {
name = 'classic-editor';
}

// Handle Quick inline edit.
if ( 'inline hide-if-no-js' === name ) {
name = 'quick-edit';
}

const props = {
post_type: '<?php echo esc_html( $post_type ); ?>',
section: name,
}

window._tkq.push( [ 'recordEvent', 'wpcom_post_list_quick_links_clicked', props ] );
} );
} );
</script>

<?php
}

add_action( 'admin_print_footer_scripts-edit.php', 'wpcom_add_tracking_for_posts_lists' );

/**
* Adds event for stats clicks in the post list (for pages and post types).
*
* @return void
*/
function wpcom_post_list_add_stats_tracking() {
global $post_type;

if ( ! in_array( $post_type, array('post', 'page') ) ) {

Check warning on line 55 in projects/packages/jetpack-mu-wpcom/src/features/posts/post-list-tracking.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Not using strict comparison for in_array; supply true for $strict argument. (WordPress.PHP.StrictInArray.MissingTrueStrict)

Check failure on line 55 in projects/packages/jetpack-mu-wpcom/src/features/posts/post-list-tracking.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Expected 1 space after the array opener in a single line array. Found: no spaces (NormalizedArrays.Arrays.ArrayBraceSpacing.SpaceAfterArrayOpenerSingleLine)

Check failure on line 55 in projects/packages/jetpack-mu-wpcom/src/features/posts/post-list-tracking.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Expected 1 space before the array closer in a single line array. Found: no spaces (NormalizedArrays.Arrays.ArrayBraceSpacing.SpaceBeforeArrayCloserSingleLine)
return;
}
?>
<script>
document.querySelectorAll( '#the-list .stats a' ).forEach( ( link ) => {
link.addEventListener( 'click', () => {
const props = {
post_type: '<?php echo esc_html( $post_type ); ?>',
}

window._tkq.push( [ 'recordEvent', 'wpcom_post_list_stats_clicked', props ] );
} );
} );
</script>
<?php
}

add_action( 'admin_print_footer_scripts-edit.php', 'wpcom_post_list_add_stats_tracking' );
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

Check failure on line 1 in projects/packages/jetpack-mu-wpcom/src/features/posts/posts.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Missing file doc comment (Squiz.Commenting.FileComment.Missing)
/**
* Load various customizations for post lists.
*
* @package automattic/jetpack-mu-wpcom
*/

require_once __DIR__ . '/post-list-tracking.php';

0 comments on commit 2c3c821

Please sign in to comment.