Cookie use: tracking user preferences

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Cookie use: tracking user preferences

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which is an example of a cookie recording a user's preference?
A A site turns your web page into HTML code
B A site remembers you chose French as your language
2. A shop site shows 'Recommended for you' items based on pages you viewed before. What made this possible?
A Cookies recording your browsing habits
B The DNS server choosing products for you
3. True or false: cookies can record browsing habits so a site can show targeted adverts.
A False
B True
4. A user picks dark mode on a website. Next visit it is dark mode again. Which statement best explains this?
A A cookie stored the theme setting
B The web server never forgets any visitor
5. Which is the main purpose of a preference cookie?
A To tailor what the site shows to the user
B To encrypt the data sent between browser and server

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Set-Cookie: lang=fr ASet-Cookie: interest=football
2Set-Cookie: theme=dark BRecommendations come from browsing habits recorded in cookies, such as products the user viewed before.
3A shop records the types of items a user browses so it can suggest similar products CSaves the user's layout choice so the site can show dark mode on later visits
4An advertiser uses a cookie of a user's browsing habits to show targeted adverts DSaves the user's chosen language so the site can show pages in French next time
5Cookies delete the user's language setting so the site forgets it ESet-Cookie: viewed=trainers
6Recommended products come from the user's monitor size only FCookies do not delete preferences; they record them so the site can remember the language and tailor pages.

Definitions

preference cookie

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
__________: language=French
2.
IF cookie.theme = "dark" ____ page.colour ← "black" ENDIF
3.
______: viewed=Headphones
4.
IF cookie.interest = "football" THEN showAdvert("football boots") _____
5.
Set-Cookie: language=French; _______=2592000

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A IF cookie EXISTS THEN
B lang ← cookie.password
C SHOW page IN lang
D ENDIF
Question 2
A READ theme FROM cookie
B IF theme = "dark" THEN
C SET background ← black
D ENDIF
E SET background ← white
F ENDIF
Question 3
A READ lastViewed FROM cookie
B items ← SIMILAR(lastViewed)
C FOR EACH item IN lastViewed
D SHOW item
Question 4
A READ interests FROM bookmarks
B advert ← MATCH(interests)
C SHOW advert
Question 5
A INPUT choice
B IF choice = "French" THEN
C lang ← "fr"
D DELETE lang FROM cookie
E ENDIF

Answer Key

Cookie use: tracking user preferences
Section A: Quick Questions
Q1
B — A site remembers you chose French as your language
Q2
A — Cookies recording your browsing habits
Q3
B — True
Q4
A — A cookie stored the theme setting
Q5
A — To tailor what the site shows to the user
Section B: Match the Pairs
Q1
Set-Cookie: lang=fr → Saves the user's chosen language so the site can show pages in French next time
Q2
Set-Cookie: theme=dark → Saves the user's layout choice so the site can show dark mode on later visits
Q3
A shop records the types of items a user browses so it can suggest similar products → Set-Cookie: viewed=trainers
Q4
An advertiser uses a cookie of a user's browsing habits to show targeted adverts → Set-Cookie: interest=football
Q5
Cookies delete the user's language setting so the site forgets it → Cookies do not delete preferences; they record them so the site can remember the language and tailor pages.
Q6
Recommended products come from the user's monitor size only → Recommendations come from browsing habits recorded in cookies, such as products the user viewed before.
Section C: Definitions
Q1
preference cookie — A cookie that records a user's preferences and browsing habits so a site can tailor what it shows, such as language, layout, suggested products or targeted adverts.
Section D: Fill in the Blanks
Q1
Set-Cookie: language=French
Q2
IF cookie.theme = "dark" THEN page.colour ← "black" ENDIF
Q3
Cookie: viewed=Headphones
Q4
IF cookie.interest = "football" THEN showAdvert("football boots") ENDIF
Q5
Set-Cookie: language=French; Max-Age=2592000
Section E: Spot the Error
Q1
B — The program should read the saved language preference from the cookie, so it must be cookie.language. A preference cookie does not hold a password.
Q2
D — ENDIF here closes the IF too early, so the ELSE part has nothing to belong to. Line 4 should be ELSE to give the default light theme.
Q3
C — The loop should go through the list of recommended products (items), not the single last viewed product. It should be FOR EACH item IN items.
Q4
A — A site records browsing habits in a cookie, not in the user's bookmarks. The interests must be read FROM cookie so the advert can be targeted.
Q5
D — The language preference must be stored in the cookie so the site remembers it next visit. Deleting it would lose the preference. It should be STORE lang IN cookie.