# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['asgi_matomo']

package_data = \
{'': ['*']}

install_requires = \
['asgiref>=3.6.0,<4.0.0', 'httpx>=0.24.0,<0.25.0']

setup_kwargs = {
    'name': 'asgi-matomo',
    'version': '0.3.1',
    'description': 'Middleware for tracking ASGI reqeusts with Matomo',
    'long_description': '# asgi-matomo\n[![Packaging status](https://img.shields.io/pypi/v/asgi-matomo?color=%2334D058&label=pypi%20package)](https://pypi.org/project/asgi-matomo)\n[![CI](https://github.com/spraakbanken/asgi-matomo/workflows/CI/badge.svg)](https://github.com/spraakbanken/asgi-matomo/actions?query=workflow%3ACI)\n[![Coverage](https://github.com/spraakbanken/asgi-matomo/workflows/Coverage/badge.svg)](https://github.com/spraakbanken/asgi-matomo/actions?query=workflow%3ACoverage)\n[![codecov](https://codecov.io/gh/spraakbanken/asgi-matomo/branch/main/graph/badge.svg?token=MRJZVCJQF5)](https://codecov.io/gh/spraakbanken/asgi-matomo)\n\nTracking requests with Matomo from ASGI apps.\n\n`MatomoMiddleware` adds tracking of all requests to Matomo to ASGI applications (Starlette, FastAPI, Quart, etc.). The intended usage is for api tracking (backends).\n\n**Note** If you serve HTML (directly or by templates), it is suggested to track those parts through Matomo\'s javascript tracking.\n\n**Installation**\n\n```bash\npip install asgi-matomo\n```\n\n## What is tracked\n\nCurrently this middleware tracks:\n- `url`\n- `ua`: user_agent\n- `gt_ms`: mesaured as the time before and after this middleware call next in the asgi stack.\n- `send_image=0` for performance issues\n- `cvar` with at least `http_status_code` and `http_method` set.\n- `lang` if `accept-lang` is set\n- `cip` client ip, **requires** `access_token` to be given.\n\nYou can also pass variable to track by adding an `asgi_matomo`  dict in the `state` dict of the ASGI `scope`:\n```python\nscope = {\n  "state": {\n    "asgi_matomo": {\n      "e_a": "Playing",\n      "cvar": {\n        "your": "custom",\n        "data": "here",\n      }\n    }\n  }\n}\n```\n\nThe keys of the `asgi_matomo` dict is expected to be valid parameter for the [Matomo HTTP Tracking API](https://developer.matomo.org/api-reference/tracking-api). `cvar` is serialized with the standard `json` lib.\n\n## Examples\n\n### Starlette\n\n```python\nfrom starlette.applications import Starlette\nfrom starlette.responses import JSONResponse\nfrom starlette.routing import Route\nfrom starlette.middleware import Middleware\n\nfrom asgi_matomo import MatomoMiddleware\n\nasync def homepage(request):\n    return JSONResponse({"data": "a" * 4000})\n\napp = Starlette(\n  routes=[Route("/", homepage)],\n  middleware=[\n    Middleware(\n      MatomoMiddleware,\n      matomo_url="YOUR MATOMO TRACKING URL",\n      idsite=12345, # your service tracking id\n  )],\n)\n```\n\n### FastAPI\n\n```python\nfrom fastapi import FastAPI\nfrom asgi_matomo import MatomoMiddleware\n\napp = FastAPI()\napp.add_middleware(\n  BrotliMiddleware,\n  matomo_url="YOUR MATOMO TRACKING URL",\n  idsite=12345, # your service tracking id\n)\n\n@app.get("/")\ndef home() -> dict:\n    return {"data": "a" * 4000}\n```\n\n## API Reference\n\n**Overview**\n\n```python\napp.add_middleware(\n  MatomoMiddleware,\n  matomo_url="YOUR MATOMO TRACKING URL",\n  idsite=12345, # your service tracking id\n  access_token="SECRETTOKEN",\n  assume_https=True,\n  exclude_paths=["/health"],\n  exclude_patterns=[".*/old.*"],\n  route_details={\n    "route": {\n      "action_name": "Name",\n    }\n  }\n)\n```\n\n**Parameters**:\n\n- **(Required)** `matomo_url`: The URL to make your tracking calls to.\n- **(Required)** `idsite`: The tracking id for your service.\n- _(Optional)_ `access_token`: Access token for Matomo. If this is set `cip` is also tracked. Required for tracking some data.\n- _(Optional)_ `assume_https`: If `True`, set tracked url scheme to `https`, useful when running behind a proxy. Defaults to `True`.\n- _(Optional)_ `exclude_paths`: A list of paths to exclude, only excludes path that is equal to a path in this list. These are tried before `exclude_patterns`. Defaults to `None`.\n- _(Optional)_ `exclude_patterns`: A list of regex patterns that are compiled, and then exclude a path from tracking if any pattern match. Defaults to `None`.\nThese are tried after `exclude_paths`.\n- _(Optional)_ `route_details`: A dict with custom route-specific tracking data. Defaults to `None`.\n\n\n**Notes**:\n\n- Currently only some parts [Matomo Tracking HTTP API](https://developer.matomo.org/api-reference/tracking-api) is supported.\n\n## Ideas for further work:\n- [x] _filtering tracked of urls_\n- [x] _custom extraction of tracked data_\n\n\nThis project keeps a [changelog](./CHANGELOG.md).\n\n# Releas Notes\n\n## Latest Changes\n\n\n## [0.3.0] - 2023-05-22\n### Added\n\n- Allow setting route-details\n\n',
    'author': 'Kristoffer Andersson',
    'author_email': 'kristoffer.andersson@gu.se',
    'maintainer': 'None',
    'maintainer_email': 'None',
    'url': 'https://spraakbanken.gu.se',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.10,<4.0',
}


setup(**setup_kwargs)
