woocommerce/plugins/woocommerce-admin/client/lib/tracks.js

45 lines
938 B
JavaScript
Raw Normal View History

/** @format */
/**
* External dependencies
*/
import debug from 'debug';
/**
* Module variables
*/
const tracksDebug = debug( 'wc-admin:tracks' );
/**
* 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
* @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 );
if (
! window.wcTracks ||
'function' !== typeof window.wcTracks.recordEvent ||
'development' === process.env.NODE_ENV
) {
return false;
}
window.wcTracks.recordEvent( eventName, eventProperties );
}
/**
* 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 } );
}