1

I have a navigation based application. All of the Google Analytics examples I see have page view tracking in viewDidLoad.

I'm wondering if this makes the most sense. If I want to learn about the true behavior of my users, shouldn't it be in viewWillAppear? What is the rationale behind putting it in viewDidLoad? Is there consensus on the proper way to track pageviews?

Thanks

Eitan
  • 1,308
  • 3
  • 15
  • 32

2 Answers2

3

Neither. UINavigationController can send a delegate messages to inform it of navigation through the hierarchy. Check out the UINavigationControllerDelegate protocol for more information. You can handle everything from one delegate instead of modifying all of your view controllers.

Having said that, if you did need to do it from the individual view controllers for some reason, you'd need to use the *Appear methods. Using the *Load methods is clearly wrong - that's for loading, not for showing, hence the name.

For another point of reference, Flurry Analytics uses the UINavigationControllerDelegate protocol.

Jim
  • 72,985
  • 14
  • 101
  • 108
0

If your goal is to get the screen registered by GA each time you browse through the hierarchy and back, in i.e a navigation based app, do the following:

For automatic screen measurement it will be sufficient to put page view tracking in viewDidLoad. If the manual screen measurement method needs to be used, you will need to put it in viewWillAppear. See https://developers.google.com/analytics/devguides/collection/ios/v2/screens

salund
  • 61
  • 1
  • 6