Other platforms
Add Loogika to Discourse
You add Loogika to a Discourse forum with a theme component. A component has an editable </head> section, and Discourse places the code from that section on every page. You need no plugin and no access to the server.
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>
You also need an admin account on the forum, because the steps below use the admin area.
How do you add Loogika with a theme component?
- In the admin sidebar, open Appearance, then Themes and components. Older versions list it under Admin, then Customize, then Themes.
- On the Components tab, click Install and choose Create new. Name it Loogika Analytics, check that the type is Component and click Create.
- Click Edit CSS/HTML and stay on the Common tab. Open the
</head>section. Do not pick Header, which is the visible header of the page. - Paste the script tag and click Save.
- Return to the page of the component. Under Include component on these themes, select your active theme, which turns the component on.
Does the Discourse Content Security Policy block Loogika?
No, as long as the tag sits in the </head> section of a theme component. Discourse ships with a strict Content Security Policy, a browser rule that decides which scripts may run. Discourse adds the required nonce, a one-time code, to script tags in that section.
Scripts that reach the page another way do not get the nonce. Raw HTML from a plugin is one example. The browser console shows a Content Security Policy error when such a script is blocked.
Does Loogika count topic and category views?
Yes. Because Discourse works as a single-page app, the browser opens topics and categories with no full page load once the first visit has started. Loogika records each of those route changes as a pageview when SPA Navigation is on in Site Settings. The setting is on for a new site.
How do you check that Loogika is installed?
Open your forum in another tab and visit a few topics. The pageviews show up in the Loogika dashboard within a few seconds. If nothing arrives, work through the table below.
Why does Discourse not send data to Loogika?
| Problem | Cause and fix |
|---|---|
The component is saved, and the page source has no script.js?siteId= | The active theme does not use the component yet. Pick that theme in the Include component on these themes field, or open the theme and add the component in its Included components list |
| The tag is on the page and the console shows a Content Security Policy error | The script was added outside the </head> section and has no nonce. Move the tag into the theme component |
| Only the first pageview of a visit is recorded | SPA Navigation is off for the site. Turn it on in Site Settings in Loogika |