English subtitles

← Put Data in the Data Layer

Get Embed Code
4 Languages

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

  1. The steps of putting data in the data
    layer are, get the tag manager instance
  2. and you do that calling get
    instance on the tag manager.
  3. Then, get the data layer and
  4. you do that calling getDataLayer
    on your tag manager instance.
  5. And then you put a key/value
    pair in the Data Layer.
  6. And you do that calling push on the Data
    Layer, specifying the key and the value.
  7. For example,
    if the key is food_pref, And
  8. values "vegan",
    this is how you would do it.
  9. That's all fairly simple.
  10. And when the values in the data layer,
    you get it out using "dataLayer.get".
  11. For example, you just call "get",
    specifying "food_pref" as the key.
  12. When the values in the data layer can
    also be used in tag manager triggers.
  13. And we're going to look
    into how to do that.
  14. In lesson one, we use the what's for
  15. dinner button to display the users food
    preferences before suggesting a dinner.
  16. You're now going to use a similar
    menu to set the food preferences.
  17. The daily special.
  18. Your tasks are in main activity,
  19. to find a new method putFoodPref in
    Data Layer, which takes a menu item.
  20. And this method puts a value for
    food pref in the data layer.
  21. And this table shows the menu item value
    and the data layer value to put in.
  22. And the key is always food pref.
  23. And then update the existing
    show daily special method
  24. to display the food pref's pop up menu.
  25. And then you'll need to set
    the old click listener to call
  26. the putFoodPrefin DataLayer method and
    to start the ShowDailySpecialActivity.
  27. You can find the code for
    creating the PopupMenu
  28. in the showFoodPrefsMenu
    method in MainActivity.
  29. This method pops up
    the food preferences menu.
  30. And then uses the food preference
    to get dinner suggestion.
  31. However, we want to get the daily
    special, not the dinner suggestion.
  32. So you'll need to copy and
    modify the code to suit your needs.
  33. So go ahead and do these steps now and
    then deploy your app.
  34. You won't see any changes in
    the way the app behaves yet.
  35. Next we'll add triggers in tag manager
    to make use of the data layer variable,
  36. and that's when you'll see
    the changes in your app.