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

**URL:** <https://meta.discourse.org/t/how-can-i-trigger-my-custom-statistics-script-on-every-page-load/274026>\
**Category:** Development\
**Created:** [August 4, 2023, 9:09pm UTC](https://meta.discourse.org/t/how-can-i-trigger-my-custom-statistics-script-on-every-page-load/274026 "2023-08-04T21:09:21Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![nodomain](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nodomain/32/303402_2.png) [@nodomain](https://meta.discourse.org/u/nodomain)\
**Post date:** [August 4, 2023, 9:09pm UTC](https://meta.discourse.org/t/how-can-i-trigger-my-custom-statistics-script-on-every-page-load/274026/1 "2023-08-04T21:09:21Z")

</div>

Knowing that Discourse is a SPA and having looked at some docs around this topic I am still not sure how to achieve this:

- we include a custom js library in the footer that interfaces with our statistics solution
- we want to enrich the stats by triggering custom events on every “page load”, e.g whenever the user navigates to a “new” page

Pseudo code:

```javascript
window.statistic = window.statistic || [];
window.statistic.push({
    action: "page.ready",
    data: {
        page: {
            path: "/c/new-to-this-forum-get-started-here/20/l/new",
            country: "WW",
            language: "en",
}, user: {
            country: "DE",
            loginStatus: "logged_in"
        }
} });

```

How and where in my custom theme do I need to place the code to achieve this?

Thanks 🙂

---

_[View the full topic](https://meta.discourse.org/t/how-can-i-trigger-my-custom-statistics-script-on-every-page-load/274026)._
