The practice world
Why it matters In this module you look inside a real-looking tracker and read exactly what it learns about one person. Seeing the data with your own eyes is the fastest way to understand why browsers fight trackers, and which defences actually work.
Everything in this module happens in the practice world: a tiny pretend web that lives inside Python. Nothing here touches a real website, a real browser or a real person. It is a model railway for the web.
Practice world: the course's simulated web, built by the watched package. It has a few fictional sites, one fictional shopper and a browser that follows simplified versions of real browsers' cookie and storage rules.
Who lives there
- Three shops:
shopa.example(outdoor gear),shopb.example(a pharmacy) andshopc.example(home and baby things). - AdCo at
adco.example: an ad network. All three shops paste AdCo's little script into their pages, the way real shops add ad and analytics tags. - Sam: our one fictional shopper, with a browser and some interests.
Every page on the shops has a category, such as running or baby, the way real shops label pages for search and ads.
AdCo already runs a tracker
You will not write a tracker. AdCo already has one switched on, the way a real ad network would. Each time Sam views a shop page, AdCo's script reports the page to AdCo, and AdCo keeps a log. Your job in this module is to read that log like an investigator, then switch on browser defences and watch what changes.
Server log: the list of every request a website receives. Real websites keep logs too; it is often the first place privacy problems show up.
Seed: a starting number for the simulator's "random" choices. The same seed always gives the same world and the same browsing, so your numbers match the tests.
One helper does the work: practice_log. You give it a world and a list of pages; it lets Sam browse them with AdCo's tracker on, and hands back AdCo's log as a list of small records.
from watched import build_world
from watched.leg2e_inside import practice_log
world = build_world(seed=7) # the same world every run
pages = world.browsing_session(12) # 12 pages Sam visits, in order
log = practice_log(world, pages)
print(len(log)) # 12: one record per page Sam saw
print(log[1])A record looks like this:
{"page": "https://shopb.example/p/sleep-aid",
"site": "shopb.example",
"category": "health",
"cookie_id": "4c1e9b0a77d2f310",
"url_id": None,
"traits": None}cookie_id is the AdCo cookie Sam's browser sent with the report, if any. The very first record has cookie_id set to None, because Sam's browser has no AdCo cookie yet. url_id and traits stay None for now; they fill in later in the module (lessons 42 and 43), when AdCo tries other tricks.
Try it Open a real shopping site, then open your browser's developer tools (right-click, then Inspect) and go to the Network tab. Reload the page and type pixel or collect into the filter box. Each line is a report to some company, just like AdCo's.
Recap
- The practice world is a pretend web inside Python: three shops, one ad network, one shopper.
- AdCo's tracker is already running; you read its log, you do not build one.
practice_log(world, pages)returns one record per page Sam viewed.
This lesson is locked
Lessons open one at a time. Finish the previous lesson to unlock this one.