Skip to content

Commit

Permalink
Bring back trackClassicPages params to limit the number of changes
Browse files Browse the repository at this point in the history
and hae a place to document the expected config data structure.
  • Loading branch information
tomalec committed Mar 13, 2024
1 parent 92e96fb commit 7b3ef32
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion assets/js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ function eventuallyInitializeTracking() {
);
}

classicTracking();
classicTracking( config() );
blocksTracking();
}
19 changes: 16 additions & 3 deletions assets/js/src/integrations/classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,23 @@ import { config } from '../config';
* To be executed once data set is complete, and `document` is ready.
*
* It also handles some Block events that are not fired reliably for `woocommerce/all-products` block.
*
* @param {Object} data - The tracking data from the current page load, containing the following properties:
* @param {Object} data.events - An object containing the events to be instantly tracked.
* @param {Object} data.cart - The cart object.
* @param {Object[]} data.products - An array of all product from the current page.
* @param {Object} data.product - The single product object.
* @param {Object} data.added_to_cart - The product added to cart.
* @param {Object} data.order - The order object.
*/
export function classicTracking() {
const { events, cart, products, product, addedToCart, order } = config();

export function classicTracking( {
events,
cart,
products,
product,
added_to_cart: addedToCart,
order,
} ) {
// Instantly track the events listed in the `events` object.
Object.values( events ?? {} ).forEach( ( eventName ) => {
if ( eventName === 'add_to_cart' ) {
Expand Down

0 comments on commit 7b3ef32

Please sign in to comment.