Magento
Last changed
Installing the recapi module on Magento 2, what differs on Magento once it runs, its three usual problems, past orders and settings.
In short
- recapi for Magento is a module. It counts product views and add-to-carts in the browser, sends orders from your server, and describes your products to recapi with nothing to write.
- On product pages, recapi's row ("You may also like") takes the place of Magento's Related Products; up-sells stay. The row is never empty: until recapi has recommendations, it shows the product's related products and up-sells, then other products of its categories.
- It needs Magento Open Source or Adobe Commerce 2.4.7 or later (on-premises or on Cloud, PaaS), or Mage-OS 1.0.6 or later, on PHP 8.2 or later. It works on Luma and Hyvä and their child themes.
- Each product's id (the ID column under Catalog → Products) is its id in recapi.
- For what you should see after installing and for shared problems, read troubleshooting.
- For an accessibility audit: the statement.
What the module sends and shows
- "Often bought together" shows under the row. Turn it off under Stores → Configuration → Sales → recapi.
- A row with none of your products to show holds its place with blank cards from the first paint: the page stays still while recapi's cards load. Without recapi, that space goes after 4 seconds. From module 0.4.43.
- Your home page shows Recently viewed at the end of its content, for a shopper who opened products before. Nothing to set. Remove Magento's own Recently Viewed Products widget there, or there are two.
- A product that can't be bought shows the row in its own box, higher up, as "Other products in stock", without "Often bought together". From module 0.4.35.
- Each order line carries its paid amount, net of discounts, excluding tax and shipping, in
the order's currency, which gives your test its sales per visitor. From module 0.4.29: update it (
composer update recapi/module-recommendations, or the quick start's download lines). - The full-page cache keeps working: product pages print nothing about the visitor.
Adobe Commerce as a Cloud Service (SaaS) installs no modules. There, use the script tag from the quick start for views, clicks and the row, and send each order from your own back end.
Install
- The module. From your Magento root, run the quick start's lines (/app/quickstart, Magento):
composer require recapi/module-recommendations,bin/magento module:enable Recapi_Recommendations, thensetup:upgrade,setup:di:compileandcache:flush. Without Composer, its other lines download the module intoapp/codeinstead, with your API's address already in them. - The keys. In your Magento admin, open Stores → Configuration → Sales → recapi and paste the API address, your public key and a secret key from Set up → Quickstart, step 1. Set them per store view if two store views are two recapi shops. Until all three are filled in, nothing is sent.
- The catalog. Send your products now rather than tonight:
bin/magento recapi:sync-catalog
Notes on installing
setup:di:compileis needed only in production mode.- Install the module one way only: a copy in
app/codeand one installed with Composer register the same module twice, and Magento stops with "Module 'Recapi_Recommendations' … has been already defined". To move to Composer, deleteapp/code/Recapifirst. - The row's code and the visit counting are served by recapi, so each fix of ours to them reaches your store within a day, with nothing to install again. If the quick start says your store runs a module installed before that, install it once more.
After ten minutes
On top of what every store sees after installing, on Magento:
- The row shows up to 4 products that are visible in the catalog and in stock. Until recapi has a list for that page, it keeps your store's own products; recapi's cards replace them once it has some.
- Until updated to 0.4.33, the module may open the row with something the customer just ordered.
- "Often bought together" never falls back to your store's own products. Modules before 0.4.25 show its title everywhere until updated.
- A test order shows one purchase per order line on Live events. From a browser where you opened the Magento admin, or the quick start's link, it is not counted in your numbers. Set up → Your data (/app/import) lists the products the sync sent.
The three usual problems
"The row only ever shows my own products"
Cause. One of the three settings on Stores → Configuration → Sales → recapi is missing or wrong, for this store view. Until all are filled in, the module sends nothing and the row keeps your store's products.
Fix. Paste the API address, the public key and a secret key again, in the right store view's scope, and flush the cache. Then open a product page.
Check. The Send your first events step leaves Waiting and the view shows on Live events. If calls are refused, see troubleshooting.
"Events arrive, but every visitor sees popular items"
Cause. With Cookie Restriction Mode on, recapi keeps a visitor id only once the visitor accepts your cookie notice. A consent module of your own that doesn't accept through Magento's notice never gives that consent, so events arrive without an id and train nothing.
Fix. Open Stores → Configuration → General → Web → Default Cookie Settings. With Cookie Restriction Mode on, check that your store shows Magento's cookie notice, or that your consent module accepts through it. Turn the mode off only if your store needs no notice. Then accept the notice on your store and view a product.
Check. See the visitor id warning.
"Sold-out or new products are wrong in the row"
Cause. Each product saved one by one is sent at once. Since module 0.4.38, an order that takes a product's last unit takes it out of the row within a minute. A product that sells out or comes back through an import or your stock system follows within 15 minutes. Other changes from mass updates and imports reach recapi with the nightly sync, at 03:17. The order's own path runs as the order is placed; the other two run from Magento's cron: if it doesn't run, they never do.
Fix. Make sure Magento's cron runs, and after an import run:
bin/magento recapi:sync-catalog
It prints how many products recapi stored. If recapi refuses a batch, the command fails and names the refusal.
Check. On Set up → Your data (/app/import), open Your items and search for the product: Active says no once it is sold out, disabled or out of the catalog.
Past orders
Past orders let recommendations learn from your sales from day one, and never count as live traffic in the dashboard's checks.
From the Magento root, once:
bin/magento recapi:send-orders
It sends the default store view's orders of the last 90 days, except cancelled ones and those still waiting for payment, from module 0.4.42:
- one purchase per product line (a configurable product's line, as the shop shows it), dated when the order was placed, with what the line paid, net of discounts, in the order's currency;
- the customer id as the buyer; a guest's email never leaves the store: the buyer is
magento-and a hash of the lowercased email keyed with your store's own encryption key, so one guest's orders train as one buyer and nobody without the key can test an address; an order without an email trains as one visitor,magento-order-<order number>; - each line with the id
magento-line-<line id>, 1,000 lines a request, retried when recapi asks to wait.
Run it again whenever you like: recapi skips the lines it already has, and the orders the module sent live as they
were placed (import). It ends with what was stored and skipped, for example
recapi stored 4 purchases from 3 orders; 2 it already had.
Other ways, for orders of another store view or from another system:
| Way | How |
|---|---|
| A file | Upload a CSV with the header user_id,item_id,level,timestamp, one line per product bought, at level 10. A Magento shop's Your data page shows the command instead of the form: open the form at /app/import?platform=site. |
| From your server | Send up to 90 days of them, with their timestamp, to POST /v1/events:import with your secret key (import). The body is the same as /v1/events, up to 20,000 events a second; faster, a batch gets 429: send it again after a second. |
Settings
- Stores → Configuration → Sales → recapi: the API address, public key and secret key, per store view. None by default. The catalog sent is the default store view's.
- Cookie Restriction Mode (Stores → Configuration → General → Web → Default Cookie Settings): on, nothing is stored on the visitor's device until they accept the cookie notice. A visitor whose browser asks not to be tracked (Do Not Track, Global Privacy Control) is not followed: nothing is stored and no event is sent about them, their orders included (consent).
- The row. Restyle it in your theme's CSS through
#recapi-recommendations(a,img,.recapi-price). Rename it with the layout argumentheading, or bring Magento's Related Products back by removing recapi's block in your theme'scatalog_product_view.xml:
<referenceBlock name="recapi.recommendations" remove="true"/>
-
Sales. A product whose regular price is above its final price shows the regular one struck through (
.recapi-was), as your theme's product lists do: your store's own figure. Recapi computes no reduction; the nightly sync drops the old price once the sale ends. A configurable product shows none, as Magento's lists don't. -
Placements and lift test. These live on your dashboard; each row's placement name is in concepts. Before module 0.4.20 every row was
default, and asked for 6 products to show 4.