Rule Exercises

Objective

Explore fundamentals of KRL and building rules.

Preparation

Exercises

The following exercises will use skills you learned in the Quickstart, but you won't be deploying your app on SquareTag. 

  1. Create a ruleset that fires a notification on ktest.heroku.com.  You will need to register it using KDK, but you won't have to install it in SquareTag for it to run on ktest
  2. Modify the rule you created in (1) to place two notification boxes on the page from the same rule. 
  3. Add a second rule that places a third notification box on the page. This notification box should say "Hello " followed by the value of query string. If the query string is empty, say "Hello Monkey". You may find the url function in the page library helpful. 
  4. Write a function that given a string in standard URL encoding (e.g. <key0>=<value0>&<key1>=<value1>...) returns the value of the key name.  (Hint, regular expressions and the string operators will be useful here.) Use function with the query string to modify the rule from (3) so that the notification says "Hello " followed by the value of the key name. Do not assume that the query string will contain only one key-value pair. So, if the url were http://ktest.heroku.com/b16x12232?name=Phil, the notification would say "Hello Phil". Be sure you still default to "Hello Monkey" if there is no query string or there is no key called name.
  5. Write a rule that counts the number of times it has fired and stops showing its notification after five times for any given user. Display the count in the notification. 
  6. Write a rule that clears the count from (5) if a query string parameter named clear is given in exampley.com URL. 
  7. How would you modify the rule in (5) so that it stops showing the notification after it has been shown five times altogether (not just to a specific user)?

Copyright Picolabs | Licensed under Creative Commons.