diff --git a/classes/local/hooks/output/standard_head_html_prepend.php b/classes/local/hooks/output/standard_head_html_prepend.php
new file mode 100644
index 0000000..35d8df4
--- /dev/null
+++ b/classes/local/hooks/output/standard_head_html_prepend.php
@@ -0,0 +1,39 @@
+.
+
+namespace tool_webanalytics\local\hooks\output;
+
+use tool_webanalytics\injector;
+
+/**
+ * Allows plugins to add any elements to the page
html tag
+ *
+ * @package tool_webanalytics
+ * @author Benjamin Walker (benjaminwalker@catalyst-au.net)
+ * @copyright 2024 Catalyst IT
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class standard_head_html_prepend {
+
+ /**
+ * Render tracking code.
+ *
+ * @param \core\hook\output\standard_head_html_prepend $hook
+ */
+ public static function callback(\core\hook\output\standard_head_html_prepend $hook): void {
+ $hook->add_html(injector::render_tracking_code());
+ }
+}
diff --git a/lib.php b/db/hooks.php
similarity index 67%
rename from lib.php
rename to db/hooks.php
index 101fd33..9febc41 100644
--- a/lib.php
+++ b/db/hooks.php
@@ -15,22 +15,20 @@
// along with Moodle. If not, see .
/**
- * Callback functions.
+ * Hook callbacks for Webanalytics
*
* @package tool_webanalytics
- * @author Dmitrii Metelkin (dmitriim@catalyst-au.net)
- * @copyright 2018 Catalyst IT
+ * @author Benjamin Walker (benjaminwalker@catalyst-au.net)
+ * @copyright 2024 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die;
+defined('MOODLE_INTERNAL') || die();
-use tool_webanalytics\injector;
-
-/**
- * This hook was introduced in moodle 3.3.
- * @return string
- */
-function tool_webanalytics_before_standard_html_head(): string {
- return injector::render_tracking_code();
-}
+$callbacks = [
+ [
+ 'hook' => core\hook\output\standard_head_html_prepend::class,
+ 'callback' => 'tool_webanalytics\local\hooks\output\standard_head_html_prepend::callback',
+ 'priority' => 0,
+ ],
+];
diff --git a/version.php b/version.php
index 0c9d5a1..a013a61 100644
--- a/version.php
+++ b/version.php
@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die;
-$plugin->version = 2021122300; // The current plugin version (Date: YYYYMMDDXX).
+$plugin->version = 2021122301; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2021122300; // Same as version.
$plugin->requires = 2024042200; // Requires Moodle 4.4 or later.
$plugin->component = "tool_webanalytics";