woocommerce/packages/js/tracks
Chi-Hsuan Huang 863316ade7
Merge pull request #32518 from woocommerce/update/32516-woocommerce-admin-links
Update woocommerce-admin links to point to woocommerce repo
2022-04-14 13:40:25 +08:00
..
src Moved WCA Packages 2022-03-18 14:25:26 -07:00
.eslintrc.js Add .eslintrc config to each packages 2022-03-29 16:08:07 +08:00
.npmrc Moved WCA Packages 2022-03-18 14:25:26 -07:00
CHANGELOG.md Bumped WCA JS package version numbers 2022-03-22 16:08:24 +08:00
README.md Moved WCA Packages 2022-03-18 14:25:26 -07:00
package.json Merge pull request #32518 from woocommerce/update/32516-woocommerce-admin-links 2022-04-14 13:40:25 +08:00
project.json Add build-watch to most js packages and remove packages watch from woocommerce-admin command 2022-03-30 11:46:12 -03:00
tsconfig-cjs.json Moved WCA Packages 2022-03-18 14:25:26 -07:00
tsconfig.json Moved WCA Packages 2022-03-18 14:25:26 -07:00

README.md

Tracks

WooCommerce user event tracking utilities for Automattic based projects.

Installation

Install the module

pnpm install @woocommerce/tracks --save

Usage

The store must opt-in to allow tracking via the woocommerce_allow_tracking setting. If the store is not opted-in no events be recorded when using the following functions.

recordEvent( eventName, eventProperties )

Record a user event to Tracks.

import { recordEvent } from '@woocommerce/tracks';

recordEvent( 'page_view', { path } )
Param Type Description
eventName String The name of the event to record, don't include the wcadmin_ prefix
eventProperties Object Event properties to include in the event

queueRecordEvent( eventName, eventProperties )

Queue a tracks event.

This allows you to delay tracks events that would otherwise cause a race condition. For example, when we trigger wcadmin_tasklist_appearance_continue_setup we're simultaneously moving the user to a new page via window.location. This is an example of a race condition that should be avoided by enqueueing the event, and therefore running it on the next pageview.

Param Type Description
eventName String The name of the event to record, don't include the wcadmin_ prefix
eventProperties Object Event properties to include in the event

recordPageView( eventName, eventProperties )

Record a page view to Tracks.

Param Type Description
path String Path the page/path to record a page view for
extraProperties Object Extra event properties to include in the event

Debugging

When debugging is activated info for each recorded Tracks event is logged to the browser console.

To activate, open up your browser console and add this:

localStorage.setItem( 'debug', 'wc-admin:*' );