Data Whimsy
  • Home
  • What is Matomo
  • Contact
  • Custom Reports
  • Connect Matomo to other software
  • CLI API etc
  • Matomo Tag Manager Simple Guide
  • Lyn Only
  • Troubleshooting + Deploying Matomo
  • Weird Data
  • Why is data in Matomo giving different numbers than Google Analytics
  • The Dashboard
  • Moving the Data
  • Book Club Forum

Without the dashboard

The top slot of your browser can send requests to Tracking API & Reporting API
The command line of your browser can accept direct Matomo input (e.g. the PHP ./console command).
On this page are a variety of things you can do without ever touching the visual dashboard (Matomo GUI)

Ecommerce methods in Matomo (Javascript)

11/7/2024

0 Comments

 
Question:
In Matomo, which methods are available in Ecommerce to pass information to Matomo, from the data layer of the browser?

Answer:
In Matomo, to track Ecommerce data from the data layer of the browser, several JavaScript methods are available within the Matomo tracking API. These methods enable you to pass product and order-related information efficiently. Here's an overview of the key methods used for Ecommerce tracking:

### 1. **Ecommerce Tracking Methods**
   - **`trackEcommerceOrder(orderId, grandTotal, subTotal, tax, shipping, discount)`**
     - This method is used to track an order after a user completes a purchase. You should call this method with details such as the order ID, total amount, and any applicable taxes, shipping, and discounts.
     - **Parameters:**
       - `orderId`: Unique identifier for the order.
       - `grandTotal`: The total amount of the order (including tax, shipping, etc.).
       - `subTotal`: (Optional) Total value of the items in the order, excluding tax and shipping.
       - `tax`: (Optional) Total tax for the order.
       - `shipping`: (Optional) Shipping cost for the order.
       - `discount`: (Optional) Discount applied to the order.

   - **`addEcommerceItem(sku, name, category, price, quantity)`**
     - This method is used to add items to the cart or an order. Each item added is associated with details such as SKU, product name, category, price, and quantity.
     - **Parameters:**
       - `sku`: The unique identifier for the product (e.g., product code).
       - `name`: (Optional) The name of the product.
       - `category`: (Optional) Category name or hierarchy (e.g., "Clothing > Men > Shirts").
       - `price`: (Optional) Price of the product.
       - `quantity`: (Optional) Quantity of the product being purchased.

   - **`trackEcommerceCartUpdate(grandTotal)`**
     - This method is used to update the cart's total value. Call this whenever the cart's content changes (e.g., adding or removing products).
     - **Parameters:**
       - `grandTotal`: The updated total amount of the cart.

### 2. **Implementation Tips**
   - **Data Layer Integration**: To use these methods with data from a data layer (like in a tag management system), you typically access the data layer variables and pass the values to these methods.
   - **Order of Execution**: Ensure that `addEcommerceItem` is called before `trackEcommerceOrder` to associate all items with the order.
   - **Asynchronous Loading**: If using Matomo asynchronously, make sure that the data layer information is loaded and accessible before calling these methods.

### 3. **Example Usage**
```javascript
// Example: Tracking a purchase with multiple items
_paq.push(['addEcommerceItem',
    "12345", // SKU
    "Running Shoes", // Product name
    "Sports > Running", // Category
    99.95, // Price
    2 // Quantity
]);

_paq.push(['addEcommerceItem',
    "67890", // SKU
    "Running Shorts", // Product name
    "Sports > Running", // Category
    49.95, // Price
    1 // Quantity
]);

// Track the order
_paq.push(['trackEcommerceOrder',
    "ORDER123", // Order ID
    249.85, // Grand Total
    199.85, // Sub Total
    20.00, // Tax
    30.00, // Shipping
    0.00 // Discount
]);
```

These methods should be called in sequence based on the Ecommerce events occurring on your website, like adding items to the cart or completing a purchase.h
h
h

0 Comments



Leave a Reply.

    Author

    Evan Genest

    Archives

    November 2024
    August 2024
    May 2024
    March 2024
    February 2024
    November 2023
    October 2023
    September 2023
    August 2023

    Categories

    All

Powered by Create your own unique website with customizable templates.
  • Home
  • What is Matomo
  • Contact
  • Custom Reports
  • Connect Matomo to other software
  • CLI API etc
  • Matomo Tag Manager Simple Guide
  • Lyn Only
  • Troubleshooting + Deploying Matomo
  • Weird Data
  • Why is data in Matomo giving different numbers than Google Analytics
  • The Dashboard
  • Moving the Data
  • Book Club Forum