Moodle
Add Rybbit 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 snippet goes.
Get your tracking snippet
In your Rybbit dashboard, open Site Settings → Tracking Script and copy your snippet. It looks like this:
<script src="https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>YOUR_SITE_ID is the numeric ID of your site. If you self-host Rybbit, app.rybbit.io is the domain of your own instance.
Add the snippet to Moodle
- Log in as an administrator and go to Site administration → Appearance → Additional HTML.
- Paste the snippet into Within HEAD.
- Click Save changes.
The snippet now loads on every page, including course pages, activities and the login page. Users must be able to reach app.rybbit.io from their browser; nothing is proxied through the Moodle server.
Verify installation
Open your live site in a new tab and click through a few pages. Within a few seconds the pageviews appear in the Rybbit dashboard.
If nothing shows up:
- View the page source and search for
script.js?siteId=to confirm the snippet is on the page. - Open the browser Network tab and check that
script.jsreturns200and thatPOSTrequests go to/api/track. - Disable ad blockers, or set up a proxy so the script loads from your own domain.
- See the script troubleshooting guide for other common causes.
Track custom events
Moodle renders standard HTML, so data-rybbit-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-rybbit-event="course_open" data-rybbit-prop-course="42">
Open course
</a>For enrolment or completion events, call window.rybbit.event() from a small block of JavaScript placed in the When BODY is closed field of the same Additional HTML page.
Troubleshooting
- Snippet saved but not in the page source: Moodle caches rendered output. Go to Site administration → Development → Purge caches and reload.
- Pages inside the mobile app are not tracked: the Moodle app renders course content in its own WebView with its own pages; the Additional HTML setting only affects the web site.
- Snippet pasted into Custom CSS: theme settings such as Boost's Raw SCSS only accept styles. Use Additional HTML for script tags.
Next steps
- Track custom events such as signups, purchases and button clicks.
- Identify users to connect sessions to accounts.
- Proxy the script through your own domain to bypass ad blockers.
- Script attributes let you skip or mask URLs and tag events.