English subtitles

← 2 q Sending specific screen view hits

Get Embed Code
4 Languages

Showing Revision 3 created 05/24/2016 by Udacity Robot.

  1. You've already learned how
    to activate auto tracking so
  2. that every time any user goes
    to any screen in your app,
  3. a hit is recorded and
    sent to Google Analytics.
  4. While you're learning how to
    add analytics to your app,
  5. it's fine to have auto tracking enabled.
  6. It's gratifying to see the hits
    coming in the dashboard.
  7. But if your app gets wildly popular and
    if you've got auto tracking enabled,
  8. then that's going to be a lot
    of screen hits that get sent.
  9. In fact, it could be too many hits,
    and you might run into quota limits.
  10. If your app exceeds its quota limits,
    excess hits will not be counted.
  11. You can read about quota
    limits in the developer docs.
  12. The main point to understand
    is that it's often better to
  13. specifically track
    what you want to track
  14. rather than enabling auto
    tracking across all activities.
  15. It's easy enough to disable auto
    tracking for all activities.
  16. Simply set ga_autoActivityTracking
    to false in the config file for
  17. your tracker.
  18. And then, instead, to track when
    users go to a specific screen,
  19. you can send a screen view hit,
    like this.
  20. You add the code to onStart.
  21. Then you get the tracker.
  22. Hopefully you know how to do that now.
  23. You can set the screen name on
    the tracker with setScreenName.
  24. And then you send the hit, calling
    build on HitBuilders.ScreenViewBuilder.
  25. And you'll need to make sure that
    your app has the right imports.
  26. You're going to need the Tracker class.
  27. And you're going to need
    the HitBuilders class.
  28. For all hits that are sent,
    you still get the geo information,
  29. the device info, the engagement details,
    and all that other good stuff.
  30. Okay, go ahead and try it now.
  31. In the tracker config file,
    set ga_autoActivityTracking to false.
  32. Then pick an activity in your app, and
  33. add the code to the onStart()
    method to send a hit.
  34. So, here,
    I'm tracking hits to ShowRecipe.
  35. So I'm in the ShowRecipeActivity
    with my onStart method.
  36. And you can see I set my screen
    name to Show recipe screen.
  37. And here's the code to send the hit.
  38. And then, of course,
    run your app and try it out.
  39. You can look in the logs to
    see that your hit gets sent
  40. when you go to that screen.
  41. See there's my hit, but not when
    you do anything else in the app.
  42. And then of course, don't forget to
    check your analytics dashboard and
  43. then come here and check the boxes.