Ecommerce
Add Loogika to PrestaShop
PrestaShop offers no field in its back office where you can paste code for the head. You add the Loogika tag with a module that injects header code, or you paste it into the head.tpl file of your theme. Clear the PrestaShop cache after either method.
Last updated .
What do you need before you start?
Copy your script tag from Site Settings in Loogika, under the Tracking Script tab. It looks like this, with your own 12-character site ID in place of YOUR_SITE_ID:
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
How do you add Loogika with a PrestaShop module?
Install a module that adds custom HTML to the page header, and paste the tag into it. The PrestaShop Addons marketplace lists such modules under names like Custom HTML or Header code.
- In the back office, go to Modules, then Module Manager or Module Catalog, and install the module.
- Open the configuration of the module, paste the tag into its header code field and save.
- Go to Advanced Parameters, then Performance, and click Clear cache.
How do you add Loogika through the theme files?
Paste the tag into the head.tpl template of a child theme. A theme update replaces the files of the parent theme, and changes made there disappear with it.
- With an FTP or SFTP client, or with a file manager, open
/themes/your-theme-name/templates/_partials/head.tpl. - Paste the tag at the end of the file, just before the closing
</head>tag, and save. - Go to Advanced Parameters, then Performance, and click Clear cache.
How do you track purchases in PrestaShop?
Add the code below to the order-confirmation.tpl file of your theme. A module that uses the hook of the order confirmation page can print the same code.
{if isset($order)}
<script>
(function () {
function waitForLoogika(callback, timeout) {
var start = Date.now();
(function check() {
if (window.loogika && typeof window.loogika.event === 'function') {
callback();
} else if (Date.now() - start < timeout) {
setTimeout(check, 100);
}
})();
}
waitForLoogika(function () {
window.loogika.event('purchase', {
transaction_id: '{$order.details.reference}',
value: {$order.totals.total.amount},
currency: '{$order.totals.total.currency}'
});
}, 5000);
})();
</script>
{/if}
Smarty, a template language for PHP, renders the PrestaShop templates. Smarty replaces the $order variables with the reference, the total and the currency of the order before the page reaches the browser.
The waitForLoogika function checks every 100 milliseconds whether the tracking script has loaded, for up to five seconds. The purchase event is then sent even when the confirmation script runs before the tag from the head.
How do you check that Loogika is installed?
Bring up your shop in a separate browser tab and browse a few products. The pageviews show up in the Loogika dashboard within a few seconds. If nothing arrives, open the page source and find script.js?siteId=.
Why does PrestaShop not send data to Loogika?
| Symptom | Fix |
|---|---|
| The page source does not contain the tag | Go to Advanced Parameters, then Performance, and clear the cache. Turn off any module that combines or minifies JavaScript while you test |
| The tag disappeared after a theme update | Move your template changes to a child theme. An update overwrites the files of the parent theme |
| The purchase event is missing | Compare the $order variables in the code with the order-confirmation.tpl file of your PrestaShop version. Then place a test order |
PrestaShop versions do not all use the same names for the $order Smarty variables. A test order shows whether the names in the purchase code match your shop.