2018-09-17 16:42:04 +00:00
|
|
|
/** @format */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Record an event to Tracks
|
|
|
|
*
|
|
|
|
* @param {String} eventName The name of the event to record, always prefixed with wca_
|
|
|
|
* @param {Object} eventProperties event properties to include in the event
|
|
|
|
*/
|
|
|
|
|
|
|
|
export function recordEvent( eventName, eventProperties ) {
|
2018-10-22 15:56:02 +00:00
|
|
|
if ( ! wcSettings.trackingEnabled || 'development' === process.env.NODE_ENV ) {
|
2018-09-17 16:42:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-06 06:41:53 +00:00
|
|
|
// @todo Should we add validation/whitelist of tracks
|
|
|
|
// @todo Don't send tracks in dev envs maybe based off WP_DEBUG?
|
2018-09-17 16:42:04 +00:00
|
|
|
const event = `wca_${ eventName }`;
|
|
|
|
|
|
|
|
// Should already be initialized via inline ./lib/clicent-assets.php
|
|
|
|
// but just being extra safe
|
|
|
|
window._tkq = window._tkq || [];
|
|
|
|
window._tkq.push( [ 'recordEvent', event, 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 } );
|
|
|
|
}
|