2018-09-17 16:42:04 +00:00
|
|
|
/** @format */
|
2019-06-24 23:49:52 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import debug from 'debug';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module variables
|
|
|
|
*/
|
|
|
|
const tracksDebug = debug( 'wc-admin:tracks' );
|
2018-09-17 16:42:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Record an event to Tracks
|
|
|
|
*
|
2019-06-27 02:44:39 +00:00
|
|
|
* @param {String} eventName The name of the event to record, don't include the wcadmin_ prefix
|
2018-09-17 16:42:04 +00:00
|
|
|
* @param {Object} eventProperties event properties to include in the event
|
|
|
|
*/
|
|
|
|
|
|
|
|
export function recordEvent( eventName, eventProperties ) {
|
2019-06-27 02:44:39 +00:00
|
|
|
tracksDebug( 'recordevent %s %o', 'wcadmin_' + eventName, eventProperties );
|
2019-06-24 23:49:52 +00:00
|
|
|
|
2019-03-04 04:08:13 +00:00
|
|
|
if (
|
|
|
|
! window.wcTracks ||
|
|
|
|
'function' !== typeof window.wcTracks.recordEvent ||
|
|
|
|
'development' === process.env.NODE_ENV
|
|
|
|
) {
|
2018-09-17 16:42:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-04 04:08:13 +00:00
|
|
|
window.wcTracks.recordEvent( eventName, eventProperties );
|
2018-09-17 16:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Record a page view to Tracks
|
|
|
|
*
|
|
|
|
* @param {String} path the page/path to record a page view for
|
|
|
|
*/
|
|
|
|
|
|
|
|
export function recordPageView( path ) {
|
|
|
|
if ( ! path ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
recordEvent( 'page_view', { path } );
|
|
|
|
}
|