Skip to content

$stateChangeSuccess fires before url is updated #3015

@ThomasJuhasz

Description

@ThomasJuhasz

I wanted to use this event with google analytics, like so:

function stateChangeGA() { $rootScope.$on("$stateChangeSuccess", function ($currentRoute, $previousRoute) { window.ga('send', { hitType: 'pageview', page: location.pathname + location.search + location.hash, title: document.title }); }); }

but it was always the last url that got sent to GA, turns out the $stateChangeSuccess event fires just before the url is updated.
I used a $timeout as a workaround:
$timeout(stateChangeGA, 0);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions