Search by

perfwatch / module-meta

bwake89

Loads the PerfWatch RUM snippet and adds page-type, page-cacheable, currency and order conversion meta tags for PerfWatch RUM.

Package info

github.com/benwake1/magento2-perfwatch-meta

Type:magento2-module

pkg:composer/perfwatch/module-meta

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.5.0 2026-12-01 20:14 UTC

This package is auto-updated.

Last update: 2026-12-01 20:48:36 UTC


README

A Magento 2 module for PerfWatch RUM. It can load the PerfWatch snippet from the admin (with a switch to turn it on or off per store view), and it adds meta tags to the <head> of frontend pages. Every page gets:

<meta name="page-type" content="product">
<meta name="page-cacheable" content="true">
<meta name="perfwatch-currency" content="EUR">
<meta name="perfwatch:dim:store" content="default">

and the order success page also gets:

<meta name="perfwatch-conversion" content="order" data-value="49.99" data-currency="GBP">

PerfWatch's rum.js reads all of them: page-type becomes the Page type filter, page-cacheable the Full-page cache filter, perfwatch-currency the Currency filter, perfwatch:dim:store a custom dimension with the store view code, and perfwatch-conversion marks the visit as converted for the Conversions page (see What PerfWatch does with it).

Requires Magento 2.4.4+ (PHP 8.1+) with Magento_Csp enabled, as it is by default. Works with Luma, Blank and Hyvä, since all of them render the head.additional block.

It also adds a Server-Timing: fpc;desc=HIT|MISS header to pages from Magento's built-in full-page cache, and a bin/magento perfwatch:release command that marks a deploy in PerfWatch.

Install

With Composer (recommended)

From the Magento root:

composer require perfwatch/module-meta
bin/magento module:enable PerfWatch_Meta
bin/magento setup:upgrade
bin/magento cache:flush

In production mode, also run bin/magento setup:di:compile and bin/magento setup:static-content:deploy after setup:upgrade, as you would for any module.

Composer installs the latest release, ^1.5 for example, so composer update perfwatch/module-meta gets fixes and new settings but never a breaking change. Releases are listed on Packagist and on the repository's Releases page. Each one says what changed.

Without Packagist: straight from GitHub

If your Composer setup only allows packages you've listed, or you want a branch that isn't released yet, add the repository yourself. GitHub's public API is rate-limited without a token, so a CI build may need composer config --global github-oauth.github.com <token>.

composer config repositories.perfwatch-meta vcs https://github.com/benwake1/magento2-perfwatch-meta
composer require perfwatch/module-meta            # the latest release
composer require perfwatch/module-meta:dev-main   # or the main branch, unreleased

Without Composer

Copy a release into app/code/PerfWatch/Meta, then run the same bin/magento commands as above:

mkdir -p app/code/PerfWatch/Meta
curl -fsSL https://github.com/benwake1/magento2-perfwatch-meta/archive/refs/heads/main.tar.gz \
  | tar -xz --strip-components=1 -C app/code/PerfWatch/Meta

For a release, change heads/main to tags/v1.5.0. Updating this way means copying it over again. With Composer, it's one command.

Requirements

  • Magento Open Source or Adobe Commerce 2.4.4 or later, or Mage-OS. Tested end to end on 2.4.8.
  • PHP 8.1 or later. CI runs on PHP 8.2, 8.3 and 8.4.
  • Magento_Csp enabled, as it is by default.
  • A PerfWatch server, with a site added for the store. The site's Install page gives the snippet.

Updating and removing

composer update perfwatch/module-meta
bin/magento setup:upgrade && bin/magento cache:flush

To remove it, run bin/magento module:disable PerfWatch_Meta, then composer remove perfwatch/module-meta and bin/magento setup:upgrade. Its settings stay in core_config_data under perfwatch_meta/. They're harmless, but you can delete them.

To check it, view the source of any page and look in <head>:

curl -s https://your-store.test/ | grep -E 'name="(page-type|page-cacheable|perfwatch-currency)"|/rum\.js'

The conversion tag only appears after a real order, so check it by placing a test order and viewing the source of the success page.

Configuration

Stores > Configuration > PerfWatch > Tracking (default, website and store view scope):

