-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Post list: Add track events for quick links and stats
- Loading branch information
1 parent
9a36c92
commit 2c3c821
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
projects/packages/jetpack-mu-wpcom/changelog/update-tracking-for-posts-list
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,5 @@ | ||
Significance: patch | ||
Type: added | ||
Comment: Adds tracking for post list quick links and post stats for WPCOM | ||
|
||
|
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
73 changes: 73 additions & 0 deletions
73
projects/packages/jetpack-mu-wpcom/src/features/posts/post-list-tracking.php
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,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 GitHub Actions / PHP Code Sniffer (non-excluded files only)
Check failure on line 55 in projects/packages/jetpack-mu-wpcom/src/features/posts/post-list-tracking.php GitHub Actions / PHP Code Sniffer (non-excluded files only)
Check failure on line 55 in projects/packages/jetpack-mu-wpcom/src/features/posts/post-list-tracking.php GitHub Actions / PHP Code Sniffer (non-excluded files only)
|
||
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' ); |
8 changes: 8 additions & 0 deletions
8
projects/packages/jetpack-mu-wpcom/src/features/posts/posts.php
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,8 @@ | ||
<?php | ||
/** | ||
* Load various customizations for post lists. | ||
* | ||
* @package automattic/jetpack-mu-wpcom | ||
*/ | ||
|
||
require_once __DIR__ . '/post-list-tracking.php'; |