-
Notifications
You must be signed in to change notification settings - Fork 808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Post list: Add track events for quick links and stats #40935
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -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'; | ||
} | ||
mmtr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 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 ] ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is
I think the user is not identified by default when using
See this example for reference. And now that I found that reference, maybe you can use the |
||
} ); | ||
} ); | ||
</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' ), true ) ) { | ||
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,4 @@ | ||
<?php // phpcs:ignore Squiz.Commenting.FileComment.Missing | ||
|
||
|
||
require_once __DIR__ . '/post-list-tracking.php'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work if the user uses the Quick Edit to save a change and then uses a quick link?