{"id":15692265,"url":"https://github.com/healeycodes/privacy-focused-analytics","last_synced_at":"2025-05-08T02:23:56.523Z","repository":{"id":112378207,"uuid":"286141282","full_name":"healeycodes/privacy-focused-analytics","owner":"healeycodes","description":"🗃️  A toy analytics system for the web with a focus on user privacy.","archived":false,"fork":false,"pushed_at":"2020-08-25T17:01:13.000Z","size":29,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-15T00:51:13.212Z","etag":null,"topics":["analytics","flask","tracking-pixels","web-analytics"],"latest_commit_sha":null,"homepage":"https://healeycodes.com/privacy-focused-analytics-from-scratch/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/healeycodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-09T00:35:56.000Z","updated_at":"2024-08-27T14:39:54.000Z","dependencies_parsed_at":"2023-05-14T04:00:36.843Z","dependency_job_id":null,"html_url":"https://github.com/healeycodes/privacy-focused-analytics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Fprivacy-focused-analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Fprivacy-focused-analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Fprivacy-focused-analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Fprivacy-focused-analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/healeycodes","download_url":"https://codeload.github.com/healeycodes/privacy-focused-analytics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252985128,"owners_count":21835924,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics","flask","tracking-pixels","web-analytics"],"created_at":"2024-10-03T18:30:18.465Z","updated_at":"2025-05-08T02:23:56.490Z","avatar_url":"https://github.com/healeycodes.png","language":"Python","readme":"## Privacy Focused Analytics\n\n\u003e My blog post: [Privacy Focused Analytics From Scratch](https://healeycodes.com/privacy-focused-analytics-from-scratch/)\n\n\u003cbr\u003e\n\nI wanted to learn more about web analytics so I budgeted myself a few hours and built a small analytics system.\n\nIt uses a Flask application with a SQLite database, and a HTML snippet to collect **anonymous user data** from any website.\n\n\u003cbr\u003e\n\n### Features\n\n- Uses a dynamic tracking pixel (optionally works without JavaScript)\n- Collects information about:\n  - What pages users visit\n  - Where users are referred from\n  - What browsers and screen sizes are used\n  - Which country the user is from (without an API call)\n- Lets you view analytics from different time slices\n\u003cbr\u003e\n\n### Snippet\n\nInclude this on any page you want to gather analytics from.\n\nChange `https://example.org` to wherever you host the Flask application.\n\n```html\n\u003cscript\u003e\n  const website = 'https://example.org'\n  const url = new URL(website + \"/pixel.gif\")\n\n  // '/'\n  url.searchParams.append(\"path\", location.pathname)\n\n  // 'Analytics Test Page'\n  url.searchParams.append(\"title\", document.title)\n\n  // 'https://www.google.com'\n  url.searchParams.append(\"referrer\", document.referrer)\n\n  // '320,568'\n  url.searchParams.append(\n    \"resolution\",\n    window.screen.width + \",\" + window.screen.height\n  )\n\n  const img = document.createElement(\"img\")\n  img.src = url\n  // When the element exists in the DOM, the request is made\n  document.body.appendChild(img)\n\u003c/script\u003e\n\u003cnoscript\u003e\n  \u003c!-- Without JavaScript, less information is available to be sent\n  e.g. just the path and title, set via static template logic --\u003e\n  \u003cimg src=\"https://example.org/pixel.gif?path=%2F\u0026title=Analytics%20Test%20Page\" /\u003e\n\u003c/noscript\u003e\n```\n\u003cbr\u003e\n\n### Setup\n\nDownload a free [GeoLite2 country database](https://dev.maxmind.com/geoip/geoip2/geolite2/) to `./GeoLite2-Country.mmdb`\n\n`pip install -r requirements.txt`\n\n\u003cbr\u003e\n\n### Run\n\n`env FLASK_APP=analytics.py flask run`\n\n\u003cbr\u003e\n\nThe tracking pixel is hosted from `/pixel.gif`.\n\nNote: It's likely that most ad blockers will stop the request.\n\n\u003cbr\u003e\n\nThere is a test page at `/` that will serve up the snippet for test purposes.\n\n\u003cbr\u003e\n\nAnalytics can be viewed at `/analytics`. Search parameters can be passed to view a time slice.\n\n- (optional) `start` - The start of the time slice in UNIX seconds (inclusive). Defaults to `0`.\n- (optional) `end` - The end of the time slice in UNIX seconds. Defaults to current time.\n\n\u003cbr\u003e\n\n### Possible improvements\n\nHopefully none? This was a self-contained experiment to learn more about something 😊\n\n\u003cbr\u003e\n\nLicense: MIT.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhealeycodes%2Fprivacy-focused-analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhealeycodes%2Fprivacy-focused-analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhealeycodes%2Fprivacy-focused-analytics/lists"}