How can I trigger my custom statistics script on every page "load"?

You’ll likely want to use onPageChange from our plugin API.

In a theme, you’d want to add something like this to javascripts/discourse/api-initializers/your-initializer.js

import { withPluginApi } from "discourse/lib/plugin-api";

export default {
  name: "custom-script-name",

  initialize() {
    withPluginApi("0.8.36", (api) => {
      api.onPageChange(() => {
        // script you want to fire on page change here
      });
    });
  },
};