Setting Default What it does
Tracking Snippet > Add the Snippet No Loads PerfWatch's rum.js on every frontend page
Tracking Snippet > Snippet The line from the site's Install page in PerfWatch, or just its URL. Only the rum.js URL is saved
Tracking Snippet > Live Hosts Only add the snippet on these hosts, one per line (*.example.com for every subdomain). Empty adds it everywhere
Tracking Snippet > Status Not a setting: says whether PerfWatch is receiving page views from this scope's snippet, asked when the page opens
Tracking Snippet > Release Don't send a release Or the static content version, which changes on each deploy, sent as data-release
Tracking Snippet > Allow PerfWatch in the Content Security Policy Yes Adds the PerfWatch server to script-src and connect-src
Page Type Tag > Enabled Yes Outputs <meta name="page-type">
Page Cacheable Tag > Enabled Yes Outputs <meta name="page-cacheable">
Page Cacheable Tag > List Non-cacheable Blocks Developer mode only When the page isn't cacheable, adds data-blocks="block.a,block.b" naming the offending blocks
Page Cacheable Tag > Cache Hit Header Yes Adds Server-Timing: fpc;desc=HIT or MISS to pages from the built-in full-page cache
Currency Tag > Enabled Yes Outputs <meta name="perfwatch-currency"> with the currency the visitor is shopping in
Store View Tag > Enabled Yes Outputs <meta name="perfwatch:dim:store"> with the store view code
Conversion Tag > Enabled Yes Outputs <meta name="perfwatch-conversion"> on the order success page
Conversion Tag > Conversion Name order The name shown on the PerfWatch Conversions page
Conversion Tag > Order Value Grand total, base currency Sent as data-value. Also: subtotal in base currency, grand total in the currency the customer paid in, or no value

Default scope only:

Setting What it does
Releases > Deploy Token The site's deploy token from PerfWatch's Install page, for perfwatch:release. Stored encrypted
Releases > PerfWatch Server Where to send releases, when it can't be read from the snippet

Flush the full-page cache after changing these settings, because cached pages keep the tags they were rendered with.

Adding the snippet from the admin

Paste the snippet from PerfWatch's Install page into Tracking Snippet > Snippet, set Add the Snippet to Yes and flush the cache. The module renders the tag itself:

<script async src="https://perf.example.com/rum.js?key=..." data-release="1732701234"></script>
  • Only the URL is kept. On save the module takes the src out of what you pasted, checks it's an https …/rum.js URL with a site key (http is allowed for localhost, 127.0.0.1 and .test hosts), and keeps only the options rum.js reads (key, sample, conv, console, spa, endpoint). Anything else pasted never reaches the storefront.
  • Nothing to paste again. Sample rate, Track conversions, Console messages and Single-page app come from PerfWatch's site settings along with rum.js itself, and stores pick up a change within about five minutes. Older snippets with &sample= or &conv=1 in them still work; the site's settings win.
  • Never counted twice. If the snippet is still pasted into Content > Design > Configuration > HTML Head > Scripts and Style Sheets for that store view, the module adds nothing. Remove it from there (and from any theme file such as default_head_blocks.xml, which the module can't see) to switch over.
  • Staging copies send nothing. Set Live Hosts to the live store's host names. A staging or development copy of the live database keeps the setting but answers on another host, so the module leaves the tag out there and no page views leave the browser. PerfWatch also drops page views from subdomains named like a staging copy (staging., dev., uat., test., preview., demo.) and from the site's staging hosts, unless the site's Count page views from setting lists them. A copy that answers on the live host name itself (a hosts-file override, say) can't be told apart: turn Add the Snippet off there.
  • One site per store view. Set the snippet at store view scope when store views are separate sites in PerfWatch.
  • Full-page cache safe. The tag only depends on store config, the deployed static version and the host, so it's the same for every visitor. The host is part of every full-page cache key (built-in and Varnish).
  • Content Security Policy. Magento 2.4.7 and later enforce the policy on the checkout page, which blocks a script from a host that isn't allowed, so without this the checkout's page views are lost. The module adds the PerfWatch server to script-src (and to connect-src, for the beacon) whenever the snippet is loaded, whether by this module or from the HTML Head. Turn it off if you'd rather list the host in your own csp_whitelist.xml.

How the page type is worked out

The module takes the request's full action name (route_controller_action, which is also the page's most specific layout handle) and maps it:

  1. Exact match from the exactMap list.
  2. Otherwise the longest matching prefix from the prefixMap list.
  3. Otherwise the full action name itself, e.g. contact_index_index.

The result is lowercased and anything other than a-z 0-9 _ - becomes _.

