A personal community project under @kyletaylored, MIT licensed.Not provided or supported by Datadog.
WooCommerce
Cart, checkout and order events from WooCommerce's own storefront DOM events, plus order data printed on the order-received page.
Maintainercommercev0.1.0schema 1.0.0
Install
import { datadogRum } from '@datadog/browser-rum'
import { wooCommercePlugin } from '@kyletaylored/datadog-rum-plugin-woocommerce'
datadogRum.init({
applicationId, clientToken, site, service, env, version,
plugins: [wooCommercePlugin()],
})<script src="https://www.datadoghq-browser-agent.com/<site>/v6/datadog-rum.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@kyletaylored/[email protected]/dist/plugin.js"
integrity="sha384-REPLACE_WITH_THE_HASH_FROM_THE_RELEASE" crossorigin="anonymous"></script>
<script>
DD_RUM.init({ /* ... */, plugins: [DD_RUM_PLUGINS['woocommerce']()] })
</script>The CDN URL is pinned to an exact version and needs the integrity hash from that release; there is no auto-updating latest URL. Platform path: WordPress plugin.
Events this plugin sends
Generated from this adapter's fixture run, not written by hand, so it describes what the code actually does. Attribute types are the schema's.
commerce.add_to_cart
| Attribute | Type |
|---|---|
cart_id | string |
currency | string |
item_count | integer |
items | array |
unique_items | integer |
value | number |
Example from the fixtures
{
"value": 56,
"currency": "USD",
"cart_id": "c1-8f2a",
"items": [
{
"item_id": "TEE-RED-M",
"item_name": "Classic Tee",
"price": 28,
"quantity": 2,
"item_variant": "Red / M",
"item_category": "Shirts"
}
],
"item_count": 2,
"unique_items": 1
}commerce.purchase
| Attribute | Type |
|---|---|
coupon | string |
currency | string |
item_count | integer |
items | array |
payment_type | string |
shipping | number |
shipping_tier | string |
tax | number |
transaction_id | string |
unique_items | integer |
value | number |
Example from the fixtures
{
"transaction_id": "wc_1042",
"value": 100.6,
"currency": "USD",
"tax": 6.2,
"shipping": 4.95,
"coupon": "WELCOME10",
"payment_type": "paypal",
"shipping_tier": "Ground",
"item_count": 3,
"unique_items": 2,
"items": [
{
"item_id": "TEE-RED-M",
"item_name": "Classic Tee",
"price": 28,
"quantity": 2,
"item_variant": "Red / M",
"item_category": "Shirts"
},
{
"item_id": "CAP-BLK",
"item_name": "Logo Cap",
"price": 28.5,
"quantity": 1,
"item_category": "Hats"
}
]
}commerce.remove_from_cart
| Attribute | Type |
|---|---|
cart_id | string |
currency | string |
item_count | integer |
items | array |
unique_items | integer |
value | number |
Example from the fixtures
{
"value": 28.5,
"currency": "USD",
"cart_id": "c1-8f2a",
"items": [
{
"item_id": "CAP-BLK",
"item_name": "Logo Cap",
"price": 28.5,
"quantity": 1,
"item_category": "Hats"
}
],
"item_count": 1,
"unique_items": 1
}Session context it sets
| Property | Example value |
|---|---|
commerce.platform | "woocommerce" |
commerce.plugin_version | "0.1.0" |
commerce.schema_version | "1.0.0" |
store.id | "shop.example.com" |
store.currency | "USD" |
store.locale | "en-US" |
customer.type | "returning" |
What it touches
| Platform globals read | window.ddRumWooCommerce, window.jQuery, document.body |
|---|---|
| Platform events subscribed | wc-blocks_added_to_cart, wc-blocks_removed_from_cart, wc-blocks_product_list_rendered, added_to_cart, removed_from_cart |
| Storage keys written | dd_rum_commerce_seen |
| RUM APIs called | addAction, setGlobalContextProperty, setUser, clearUser |
| Consent source | WP Consent API (via the consent option or a consent plugin) |
Declared by the plugin and checked against its fixture run: the conformance suite fails if the adapter calls a RUM API this list does not mention. Also printed to the console in debug mode.
Options
| Option | Default | Effect |
|---|---|---|
events | none | Allow-list of commerce actions. Every action in the schema by default. |
identifyUsers | true | Call setUser with the WordPress user ID. |
includeEmail | false | Add the customer email to setUser. |
includeName | false | Add the customer name to setUser. |
includeItems | false | Attach items[], capped at 20 entries. |
actionPrefix | "commerce." | Rename the action prefix if the site has its own convention. |
consent | "auto" | auto reads the consent signal, ignore skips the gate, or supply a resolver callback. |
beforeTrack | none | Edit or drop an event before it is sent. |
dataGlobal | "ddRumWooCommerce" | Global holding the server-rendered store, customer and order payload. |
debug | false | Log every mapped event to the console. |
Compatibility and maintainer
| RUM SDK | @datadog/browser-rum@>=7.0.0 <8.0.0 |
|---|---|
| Schema | 1.0.0 · reference |
| Platforms | WooCommerce >=8.0Cart and Checkout blocks. Classic themes are covered through the jQuery added_to_cart event. WordPress >=6.4 |
| Maintainer | Kyle Taylor (@kyletaylored) |
| Source | packages/plugin-woocommerce |
Verify the install
- Pass
debug: trueand reload. Every mapped event prints to the console, along with the plugin's declared footprint.plugins: [wooCommercePlugin({ debug: true })] - Query the RUM Explorer for the first action. It should appear within a minute of the first matching interaction on the site.
@type:action @action.name:commerce.add_to_cart - Reconcile against the platform's own report before trusting the numbers. These are browser-measured and will undercount; the accuracy bar is within 5% of the platform admin over 7 days.