1

I'm wondering if anyone has a solution for tracking "page" changes for one-page apps?

I understand the concept of a one-page app in that all the html/css for a page is preloaded and the pages are constructed based on dictating which elements of a page to hide/show. Even though technically it's a one-page app, the perception of the user is that it is several pages/experiences.

What's the best way to differentiate/track these pages/experiences in a one-page app environment?

Collarbone
  • 570
  • 7
  • 17

1 Answers1

1

Yes, https://github.com/angular-ui/ui-router has $stateChangeSuccess, which is fired once the page/state transition is complete. Just simply add a $rootScope.$on to the page controllers where you want stuff to happen on page changes.

http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state

$rootScope.$on('$stateChangeStart', 
    function(event, toState, toParams, fromState, fromParams){ 
        console.log('Page change happened');
})
cheekybastard
  • 5,535
  • 3
  • 22
  • 26