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.

Maintainers

Package info

github.com/actuatedigital/module-salesfire-hyva

Language:HTML

Type:magento2-module

pkg:composer/actuatedigital/module-salesfire-hyva

Transparency log

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-07-22 10:04 UTC

This package is auto-updated.

Last update: 2026-07-22 10:35:10 UTC


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:

  1. The Salesfire beacon + product/transaction data (via \Salesfire\Formatter) — theme agnostic, works fine in Hyvä.
  2. require(['sfgetid'], …) — bootstraps the Salesfire customer id.
  3. 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.jsdefine(['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\Script extends Salesfire\Salesfire\Block\Script and overrides initSfGetIdScript() / initSfAddToCartScript() to render the two templates above.
  • view/frontend/layout/hyva_default.xml removes the original salesfire_script block and adds the subclass. The hyva_default layout 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 (module Salesfire_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 defined errors from the Salesfire head script.
  • localStorage.getItem('sf_cuid') is populated and window.sfDataLayer contains a session.id entry.
  • Adding/removing a cart item pushes an ecommerce.add / ecommerce.remove entry into window.sfDataLayer.

Licence

MIT © Actuate Digital