Track requests to your Flask server with Matomo
Reason this release was yanked:
Premature release
Project description
Flask-Matomo
Flask-Matomo is a library which lets you track the requests of your Flask website using Matomo (Piwik).
Forked from LucasHild/flask-matomo.
Installation
pip install flask-matomo
Usage
from flask import Flask, jsonify
from flask_matomo import *
app = Flask(__name__)
matomo = Matomo(app, matomo_url="https://matomo.mydomain.com",
id_site=5, token_auth="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
@app.route("/")
def index():
return jsonify({"page": "index"})
if __name__ == "__main__":
app.run()
In the code above:
- The Matomo object is created by passing in the Flask application and arguments to configure Matomo.
- The matomo_url parameter is the url to your Matomo installation.
- The id_site parameter is the id of your site. This is used if you track several websites with one Matomo installation. It can be found if you open your Matomo dashboard, change to site you want to track and look for &idSite= in the url.
- The token_auth parameter can be found in the area API in the settings of Matomo. It is required for tracking the ip address.
Adding details to route
You can provide details to a route in 2 ways, first by using the matomo.details
decorator:
from flask import Flask, jsonify
from flask_matomo import *
app = Flask(__name__)
matomo = Matomo(app, matomo_url="https://matomo.mydomain.com",
id_site=5, token_auth="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
@app.route("/foo")
@matomo.details(action_name="Foo")
def foo():
return jsonify({"page": "foo"})
if __name__ == "__main__":
app.run()
or by giving details to the Matomo constructor:
from flask import Flask, jsonify
from flask_matomo import *
app = Flask(__name__)
matomo = Matomo(
app,
matomo_url="https://matomo.mydomain.com",
id_site=5,
token_auth="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
routes_details={
"/foo": {
"action_name": "Foo"
}
}
)
@app.route("/foo")
def foo():
return jsonify({"page": "foo"})
if __name__ == "__main__":
app.run()
Meta
Lucas Hild - https://lucas-hild.de This project is licensed under the MIT License - see the LICENSE file for details
Release Notes
Latest Changes
0.2.0 - 2023-05-22
Changed
- Track original IP address if request was forwarded by proxy. Tanikai/flask-matomo by @Tanakai.
- Change ignored routes to compare against rules instead of endpoint. MSU-Libraries/flask-matomo by @meganschanz.
- Add ignored UserAgent prefix; set action to be url_rule. MSU-Libraries/flask-matomo by @natecollins.
- Fix matomo.ignore decorator.
- Handle request even if tracking fails. PR #30 by @kod-kristoff.
- Ignore routes by regex. PR #29 by @kod-kristoff.
- Make token_auth optional. PR #28 by @kod-kristoff.
- Track dynamic request data. PR #27 by @kod-kristoff.
- Also track request time. PR #26 by @kod-kristoff.
- Extend tracked variables. PR #25 by @kod-kristoff.
- fix matomo.details decorator. PR #19 by @kod-kristoff.
0.1.0
- Forked from LucasHild/flask-matomo.
- Renamed to
flask-matomo2
. - Add test suite.
- Setup CI with Github Actions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flask_matomo2-0.2.0.tar.gz
(5.8 kB
view hashes)
Built Distribution
Close
Hashes for flask_matomo2-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5934b8b91a429a53a6ee260cd6e77fb3e583cb876e8f2430690ea940110c8ace |
|
MD5 | 75e87125c8c9b04debc41f492a2925b3 |
|
BLAKE2b-256 | 665323868968f846982b39ab8dd5104ff21fb39da520db4a96e035a900324c74 |