woocommerce/packages/js/tracks
Christopher Allford 95bc1189e5
Update `wireit` & Optimize Builds (#43595)
This bumps the version to 0.14.3 so that we can take advantage of some
upstream improvements. It also makes some changes to the way our
builds and watches work to minimize the number of unnecessary
Node processes involved in the execution.
2024-01-15 14:06:55 -08:00
..
changelog Update `wireit` & Optimize Builds (#43595) 2024-01-15 14:06:55 -08:00
src Add `recordEvent` validation to Tracks package (#34005) 2022-09-01 13:34:42 -03:00
typings Add `recordEvent` validation to Tracks package (#34005) 2022-09-01 13:34:42 -03: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 Prepare Packages for Release (#33776) 2022-07-08 14:04:49 +12:00
PREVIOUS_CHANGELOG.md Update JS packages changelogs (#33412) 2022-06-16 10:06:31 +12:00
README.md Moved WCA Packages 2022-03-18 14:25:26 -07:00
composer.json bump php version in packages/js/*/composer.json (#42020) 2024-01-04 10:18:34 -04:00
composer.lock Update changelogger to 3.3.0 to support PR number capturing with merge (#36266) 2023-01-05 14:42:51 +05:30
package.json Update `wireit` & Optimize Builds (#43595) 2024-01-15 14:06:55 -08:00
tsconfig-cjs.json Enforce Strict `@types` Dependencies (#37351) 2023-03-23 18:02:20 -07:00
tsconfig.json Enforce Strict `@types` Dependencies (#37351) 2023-03-23 18:02:20 -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:*' );