actuatedigital / module-salesfire-hyva
Hyvä theme compatibility for the Salesfire (Salesfire_Salesfire) Magento 2 module. Replaces the RequireJS/jQuery/Knockout-based sfgetid and cart-tracking scripts with plain, CSP-safe scripts that use Hyvä's private-content-loaded event.
Package info
github.com/actuatedigital/module-salesfire-hyva
Language:HTML
Type:magento2-module
pkg:composer/actuatedigital/module-salesfire-hyva
Requires
- php: >=8.1
- salesfire/magento2: ^1.4
Suggests
- hyva-themes/magento2-theme-module: Required at runtime — this module only activates under the Hyvä theme via the hyva_default layout handle.
README
Hyvä theme compatibility for the Salesfire Magento 2 module (salesfire/magento2,
module Salesfire_Salesfire).
Why this is needed
Salesfire_Salesfire injects a head script (Salesfire\Salesfire\Block\Script) that emits
three things:
- The Salesfire beacon + product/transaction data (via
\Salesfire\Formatter) — theme agnostic, works fine in Hyvä. require(['sfgetid'], …)— bootstraps the Salesfire customer id.window.sfData.currency = …; require(['sfcarttracking'])— bootstraps add/remove‑from‑cart tracking.
Items 2 and 3 rely on RequireJS, and the cart tracker additionally depends on jQuery
and Knockout Magento_Customer/js/customer-data. None of those exist in a Hyvä storefront, so
in Hyvä those two bootstraps throw require is not defined and Salesfire never receives a
customer id or cart events. This breaks Salesfire audiences/personalisation and cart analytics
while leaving the core beacon working — so the failure is easy to miss.
What this module does
It overrides only the two broken emitters with plain, CSP‑nonce'd inline scripts that use Hyvä's native mechanisms:
| Original (Luma) | Hyvä replacement |
|---|---|
sfgetid.js — define(['mage/url']), fetch /salesfire/ajax/sfgetid |
Plain fetch() of the same endpoint (getid.phtml) |
cart-tracking.js — Knockout customerData.get('cart').subscribe |
Listens to Hyvä's private-content-loaded window event and diffs event.detail.data.cart (cart-tracking.phtml) |
The Salesfire beacon and product/transaction payload (item 1) are inherited unchanged from the vendor block — no logic is duplicated and the vendor module is not patched.
How it works
Actuate\SalesfireHyva\Block\ScriptextendsSalesfire\Salesfire\Block\Scriptand overridesinitSfGetIdScript()/initSfAddToCartScript()to render the two templates above.view/frontend/layout/hyva_default.xmlremoves the originalsalesfire_scriptblock and adds the subclass. Thehyva_defaultlayout handle only applies under the Hyvä theme, so a Luma storefront keeps the original RequireJS behaviour untouched — no runtime theme checks.- Inline scripts reuse the CSP nonce already generated by the parent block (Magento ≥ 2.4.7), so they are compatible with a strict Content‑Security‑Policy.
Requirements
salesfire/magento2^1.4(moduleSalesfire_Salesfire)- A Hyvä theme (
hyva-themes/magento2-theme-module) — the module is inert without it.
Installation
Via Composer (once published to your repository / Packagist):
composer require actuate/module-salesfire-hyva bin/magento module:enable Actuate_SalesfireHyva bin/magento setup:upgrade
Or drop the module into app/code/Actuate/SalesfireHyva and run the same
module:enable / setup:upgrade.
Verifying
On the Hyvä storefront, with the browser console open:
- No
require is not definederrors from the Salesfire head script. localStorage.getItem('sf_cuid')is populated andwindow.sfDataLayercontains asession.identry.- Adding/removing a cart item pushes an
ecommerce.add/ecommerce.removeentry intowindow.sfDataLayer.
Licence
MIT © Actuate Digital