woocommerce/packages/js/tracks
jonathansadowski d48a0b2d90
Add helper tool for making sure build, lint, and test are run through Turborepo (#33573)
* Add helper tool for making sure build, lint, and test are run through Turborepo

* Update node version for require-turbo
2022-06-28 13:17:05 -05:00
..
changelog Add helper tool for making sure build, lint, and test are run through Turborepo (#33573) 2022-06-28 13:17:05 -05: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
.gitignore Update JS packages changelogs (#33412) 2022-06-16 10:06:31 +12:00
.npmrc Moved WCA Packages 2022-03-18 14:25:26 -07:00
CHANGELOG.md Update JS packages changelogs (#33412) 2022-06-16 10:06:31 +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 Add PR numbers to changelog entries on code freeze process (#33627) 2022-06-28 11:15:39 -07:00
composer.lock Add PR numbers to changelog entries on code freeze process (#33627) 2022-06-28 11:15:39 -07:00
package.json Add helper tool for making sure build, lint, and test are run through Turborepo (#33573) 2022-06-28 13:17:05 -05: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:*' );