Static site generators
Add Loogika to Hexo
From version 5, Hexo includes an injector API that can insert HTML into the head of each page it generates. You register the Loogika tag in a small file in the scripts folder of your site, so the theme stays untouched. On older Hexo versions you paste the tag into the head partial of the theme.
Last updated .
What do you need before you start?
Find your script tag in the Loogika dashboard. Open Site Settings and pick the Tracking Script tab. Your own 12-character site ID stands where this example says YOUR_SITE_ID:
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
How do you add Loogika with the Hexo injector?
The injector method needs one config entry and one script file. We recommend it on Hexo 5 and later, because a theme update cannot remove the tag.
- Add your site ID to the
_config.ymlfile in the root of the project. The config file inside the theme folder is the wrong place. - Create the file
scripts/loogika.jswith the code below. Create thescriptsfolder if it does not exist. - Regenerate the site and deploy the
publicfolder.
loogika:
site_id: "YOUR_SITE_ID"
Hexo loads every file in the scripts folder at startup and gives it access to the hexo object. The file reads the site ID and registers the tag:
const { site_id: siteId } = hexo.config.loogika || {};
if (siteId) {
hexo.extend.injector.register(
"head_end",
`<script src="https://app.loogika.com/api/script.js?siteId=${siteId}" defer></script>`
);
}
The head_end position places the tag just before the closing </head> tag. The call has no third argument, so the injector applies to every page type.
Regenerate the site with this command, then deploy the public folder:
hexo clean && hexo generate
How do you add Loogika through the theme layout?
On Hexo versions before 5.0 you paste the tag into the head partial of your theme, before the closing </head> tag. The default theme of Hexo stores that partial at themes/landscape/layout/_partial/head.ejs. In another theme, look for a similar partial under layout.
...
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
</head>
A theme update overwrites the head partial and removes the tag with it. If your version of Hexo has the injector, choose that method.
How do you check that Loogika is installed?
Visit the published site in a new tab and open a few posts. Loogika shows the pageviews in the dashboard within a few seconds.
If no pageviews arrive, open the page source and look for script.js?siteId=. A tag that is present but silent is often stopped by an ad blocker. The script troubleshooting page covers that case and other causes.
Why does Hexo not send data to Loogika?
| Cause | Fix |
|---|---|
hexo.extend.injector is undefined | Hexo has had the injector API since version 5.0. Run hexo version to check, then upgrade or use the theme layout method |
| The tag is missing after you added the script file | Hexo keeps rendered output in the db.json cache and can serve old pages from it. Clear the cache with hexo clean, then run hexo generate |
| The site ID sits in the theme config | hexo.config reads the _config.yml file in the project root. Move the loogika block there |
| Local previews show up in the statistics | The injector also runs under hexo server, the same way it does under hexo generate. To avoid local pageviews, keep a local copy of _config.yml where site_id is empty |