Middlewares

Monetate

🧭 Overview

The monetate.global.ts middleware handles page tracking and data events for Monetate and Algolia. It ensures that page views, product views, and other interactions are pushed to the Monetate tracking system based on route metadata and path patterns.


📄 Code Summary

This middleware runs only on the client side and is responsible for:

  • Detecting page types like home, category, product, etc.
  • Sending view and event data to Monetate and Algolia.
  • Handling safe routes like /trolley, /account/home, and /search.
  • Automatically identifying taxonomy/category pages.

🧩 Key Constants

SAFE_ROUTES

Defined paths to detect common route types:

const SAFE_ROUTES = {
  trolley: "/trolley",
  orderConfirmation: "/order-confirmation",
  myAccount: "/account/home",
  categories: "/categories",
  search: "/search",
};

PAGE_TYPE_MAPPING

Static route mapping to page types understood by Monetate:

const PAGE_TYPE_MAPPING = {
  "/": "main",
  "/login": "login",
  "/checkout": "checkout",
  "/register": "register",
  "/contact": "contact",
  // ...and more
} as const;

🔧 Behavior Summary

ConditionEvent / ActionPage Type
layout === productSends product view eventsproduct
to.path in PAGE_TYPE_MAPPINGMaps route to known Monetate page typemapped type
to.path === '/'Marks homepage viewmain
to.path includes /categoriesSets as taxonomy category viewtaxonomy
Matches /x/x/c123 patternSends PLP view eventtaxonomy
Includes /trolley, /search, etc.Sends respective tracking eventscontextual

📝 Notes

  • Works only on process.client (browser-side only).
  • Calls methods from monetateService, useAlgoliaEvent, and utility helpers.
  • Uses window.monetateQ for queuing and sending tracking events.

✅ Example Usage

// Inside your layout/page:
definePageMeta({
  middleware: ["monetate"],
});

📚 Learn More


Copyright © 2026