# Current PageTracker.current?

**URL:** https://meta.discourse.org/t/current-pagetracker-current/79340
**Category:** Development
**Created:** [January 30, 2018, 4:10am UTC](https://meta.discourse.org/t/current-pagetracker-current/79340 "2018-01-30T04:10:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jesselperry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jesselperry/32/119501_2.png) [@jesselperry](https://meta.discourse.org/u/jesselperry)
#### Post date: [January 30, 2018, 4:10am UTC](https://meta.discourse.org/t/current-pagetracker-current/79340/1 "2018-01-30T04:10:48Z")

</div>

Is there a new way to get a Javascript event when page URL changes? Discourse.PageTracker.current is not working for me.

> [@zogstrip](#):
>
> Discourse.PageTracker.current() / change  
> This event is triggered when the current “page” changes. This is useful if you want to hook into an analytics or tracking package:
> 
> Discourse.PageTracker.current().on(‘change’, function(url) {  
> console.log('the page changed to: ’ + url);  
> });

---

<div class="post-metadata">

### Author: ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)
#### Post date: [January 30, 2018, 4:22am UTC](https://meta.discourse.org/t/current-pagetracker-current/79340/2 "2018-01-30T04:22:37Z")

</div>

I’ve had some luck with something like this. (May not be the most optimal way 😅)

```plaintext
<script type="text/discourse-plugin" version="0.8.16">
api.onPageChange(() => {
	foo();
});

function foo() {
	// do stuff
	console.log(" foo loaded");
}
</script>

```

[https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/plugin-api.js.es6#L341-L356](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/plugin-api.js.es6#L341-L356)

---

<div class="post-metadata">

### Author: ![jesselperry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jesselperry/32/119501_2.png) [@jesselperry](https://meta.discourse.org/u/jesselperry)
#### Post date: [January 30, 2018, 5:02am UTC](https://meta.discourse.org/t/current-pagetracker-current/79340/3 "2018-01-30T05:02:44Z")

</div>

Thank you! That seems to be the best way currently. Also found it referenced here:

> [@Accessibility: Signal changes to screen readers on navigation](https://meta.discourse.org/t/accessibility-signal-changes-to-screen-readers-on-navigation/77897/2):
>
> We already have a hook on page change, maybe use that? \<script type="text/discourse-plugin" version="0.2"\> api.onPageChange((url, title) =\> { Em.run.next(()=\>{ $('body').addClass('xyz') }); }); \</script\>