Full action name page-type
cms_index_index home
cms_page_view cms
cms_noroute_index 404
catalog_category_view category
catalog_product_view product
catalogsearch_result_index, catalogsearch_advanced_result search
checkout_cart_index cart
checkout_index_index checkout
checkout_onepage_success, multishipping_checkout_success success
customer_*, sales_order_*, wishlist_*, review_customer_*, newsletter_manage_*, vault_cards_*, downloadable_customer_* account
anything else the full action name

A product or category that doesn't exist is forwarded to cms_noroute_index, so it reports as 404.

Extending the mapping

Both lists are di.xml array arguments on PerfWatch\Meta\Model\PageTypeResolver. Magento merges array arguments across modules, so another module can add or override entries in its own etc/di.xml (add PerfWatch_Meta to that module's <sequence> so its entries win):

<type name="PerfWatch\Meta\Model\PageTypeResolver">
    <arguments>
        <argument name="exactMap" xsi:type="array">
            <item name="contact_index_index" xsi:type="string">contact</item>
            <item name="blog_post_view" xsi:type="string">blog</item>
        </argument>
        <argument name="prefixMap" xsi:type="array">
            <item name="amasty_storelocator_" xsi:type="string">stores</item>
        </argument>
    </arguments>
</type>

How the cacheable flag is worked out

Magento skips the full-page cache for a whole page if any <block> in its merged layout XML has cacheable="false". The module asks the page's own layout object, using Magento\Framework\View\Layout::isCacheable(). That is the same check Magento_PageCache uses to decide whether to cache the page. It looks for //block[@cacheable="false"] in the merged layout XML and counts only blocks that were actually generated, so a block removed with <referenceBlock remove="true"/> doesn't count. <referenceBlock cacheable="false"/> doesn't count either, which matches Magento.

  • true: the page can go into the FPC (Varnish or built-in).
  • false: the page is rendered on every request.

When List Non-cacheable Blocks applies, the same XPath is run on the merged layout and the matching block names that are in the page structure go into data-blocks. The default is Developer mode only, so block names are never exposed in production unless you choose Yes (all modes).

Pages served from the FPC will always show true, because only cacheable pages get stored. Pages that show false are the interesting ones: each of those requests misses the cache.

How conversions are marked

On checkout_onepage_success the module reads the order just placed from the checkout session (the same order Magento's own success page shows) and outputs the conversion name, the chosen order total and that total's currency: the base currency for the base totals, the order currency for "Grand total, currency the customer paid in". On multishipping_checkout_success it outputs the name only, because that checkout places several orders at once.

Only the name, the number and the currency code are sent: no order ID, customer, email or items.

PerfWatch keeps a separate total per currency and never adds them together. The Currency filter uses perfwatch-currency from the page the visit started on, which is the currency the visitor was browsing in. A visitor browsing in EUR on a GBP-base store is filtered as EUR, and their order value shows under GBP with the default setting.

It only counts in PerfWatch once Track conversions is turned on for the site (Site settings); the snippet doesn't change, and stores pick it up within about five minutes. Without it, PerfWatch can't link the success page to where the visit started, and drops the conversion.

Cache hits and misses

With Magento's built-in full-page cache, pages get a Server-Timing header that rum.js sends with the page view, so PerfWatch can split TTFB and LCP into cache hits and misses:

  • fpc;desc=HIT: served from the cache.
  • fpc;desc=MISS: rendered now and stored for next time. The header is added after the page is stored, so it never ends up in the cache.
  • No header: a page the cache doesn't store (not public, or not a 200 or 404). Its page-cacheable tag says why.

With Varnish the built-in cache doesn't run, so set the header in vcl_deliver instead:

if (obj.hits > 0) {
    set resp.http.Server-Timing = "varnish;desc=HIT";
} else {
    set resp.http.Server-Timing = "varnish;desc=MISS";
}

A CDN in front can add its own, such as cdn-cache;desc=HIT; PerfWatch keeps the CDN and server results apart.

Marking releases

Run this at the end of a deploy, after setup:static-content:deploy:

bin/magento perfwatch:release                # named after the static content version
bin/magento perfwatch:release v1.42.0 --note="Checkout refactor"

It posts to PerfWatch's /api/deploys, so the charts show where the release went out and its release page compares before and after (and runs an accessibility scan, if the site asks for one). The token comes from --token, then the PERFWATCH_DEPLOY_TOKEN environment variable, then Releases > Deploy Token. The server comes from --server, then Releases > PerfWatch Server, then the snippet's URL. Without a name, the release is the static content version, the same value Tracking Snippet > Release puts on page views.

Full-page cache safety

  • The tags come from a plain template block (perfwatch.meta) inside head.additional, added on the default handle. They're rendered into the HTML that gets cached, so cached hits carry the tags without extra work.
  • The block has no cacheable="false", no ttl (so no ESI) and isn't private content. The module never makes a page uncacheable.
  • It only uses page-level inputs: the action name, the layout, store config, the store view and the current currency. It doesn't read the session, customer or quote, so a cached copy is correct for every visitor. The current currency is part of Magento's HTTP context, so the full-page cache (built-in or Varnish) already keeps one copy of each page per currency.
  • The conversion tag is the one exception: it reads the checkout session, so it's a separate block (perfwatch.conversion) that is only added on the success page layout handles. Magento never caches success pages, and the block is also cacheable="false" as a safety net, so an order total can never be stored in the full-page cache.

What PerfWatch does with it

  • Full-page cache filter: every dashboard page can be narrowed to cacheable or not cacheable page views.
  • Full-page cache split on each metric page shows the p75 for both groups. It appears once a site sends the tag.
  • Currency filter: every dashboard page can be narrowed to visitors shopping in one currency. It appears once page views carry at least two currencies.
  • Conversions page: visits are grouped by how fast their first page was (LCP, INP, CLS, TTFB) and compared on how often they reached the success page.
  • Overview insight: when at least 5% of page views can't be cached and their TTFB p75 is more than 1.5× that of cacheable pages, the overview flags it and links to those page views.

Page views from before the module was installed show as "(not set)".

Files

registration.php, composer.json
etc/module.xml, etc/config.xml, etc/acl.xml, etc/di.xml
etc/adminhtml/system.xml, etc/frontend/di.xml
Model/Config.php                       config reads, developer-mode gate
Model/Config/Source/ListBlocks.php     No / Yes / Developer mode only
Model/Config/Source/OrderValue.php     which order total is the conversion value
Model/Config/Source/Release.php        what the snippet sends as the release
Model/Config/Backend/Snippet.php       keeps only the rum.js URL from what's pasted
Model/SnippetUrl.php                   parses and checks the rum.js URL
Model/Csp/SnippetPolicyCollector.php   adds PerfWatch to the Content Security Policy
Model/PageTypeResolver.php             action name -> page type
Model/RumStatus.php                    asks PerfWatch whether page views are arriving
Block/Adminhtml/System/Config/Status.php  the Status line in the admin
Plugin/PageCache/ServerTiming.php      Server-Timing HIT / MISS on the built-in full-page cache
Console/Command/Release.php            bin/magento perfwatch:release
Model/CacheabilityInspector.php        isCacheable() + offending block names
ViewModel/PageMeta.php                 builds the page-type, page-cacheable, currency and store tags
ViewModel/Conversion.php               builds the conversion tag from the last order
ViewModel/Snippet.php                  builds the rum.js <script> tag
view/frontend/layout/default.xml       adds the meta and snippet blocks to head.additional
view/frontend/layout/checkout_onepage_success.xml, multishipping_checkout_success.xml
                                       add the conversion block on success pages
view/frontend/templates/meta.phtml     renders the page <meta> tags
view/frontend/templates/conversion.phtml renders the conversion <meta> tag
view/frontend/templates/snippet.phtml  renders the rum.js <script> tag

Development

The unit tests run without a Magento install: Composer pulls the Magento framework packages from the public Mage-OS mirror, so no Marketplace keys are needed.

composer install '--ignore-platform-req=ext-*'
composer test      # PHPUnit, Test/Unit
composer lint      # Magento's coding standard, warnings included
composer analyse   # PHPStan, level 6

GitHub Actions runs all three on PHP 8.2, 8.3 and 8.4 (.github/workflows/ci.yml). They must pass before a pull request merges into main (see .github/rulesets).

Releasing

Versions come from Git tags, not from composer.json, and Packagist picks up a new tag by itself. Follow semantic versioning: a new setting or feature is a minor version, a fix is a patch, and anything that breaks an existing install is a major version.

git switch main && git pull
git tag -a v1.5.0 -m "v1.5.0"
git push origin v1.5.0
gh release create v1.5.0 --generate-notes

Tags can't be moved or deleted once pushed (the release tags ruleset), so check main is green first.

Licence

Copyright (c) 2026 Ben Wake. Free for store owners to use and modify on their own stores under the PolyForm Internal Use License 1.0.0: you can't redistribute or sell it, and the copyright notice must be kept. This is not an open-source licence.