Skip to content

About

Generate an English/French cookie and tracker disclosure page from a real consent-tracker-scan report, grouped by purpose, with a diff to keep it true over time.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

cookie-policy-gen

Turn a consent-tracker-scan report into a cookie and tracker notice in English and French for Canadian sites. It lists only what the scan actually saw, and it can tell you when the notice is out of date.

python -m consent_tracker_scan https://your-site.ca/ --pages 5 --json scan.json
python -m cookie_policy_gen policy scan.json --out-dir public/     # EN + FR, Markdown + HTML
python -m cookie_policy_gen inventory scan.json -o cookies.json    # sorted, stable JSON
python -m cookie_policy_gen diff cookies.json new-scan.json        # exit 1 if anything changed
  • Grouped by purpose: strictly necessary, preferences, analytics, marketing, and unclassified. Cookies, localStorage/sessionStorage keys and third-party services are all listed.
  • One row per item: name, provider, purpose, duration (Session, 30 minutes, 1 year 1 month), first or third party, and the pages where it was seen.
  • Canadian context: plain information on PIPEDA (meaningful consent) and Quebec Law 25 (s. 8.1 technologies that identify, locate or profile, s. 8.2 privacy policy, s. 3.1 person in charge). Labelled "This is not legal advice" / "Ceci n'est pas un avis juridique".
  • Placeholders the owner must fill, highlighted in the HTML: [ORGANIZATION NAME], [PRIVACY CONTACT EMAIL], [PERSON IN CHARGE OF PERSONAL INFORMATION], [LAST UPDATED], [JOB TITLE], [MAILING ADDRESS] and a consent-mechanism placeholder when trackers are present. The French page uses [NOM DE L'ORGANISATION], [COURRIEL DU CONTACT VIE PRIVÉE], [PERSONNE RESPONSABLE DE LA PROTECTION DES RENSEIGNEMENTS PERSONNELS], [DERNIÈRE MISE À JOUR], and so on.
  • Honest by construction: if the scan found no analytics or marketing tracker, the page says so and shows "None found by the scan". Cookieless analytics (Cloudflare Web Analytics, Plausible, Fathom, Simple Analytics) are named as such, and the page still explains that the browser contacts their servers.
  • Self-contained HTML: one file, inline CSS, no JavaScript, no external resource, lang="en-CA" / lang="fr-CA".
  • No dependencies. Standard library only, Python 3.10+.

Measured result

The scan of demarkstudio.ca, run on this machine with the scanner's default polite settings (robots.txt, 1 s between pages):

$ python -m consent_tracker_scan https://demarkstudio.ca/en/ --pages 3 --json examples/demarkstudio-scan.json --md scan.md
scanning https://demarkstudio.ca/en/
scanning https://demarkstudio.ca/en/product
scanning https://demarkstudio.ca/en/pricing
3 page(s): 0 high, 0 medium, 1 low; 1 cookie(s), 0 storage key(s), 1 third-party host(s); banner: none

$ python -m cookie_policy_gen policy examples/demarkstudio-scan.json --out-dir examples --name demarkstudio-cookie-policy
wrote examples/demarkstudio-cookie-policy.en.md
wrote examples/demarkstudio-cookie-policy.en.html
wrote examples/demarkstudio-cookie-policy.fr.md
wrote examples/demarkstudio-cookie-policy.fr.html

The scan found one first-party cookie, idioma (1 year, HttpOnly), and one third party, Cloudflare Web Analytics, which set no cookie. No analytics or marketing cookie, no web storage, no consent banner. From examples/demarkstudio-cookie-policy.en.md:

## Summary

An automated scan of 3 page(s) of demarkstudio.ca on 2026-09-29, made as a first-time visitor who had not made any consent choice, found 1 cookie(s), 0 web storage key(s) and 1 third-party service(s).

The scan found no cookies, web storage or third-party trackers used for analytics or marketing.

It found 1 item(s) that remember preferences: `idioma` (demarkstudio.ca).

The site uses cookieless analytics: Cloudflare Web Analytics. The scan saw no cookie and no web storage from this service. Your browser still connects to its servers when a page loads, which gives them technical data such as your IP address, the page address and your browser type.

> **Note for [ORGANIZATION NAME] (delete before publishing):**
>
> - these items were classified from their name only; confirm what they do: `idioma` (demarkstudio.ca).
> - replace every placeholder in square brackets.
[...]
### Preferences (1)

Remember choices such as language or display settings.

| Name | Provider | Purpose | Duration | Party | Type | Seen on |
|---|---|---|---|---|---|---|
| `idioma` | demarkstudio.ca | Remembers the language chosen by the visitor. | 1 year | First party | Cookie | /en/, /en/pricing, /en/product |

### Analytics (1)

Measure visits and how the site is used, so it can be improved.

| Name | Provider | Purpose | Duration | Party | Type | Seen on |
|---|---|---|---|---|---|---|
| `static.cloudflareinsights.com` | Cloudflare Web Analytics | Counts visits without cookies (Cloudflare Web Analytics). | Not stored (network request) | Third party | Third-party request (no cookie) | /en/, /en/pricing, /en/product |

The scanner could not tie idioma to a tracker, so this tool classified it from its name (Spanish for "language") and the page asks the owner to confirm it. The French page is examples/demarkstudio-cookie-policy.fr.md; the HTML pages are next to it.

Diff, simulated: examples/demarkstudio-inventory.SIMULATED-addition.json is the real inventory plus one _ga cookie added by hand. The real site sets no such cookie.

$ python -m cookie_policy_gen inventory examples/demarkstudio-scan.json -o examples/demarkstudio-inventory.json
$ python -m cookie_policy_gen diff examples/demarkstudio-inventory.json examples/demarkstudio-inventory.SIMULATED-addition.json
Added (1):
  + cookie _ga (demarkstudio.ca): analytics, first party, 1 year 1 month, provider Google Analytics
Removed (0):
Changed (0):
changed: 1 added, 0 removed, 0 changed
$ echo $?
1
$ python -m cookie_policy_gen diff examples/demarkstudio-scan.json examples/demarkstudio-inventory.json
Added (0):
Removed (0):
Changed (0):
identical: 0 added, 0 removed, 0 changed
$ echo $?
0

$ python -m pytest -q -p no:cacheprovider --import-mode=importlib cookie-policy-gen
47 passed in 0.19s

The tests use no internet. They use fixture reports in tests/ that follow the scanner's real JSON shape: a shop with Google Analytics, the Meta pixel, Hotjar storage, a Cookiebot banner, Plausible and unknown third parties; a clean site with cookieless analytics only; and a trimmed report with odd fields for the tolerant loader.

Usage

cookie-policy-gen policy INPUT [--overrides FILE] [--lang en|fr|all] [--format md|html|all]
                               [--out-dir DIR] [--name cookie-policy]
cookie-policy-gen inventory INPUT [--overrides FILE] [-o FILE]
cookie-policy-gen diff OLD NEW [--overrides FILE] [--format text|md] [--json] [-o FILE]

INPUT, OLD and NEW can each be a raw consent-tracker-scan JSON report or an inventory written by this tool. Without --out-dir, policy prints one page (English Markdown by default) to stdout. With --out-dir, it writes <name>.<lang>.md and <name>.<lang>.html for both languages.

diff reports items added, removed or changed. An item is identified by type, domain and name; a change is a different purpose, party, provider or duration (compared as the human-readable duration, so a scan a few seconds later is not a change). Pages are not compared, since they depend on which pages a crawl visited.

Exit codes: 0 success (diff: identical), 1 diff found changes, 2 usage error or unreadable input. In CI, scan the site, then diff the committed inventory against the new scan: a new tracker fails the build until the notice is regenerated.

Supported input

From a consent-tracker-scan report the loader reads:

  • site, start_url, scanned_at, consent_banner.detected / .cmp, and pages[] (final_url or url; pages with an error are not counted);
  • cookies[]: name, domain, party, expires (ISO time, Unix time, "session" or -1), expires_in_days, max_age, tracker, category, pages;
  • storage[]: key (or name), type (localStorage or sessionStorage), origin, party, tracker, category, pages;
  • third_party_hosts[]: host, site, tracker, category, pages. If it is missing, hosts are rebuilt from third_party_requests[].

Missing keys get defaults, unknown categories become unknown, and items without a name are skipped. Durations are computed from expires minus scanned_at and rounded to whole days (or minutes below a day), so inventories stay stable between scans.

Purposes

Scanner category Purpose
consent, cdn_fonts necessary
analytics, session_replay, tag_manager, cookieless_analytics analytics
advertising, social_pixel, embed marketing
unknown unclassified

First-party items the scanner could not classify are matched by name against a short list in cookie_policy_gen/data/known.json (Cloudflare bot cookies, Stripe fraud cookies, session and CSRF cookies, consent cookies, language and theme cookies). Those items are flagged for the owner to confirm. Everything else stays unclassified, and the page tells the owner to describe it.

Overrides

The owner knows best. An overrides file sets purpose, description (a string, or {"en": ..., "fr": ...}) or provider by name. Keys can be NAME, cookie:NAME, localStorage:KEY, sessionStorage:KEY or request:HOST, and * / ? wildcards work. See examples/overrides.example.json.

{"overrides": {"idioma": {"purpose": "preferences", "description": {"en": "Remembers the chosen language.", "fr": "Mémorise la langue choisie."}}}}

Limitations

  • The notice is only as complete as the scan: one visit, before consent, on the scanned pages. Tools that load after consent, after a login, on scroll or on other pages are not listed. Scan more pages and rescan after every site change.
  • Purposes come from the scanner's tracker list and a short name list. A vendor can use one cookie for several purposes; check each row.
  • The legal sections are plain general information about PIPEDA and Quebec Law 25, not an assessment of the site. They do not cover other provincial laws in detail. This is not legal advice; have the page reviewed before publishing it.

Author

Marvin Palencia, founder of DeMark Studio, Miramichi, New Brunswick, Canada. Portfolio: marvin.demarkstudio.ca

MIT License.

About

Generate an English/French cookie and tracker disclosure page from a real consent-tracker-scan report, grouped by purpose, with a diff to keep it true over time.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages