4

I want to track the page where the user was previously than the current one. I was trying to use $ionicHistory.viewHistory() but I can manage to get it. I'm new to angularjs and $ionic so I guess this is a newbie question.

This whole thing is with the purpose of doing a funnel analysis for a single page web app using Piwik but since it doesn't have a proper funnel plugin (thanks Piwik) I'll have to implement it myself. So if you have any advice on the topic it would be great to hear from you.

Diego Aguado
  • 1,604
  • 18
  • 36

3 Answers3

12

So what you are looking for is $ionicHistory.backView() or $ionicHistory.backTitle(). If you are using angular states and routing and views.

So in a controller you would call:

$scope.lastView = $ionicHistory.backView() 

This gives the the last view you were in. So if you go from A to B it will give you A.

If you want the title of the last view call this in a controller:

$scope.lastViewTitle = $ionicHistory.backTitle()

This gives you a string, which is whatever title you gave the previous view. This would return "My Page" if you called backTitle() after you just left this view.

<ion-view view-title="My Page">
    <ion-content>
      Hello!
    </ion-content>
  </ion-view>

You can read more here: http://ionicframework.com/docs/api/service/$ionicHistory/

If you dont want views but states, you should be able to grab the previous state on $stateChangeSuccess that is broadcast.

$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
   //assign the "from" parameter to something
});
ebram khalil
  • 8,252
  • 7
  • 42
  • 60
Jess Patton
  • 2,476
  • 1
  • 15
  • 26
2
var history = $ionicHistory.backView();//returns an object with data about the previous screen. console.log(history) to see the entire data.

var previous_statename = history.stateName;//compare this
var previous_url = history.url;
var previous_title = history.title;
HIRA THAKUR
  • 17,189
  • 14
  • 56
  • 87
0

Use:

$ionicHistory.backView().stateName

which will have this value:

app.tab.contacts
trincot
  • 317,000
  • 35
  • 244
  • 286
kunal shaktawat
  • 1,428
  • 12
  • 21