YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Create a Trigger wData Layer Variable

Get Embed Code
4 Languages

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

  1. Now that we've written the code to save
    the food preference in the data layer,

  2. we can create variables in tag manager
    to hold the special of the day for
  3. each kind of food preference.
  4. First, we need to create a data layer
    variable to hold the food preference.
  5. So you go to the variable screen,
    create a new variable.
  6. And this time, it's important
    to choose data layer variable.
  7. Name the variable, this name is for
    you to identify what's in the variable.
  8. And then you configure the variable.
  9. The only thing you can figure for
  10. Data Layer Variable is the name of the
    variable that you using in your code.
  11. This name must exactly match
    the key you set in your code.
  12. So in my case I used the key food_pref,
    so
  13. my variable must be configured for
    the variable name to be food_pref.
  14. You can set the default
    value if you like.
  15. I'm going to set it to unrestricted.
  16. Create the variable.
  17. Now we have the food pref variable.
  18. The next thing to do is to
    create the daily specials for
  19. the different food preferences.
  20. So, the easiest way to create a new
    variable is to copy an existing one.
  21. So, I'm going to copy daily-special-en,
    copy.
  22. Make sure to rename it.
  23. Notice that the type
    is a value collection.
  24. Configure the variable, set the value,
  25. choose a nice vegan special of the day,
    whatever sounds good to you.
  26. Since we copied an existing variable
    we've got the triggers that came with
  27. that variable.
  28. And we need to get rid of them.
  29. So delete all the existing triggers and
    create a new custom trigger.
  30. Now, this list of triggers doesn't
    include the trigger we want, so
  31. we create a new one.
  32. And it's going to be the vegan trigger.
  33. Custom is good.
  34. And then you want it to fire when
    the food preference is vegan.
  35. Look for the food preference contains,
    or even contained, equals vegan.
  36. Save the trigger,
    create the variable, and
  37. now we have the daily-special-vegan
    to the value collection variable.
  38. As well as the food pref which
    is a data layer variable.
  39. And don't forget to publish.
  40. Okay, it's your turn now.
  41. So you're going to create the food
    pref variable and the trigger and
  42. we'll start out showing
    a vegan daily special.
  43. To start with, create the food-pref
    DataLayer variable and
  44. then create a value collection
    variable for the vegan daily special.
  45. And the easiest way to
    do that is to copy and
  46. edit the daily-special-en
    that already exists.
  47. Choose a custom trigger for it and
    then create and use the vegan trigger.
  48. And what's the last step
    that you mustn't forget?
  49. Publish.
  50. Okay, go ahead and do these things.
  51. And then try it out on your app.