Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Block/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,15 @@ public function isCheckoutStartedPage(): bool
&& $request->getControllerName() === 'index'
&& $request->getActionName() === 'index';
}

public function getPageSection(): ?string
{
$request = $this->getRequest();

return [
'cms/index/index' => 'homepage',
'catalog/category/view' => 'product_collection',
'catalog/product/view' => 'product_details',
][$request->getRouteName() . '/' . $request->getControllerName() . '/' . $request->getActionName()] ?? null;
}
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.3 - 2026-11-03

- Report the page section (homepage, product collection or product details) from Magento's route, so page views, product views and Webchat messages say where they happened.

## 1.0.2 - 2026-10-28

- `bin/magento module:uninstall Hellotext_Tracking --remove-data` now removes the Hellotext integration, its OAuth consumer and token, and the module configuration. Before, Magento skipped the module's uninstall script because the module was not registered in `setup_module`.
Expand Down
24 changes: 24 additions & 0 deletions Test/bridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,30 @@ test('identifies an authenticated customer before storefront events and keeps tr
assert.deepEqual(calls.filter(([name]) => name === 'track').map(([, action]) => action), ['page.viewed', 'product.viewed']);
});

test('sets the page section on the page each initialize builds, before storefront events', async () => {
const sections = [];
let initialize;
const sdk = {
initialize: async () => { sdk.page = { section: null }; },
track: async (action) => { sections.push([action, sdk.page.section]); return { failed: false }; }
};
runBridge({
window: {},
document: {
querySelector: () => productElement({ name: 'Shirt', reference: 'magento:store-one:product:42', sku: 'TS-42', source: 'magento' }),
querySelectorAll: () => [],
addEventListener: () => {}
},
console, Promise, URL, setTimeout,
require: (_deps, callback) => callback(sdk),
define: (_deps, factory) => { initialize = factory(); }
});

initialize({ businessId: 'public-business', apiRoot: 'http://api.lvh.me:3200/v1', pageSection: 'product_details' });
await new Promise(setImmediate);
assert.deepEqual(sections, [['page.viewed', 'product_details'], ['product.viewed', 'product_details']]);
});

test('product observation URL excludes query parameters and fragments', async () => {
const calls = [];
let initialize;
Expand Down
9 changes: 9 additions & 0 deletions Test/init.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ public function getValue($path, $scope = null) { return match ($path) {
if ($block->hasSafeConfig() !== $expected) { throw new \RuntimeException('Checkout route guard failed.'); }
}
echo "Storefront checkout-route guards passed.\n";
foreach ([['cms', 'index', 'index', 'homepage'], ['catalog', 'category', 'view', 'product_collection'],
['catalog', 'product', 'view', 'product_details'], ['cms', 'page', 'view', null], ['catalogsearch', 'result', 'index', null]]
as [$route, $controller, $action, $expected]) {
$context->route = $route;
$context->controller = $controller;
$context->action = $action;
if ($block->getPageSection() !== $expected) { throw new \RuntimeException('Page section mapping failed.'); }
}
echo "Storefront page sections passed.\n";
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hellotext/magento",
"description": "Connect Magento Open Source stores to Hellotext: storefront activity, customer identity, orders and catalog/customer import.",
"type": "magento2-module",
"version": "1.0.2",
"version": "1.0.3",
"license": "proprietary",
"keywords": [
"magento",
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<!-- setup_version registers the module in setup_module, which is the only list Magento reads to run
Setup/Uninstall.php when the module is uninstalled with its data. Declarative schema alone never adds it. -->
<module name="Hellotext_Tracking" setup_version="1.0.2">
<module name="Hellotext_Tracking" setup_version="1.0.3">
<sequence>
<module name="Magento_Catalog"/>
<module name="Magento_CatalogInventory"/>
Expand Down
1 change: 1 addition & 0 deletions view/frontend/templates/init.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ $config = json_encode(
'storeId' => $block->getTrackingStoreId(),
'currency' => $block->getTrackingCurrency(),
'checkoutStarted' => $block->isCheckoutStartedPage(),
'pageSection' => $block->getPageSection(),
]],
JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
);
Expand Down
7 changes: 6 additions & 1 deletion view/frontend/web/js/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ define(['Magento_Customer/js/customer-data', 'Hellotext_Tracking/js/cart-tracker
apiRoot: config.apiRoot,
// Web push needs a service worker served from the store's own origin.
push: false
})).then(function () { session = Hellotext.session; });
})).then(function () {
session = Hellotext.session;
// Initializing builds a new page, so set its section again: every event of this page reports it,
// Webchat messages included.
if (Hellotext.page) { Hellotext.page.section = config.pageSection; }
});
}

function synchronizeSession(Hellotext) {
Expand Down
Loading