{"id":13421557,"url":"https://github.com/citruspi/Flask-Analytics","last_synced_at":"2025-03-15T10:31:14.381Z","repository":{"id":14300634,"uuid":"17009250","full_name":"citruspi/Flask-Analytics","owner":"citruspi","description":"Analytics snippets generator extension for the Flask framework.","archived":false,"fork":false,"pushed_at":"2016-10-12T18:57:38.000Z","size":70,"stargazers_count":81,"open_issues_count":2,"forks_count":21,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-03T18:49:18.473Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/citruspi.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}},"created_at":"2014-02-20T04:38:39.000Z","updated_at":"2024-11-26T17:33:25.000Z","dependencies_parsed_at":"2022-09-16T00:51:45.888Z","dependency_job_id":null,"html_url":"https://github.com/citruspi/Flask-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/citruspi%2FFlask-Analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/citruspi%2FFlask-Analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/citruspi%2FFlask-Analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/citruspi%2FFlask-Analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/citruspi","download_url":"https://codeload.github.com/citruspi/Flask-Analytics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243718889,"owners_count":20336590,"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":[],"created_at":"2024-07-30T23:00:25.020Z","updated_at":"2025-03-15T10:31:13.968Z","avatar_url":"https://github.com/citruspi.png","language":"Python","readme":"[![Travis branch](https://img.shields.io/travis/citruspi/Flask-Analytics/master.svg?style=flat-square)](https://travis-ci.org/citruspi/Flask-Analytics)\n[![Coveralls branch](https://img.shields.io/coveralls/citruspi/Flask-Analytics/master.svg?style=flat-square)](https://coveralls.io/github/citruspi/Flask-Analytics)\n[![License](https://img.shields.io/github/license/citruspi/Flask-Analytics.svg?style=flat-square)](http://unlicense.org)\n[![PyPI](https://img.shields.io/pypi/v/Flask-Analytics.svg?style=flat-square)](https://pypi.python.org/pypi/Flask-Analytics)\n[![PyPI](https://img.shields.io/pypi/wheel/Flask-Analytics.svg?style=flat-square)](https://pypi.python.org/pypi/Flask-Analytics)\n[![PyPI](https://img.shields.io/pypi/pyversions/Flask-Analytics.svg?style=flat-square)](https://pypi.python.org/pypi/Flask-Analytics)\n[![PyPI](https://img.shields.io/pypi/status/Flask-Analytics.svg?style=flat-square)](https://pypi.python.org/pypi/Flask-Analytics)\n\n## Flask-Analytics\n\nFlask Analytics is an extension for Flask which generates analytics snippets for inclusion in templates.\n\n## Installation\n\n```bash\n$ pip install Flask-Analytics\n```\n\n## Usage\n\n__app.py__\n\n```python\nfrom flask import Flask, render_template\nfrom flask_analytics import Analytics\n\napp = Flask(__name__)\nAnalytics(app)\n\napp.config['ANALYTICS']['GAUGES']['SITE_ID'] = 'XXXXXXXXXXXXX'\n\n\n@app.route('/')\ndef index():\n\n    return render_template('index.html')\n```\n\n__index.html__\n\n```\n{{ analytics }}\n```\n\n__result__\n\n```html\n$ curl http://localhost:5000/\n\u003cscript type=\"text/javascript\"\u003e\n    var _gauges = _gauges || [];\n    (function() {\n        var t   = document.createElement('script');\n        t.type  = 'text/javascript';\n        t.async = true;\n        t.id    = 'gauges-tracker';\n        t.setAttribute('data-site-id', 'XXXXXXXXXXXXX');\n        t.src = '//secure.gaug.es/track.js';\n        var s = document.getElementsByTagName('script')[0];\n        s.parentNode.insertBefore(t, s);\n    })();\n\u003c/script\u003e\n```\n\n## Services\n\n`Flask-Analytics` uses keys defined in `app.config['ANALYTICS']` to determine which for which services analytics snippets should be generated.\n\n| Service | Keys Required |\n|:--------|:--------------|\n| [Google Analytics (ga.js)](http://www.google.com/analytics/) | `['GOOGLE_CLASSIC_ANALYTICS']['ACCOUNT']` |\n| [Universal Analytics (analytics.js) ](http://www.google.com/analytics/) | `['GOOGLE_UNIVERSAL_ANALYTICS']['ACCOUNT']` |\n| [Piwik](http://piwik.org/) | `['PIWIK']['BASE_URL']`\u003cbr\u003e`['PIWIK']['SITE_ID']`|\n| [Gaug.es](http://gaug.es/) | `['GAUGES']['SITE_ID']` |\n| [Chartbeat](https://chartbeat.com) | `['CHARTBEAT']['UID']`\u003cbr\u003e`['CHARTBEAT']['DOMAIN']` |\n| [GoSquared](https://www.gosquared.com) | `['GOSQUARED']['UID']` |\n\nIndividual services can be disabled by setting the `ENABLED` key for that service (e.g. `['ANALYTICS']['PIWIK']['ENABLED']`). Analytics as a whole can be disabled by setting the `ENABLED` key at the top (e.g. `['ANALYTICS']['ENABLED']`).\n\nWhen a service, or analytics as a whole, is disabled, it returns an empty string, so it's safe to keep `{{analytics}}` in your template.\n\nWhen the configuration changes, the source for the analytics code will automatically be rebuilt the next time it's called.\n\n## Tests\n\n```\n$ nosetests -v --with-coverage --cover-package=flask_analytics --cover-html \ntest_all (test_app.TestAnalytics) ... ok\ntest_boostrap (test_app.TestAnalytics) ... ok\ntest_chartbeat (test_app.TestAnalytics) ... ok\ntest_disabled (test_app.TestAnalytics) ... ok\ntest_gauges (test_app.TestAnalytics) ... ok\ntest_google_classic (test_app.TestAnalytics) ... ok\ntest_google_universal (test_app.TestAnalytics) ... ok\ntest_gosquared (test_app.TestAnalytics) ... ok\ntest_none (test_app.TestAnalytics) ... ok\ntest_piwik (test_app.TestAnalytics) ... ok\n\nName                                                    Stmts   Miss  Cover   Missing\n-------------------------------------------------------------------------------------\nflask_analytics.py                                          1      0   100%   \nflask_analytics/analytics.py                               60      1    98%   77\nflask_analytics/providers.py                                0      0   100%   \nflask_analytics/providers/base.py                           2      0   100%   \nflask_analytics/providers/chartbeat.py                     13      0   100%   \nflask_analytics/providers/gauges.py                        11      0   100%   \nflask_analytics/providers/googleclassicanalytics.py        11      0   100%   \nflask_analytics/providers/googleuniversalanalytics.py      11      0   100%   \nflask_analytics/providers/gosquared.py                     11      0   100%   \nflask_analytics/providers/piwik.py                         13      0   100%   \n-------------------------------------------------------------------------------------\nTOTAL                                                     133      1    99%   \n----------------------------------------------------------------------\nRan 10 tests in 0.111s\n\n\nOK\n```\n\n## License\n\nFlask-Analytics is dedicated to the public domain. Please read the license for\nmore information.\n","funding_links":[],"categories":["Analytics","Python","介绍"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcitruspi%2FFlask-Analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcitruspi%2FFlask-Analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcitruspi%2FFlask-Analytics/lists"}