Added event prop 'screen' to be recorded (https://github.com/woocommerce/woocommerce-admin/pull/4643)
* Added event prop to be recorded This commit adds the event prop `screen` to `wcadmin_wcadmin_inbox_action_click` * Getting screen name from referer Now the we get the screen name from the referer * The screen name is not being sent anymore to the API The screen name is not sent anymore to the API. Also, the $screen_name is set as empty in the API to make the method more defensive. * Created method `get_screen_name` This commit moves the code related to getting the screen name to a specific method. * Added screen name recording for individual posts This commits adds screen name recording for individual posts Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
This commit is contained in:
parent
a6195efad6
commit
0d35c1c791
|
@ -12,10 +12,6 @@ import PropTypes from 'prop-types';
|
|||
*/
|
||||
import { ADMIN_URL as adminUrl } from '@woocommerce/wc-admin-settings';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
|
||||
class InboxNoteAction extends Component {
|
||||
constructor( props ) {
|
||||
super( props );
|
||||
|
|
|
@ -17,7 +17,7 @@ import classnames from 'classnames';
|
|||
import { recordEvent } from 'lib/tracks';
|
||||
import './style.scss';
|
||||
import { H, Section } from '@woocommerce/components';
|
||||
import { getUrlParams } from 'utils';
|
||||
import { getScreenName } from 'utils';
|
||||
|
||||
class InboxNoteCard extends Component {
|
||||
constructor( props ) {
|
||||
|
@ -32,7 +32,7 @@ class InboxNoteCard extends Component {
|
|||
this.openDismissModal = this.openDismissModal.bind( this );
|
||||
this.closeDismissModal = this.closeDismissModal.bind( this );
|
||||
this.bodyNotificationRef = createRef();
|
||||
this.screen = this.getScreenName();
|
||||
this.screen = getScreenName();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -62,27 +62,10 @@ class InboxNoteCard extends Component {
|
|||
note_name: note.name,
|
||||
note_title: note.title,
|
||||
note_content_inner_link: innerLink,
|
||||
screen: this.screen,
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
getScreenName() {
|
||||
let screenName = '';
|
||||
const { page, path, post_type: postType } = getUrlParams(
|
||||
window.location.search
|
||||
);
|
||||
if ( page ) {
|
||||
const currentPage = page === 'wc-admin' ? 'home_screen' : page;
|
||||
screenName = path
|
||||
? path.replace( /\//g, '_' ).substring( 1 )
|
||||
: currentPage;
|
||||
} else if ( postType ) {
|
||||
screenName = postType;
|
||||
}
|
||||
return screenName;
|
||||
}
|
||||
|
||||
// Trigger a view Tracks event when the note is seen.
|
||||
onVisible( isVisible ) {
|
||||
if ( isVisible && ! this.hasBeenSeen ) {
|
||||
|
@ -216,6 +199,7 @@ class InboxNoteCard extends Component {
|
|||
label={ __( "Yes, I'm sure", 'woocommerce-admin' ) }
|
||||
actionCallback={ this.closeDismissModal }
|
||||
dismiss={ true }
|
||||
screen={ this.screen }
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
/**
|
||||
* Get the URL params.
|
||||
*
|
||||
* @param {string} locationSearch - Querystring part of a URL, including the question mark (?).
|
||||
* @return {Object} - URL params.
|
||||
*/
|
||||
export function getUrlParams( locationSearch ) {
|
||||
if ( locationSearch ) {
|
||||
return locationSearch
|
||||
|
@ -13,3 +19,25 @@ export function getUrlParams( locationSearch ) {
|
|||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the current screen name.
|
||||
*
|
||||
* @return {string} - Screen name.
|
||||
*/
|
||||
export function getScreenName() {
|
||||
let screenName = '';
|
||||
const { page, path, post_type: postType } = getUrlParams(
|
||||
window.location.search
|
||||
);
|
||||
if ( page ) {
|
||||
const currentPage = page === 'wc-admin' ? 'home_screen' : page;
|
||||
screenName = path
|
||||
? path.replace( /\//g, '_' ).substring( 1 )
|
||||
: currentPage;
|
||||
} else if ( postType ) {
|
||||
screenName = postType;
|
||||
}
|
||||
return screenName;
|
||||
}
|
||||
|
|
|
@ -124,6 +124,7 @@ class NoteActions extends Notes {
|
|||
'note_content' => $note->get_content(),
|
||||
'action_name' => $triggered_action->name,
|
||||
'action_label' => $triggered_action->label,
|
||||
'screen' => $this->get_screen_name(),
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -133,4 +134,33 @@ class NoteActions extends Notes {
|
|||
|
||||
return rest_ensure_response( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get screen name.
|
||||
*
|
||||
* @return string The screen name.
|
||||
*/
|
||||
public function get_screen_name() {
|
||||
$screen_name = '';
|
||||
|
||||
if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
|
||||
parse_str( wp_parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_QUERY ), $queries ); // phpcs:ignore sanitization ok.
|
||||
}
|
||||
if ( isset( $queries ) ) {
|
||||
$page = isset( $queries['page'] ) ? $queries['page'] : null;
|
||||
$path = isset( $queries['path'] ) ? $queries['path'] : null;
|
||||
$post_type = isset( $queries['post_type'] ) ? $queries['post_type'] : null;
|
||||
$post = isset( $queries['post'] ) ? get_post_type( $queries['post'] ) : null;
|
||||
}
|
||||
|
||||
if ( isset( $page ) ) {
|
||||
$current_page = 'wc-admin' === $page ? 'home_screen' : $page;
|
||||
$screen_name = isset( $path ) ? substr( str_replace( '/', '_', $path ), 1 ) : $current_page;
|
||||
} elseif ( isset( $post_type ) ) {
|
||||
$screen_name = $post_type;
|
||||
} elseif ( isset( $post ) ) {
|
||||
$screen_name = $post;
|
||||
}
|
||||
return $screen_name;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue