Return to Video

Put Data in the Data Layer

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

more » « less
Video Language:
English
Team:
Udacity
Project:
UD876-2 - Google Play Services - Analytics
Duration:
02:20

English subtitles

Revisions Compare revisions