OnyxMetric
Integration Guides

Moodle

Add OnyxMetric analytics to your Moodle site

Moodle has an Additional HTML admin setting that adds code to every page without touching the theme. Its Within HEAD field is where the tag goes.

Copy your tracking snippet

In OnyxMetric, open your site's Site Settings and copy the tracking script. It looks like this:

<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>

YOUR_SITE_ID is the numeric ID of your site.

Add the snippet to Moodle

  1. Log in as an administrator and go to Site administration → Appearance → Additional HTML.
  2. Paste the snippet into Within HEAD.
  3. Click Save changes.

The tag now loads on every page, including course pages, activities, and the login page. Browsers must be able to reach app.onyxmetric.com, because nothing is proxied through the Moodle server.

Check that it works

Load your live site and click through a few pages. Pageviews show up in the OnyxMetric dashboard within seconds.

If nothing arrives:

  • View the page source and search for script.js?siteId= to confirm the tag is present.
  • In the browser's Network tab, check that script.js returns 200 and that requests go to /api/track.
  • Turn off ad blockers, or proxy the script through your own domain.
  • Read script troubleshooting for other causes.

Track custom events

Moodle renders standard HTML, so data-onyx-event attributes work anywhere you control markup, for example in a course page's HTML block or a label:

<a href="/course/view.php?id=42" data-onyx-event="course_open" data-onyx-prop-course="42">
  Open course
</a>

For enrollment or completion events, call window.onyx.event() from a small script placed in the When BODY is closed field of the same Additional HTML page.

Troubleshooting

  • Saved but not in the page source: Moodle caches rendered output. Go to Site administration → Development → Purge caches and reload.
  • Mobile app pages not tracked: the Moodle app renders course content in its own WebView. Additional HTML affects the web site only.
  • Snippet pasted into a CSS field: theme settings such as Boost's Raw SCSS accept styles only. Use Additional HTML for script tags.

Next steps

On this page