woocommerce/packages/js/tracks
Chi-Hsuan Huang edbfd5bf93
Merge pull request #32937 from woocommerce/update/convert-woo-tracks-to-ts
Convert `@woocommerce/tracks` to TS
2022-05-11 09:57:27 +08:00
..
changelog Merge pull request #32937 from woocommerce/update/convert-woo-tracks-to-ts 2022-05-11 09:57:27 +08:00
src Convert @woocommerce/tracks to TS 2022-05-10 15:29:07 +08:00
typings Convert @woocommerce/tracks to TS 2022-05-10 15:29:07 +08: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
composer.json Packages: Add Changelogger scripts (#32813) 2022-05-05 15:26:36 +12:00
composer.lock Packages: Add Changelogger scripts (#32813) 2022-05-05 15:26:36 +12:00
package.json Convert @woocommerce/tracks to TS 2022-05-10 15:29:07 +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 Added EOF Newlines 2022-05-10 13:35:31 -07:00
tsconfig.json Convert @woocommerce/tracks to TS 2022-05-10 15:29:07 +08: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:*' );