Metadata-Version: 2.4
Name: djinsight
Version: 0.4.1
Summary: MCP-first analytics for Django/Wagtail package for tracking page view statistics with Redis and async processing
Home-page: https://github.com/krystianmagdziarz/djinsight
Author: MDigital
Author-email: MDigital <kontakt@mdigital.com.pl>
Maintainer-email: MDigital <kontakt@mdigital.com.pl>
License: MIT License
        
        Copyright (c) 2023 Your Name
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://github.com/krystianmagdziarz/djinsight
Project-URL: Documentation, https://djinsight.readthedocs.io/
Project-URL: Repository, https://github.com/krystianmagdziarz/djinsight.git
Project-URL: Bug Tracker, https://github.com/krystianmagdziarz/djinsight/issues
Project-URL: Changelog, https://github.com/krystianmagdziarz/djinsight/blob/main/CHANGELOG.md
Keywords: django,wagtail,analytics,statistics,page-views,redis,celery
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 3.2
Classifier: Framework :: Django :: 4.0
Classifier: Framework :: Django :: 4.1
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Framework :: Wagtail
Classifier: Framework :: Wagtail :: 3
Classifier: Framework :: Wagtail :: 4
Classifier: Framework :: Wagtail :: 5
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Django>=3.2
Provides-Extra: dev
Requires-Dist: pytest>=6.0; extra == "dev"
Requires-Dist: pytest-django>=4.0; extra == "dev"
Requires-Dist: pytest-cov>=3.0; extra == "dev"
Requires-Dist: black>=22.0; extra == "dev"
Requires-Dist: flake8>=4.0; extra == "dev"
Requires-Dist: isort>=5.0; extra == "dev"
Requires-Dist: mypy>=0.900; extra == "dev"
Requires-Dist: factory-boy>=3.0; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx>=4.0; extra == "docs"
Requires-Dist: sphinx-rtd-theme>=1.0; extra == "docs"
Provides-Extra: test
Requires-Dist: pytest>=6.0; extra == "test"
Requires-Dist: pytest-django>=4.0; extra == "test"
Requires-Dist: pytest-cov>=3.0; extra == "test"
Requires-Dist: factory-boy>=3.0; extra == "test"
Requires-Dist: coverage>=6.0; extra == "test"
Provides-Extra: redis
Requires-Dist: redis>=4.0.0; extra == "redis"
Requires-Dist: django-redis>=5.0.0; extra == "redis"
Provides-Extra: celery
Requires-Dist: redis>=4.0.0; extra == "celery"
Requires-Dist: django-redis>=5.0.0; extra == "celery"
Requires-Dist: celery>=5.0.0; extra == "celery"
Provides-Extra: mcp
Requires-Dist: mcp>=1.0.0; extra == "mcp"
Provides-Extra: wagtail
Requires-Dist: wagtail>=5.0; extra == "wagtail"
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# djinsight

**Track page views. Query with AI.**

Your Django app's analytics, exposed to Claude and AI agents via MCP.

[![PyPI version](https://badge.fury.io/py/djinsight.svg)](https://badge.fury.io/py/djinsight)
[![Python](https://img.shields.io/pypi/pyversions/djinsight.svg)](https://pypi.org/project/djinsight/)

---

## The Problem

You want page view analytics. But you also want Claude to answer questions like:

> "What are my top 5 articles this week?"

Most analytics packages don't talk to AI. djinsight does.

---

## Installation

```bash
pip install djinsight
```

Add to `settings.py`:

```python
INSTALLED_APPS += ['djinsight']

DJINSIGHT = {
    'ENABLE_TRACKING': True,
    'USE_REDIS': False,
    'USE_CELERY': False,
}
```

Run migrations:

```bash
python manage.py migrate
```

Add URLs to `urls.py`:

```python
urlpatterns = [
    path('djinsight/', include('djinsight.urls')),
]
```

Done.

---

## Usage

### Track a page

Add to any template:

```django
{% load djinsight_tags %}
{% track %}
```

That's it. Views are now tracked.

### Display stats

```django
{% stats metric="views" period="week" %}
{% stats metric="views" period="week" output="chart" %}
```

---

## Connect to Claude

1. Install with MCP support:

```bash
pip install djinsight[mcp]
```

2. Add to Claude Desktop config (`~/Library/Application Support/Claude/claude_desktop_config.json`):

```json
{
	"mcpServers": {
		"djinsight": {
			"command": "python",
			"args": ["-m", "djinsight.mcp"],
			"env": {
				"DJANGO_SETTINGS_MODULE": "your_project.settings"
			}
		}
	}
}
```

3. Restart Claude Desktop.

**13 tools available:**

- **Basic:** `get_page_stats`, `get_top_pages`, `list_tracked_models`
- **Periods:** `get_period_stats`, `compare_periods`
- **Trends:** `get_trending_pages`
- **Referrers:** `get_referrer_stats`, `get_traffic_sources`
- **Behavior:** `get_device_breakdown`, `get_hourly_pattern`
- **Cross-model:** `get_site_overview`, `compare_content_types`
- **Search:** `search_pages`

Now Claude can answer:

- "What are my top 10 pages this week?"
- "Where does my traffic come from?"
- "Which pages are trending up?"
- "Compare mobile vs desktop traffic"

---

## High Traffic?

Use Redis + Celery for async processing:

```python
DJINSIGHT = {
    'ENABLE_TRACKING': True,
    'USE_REDIS': True,
    'USE_CELERY': True,
    'REDIS_HOST': 'localhost',
}
```

Start Celery:

```bash
celery -A your_project worker -l info
celery -A your_project beat -l info
```

---

## Stats Tag Options

```django
{% stats metric="views" period="week" output="chart" chart_type="line" %}
```

| Parameter    | Options                                   |
| ------------ | ----------------------------------------- |
| `metric`     | `views`, `unique_views`                   |
| `period`     | `today`, `week`, `month`, `year`, `total` |
| `output`     | `text`, `chart`, `json`, `badge`          |
| `chart_type` | `line`, `bar`                             |

---

## Custom Backends

Swap any component:

```python
DJINSIGHT = {
    'PROVIDER_CLASS': 'myapp.providers.CustomProvider',
    'WIDGET_RENDERER': 'myapp.renderers.CustomRenderer',
}
```

---

## License

MIT

## Links

- [Issues](https://github.com/krystianmagdziarz/djinsight/issues)
- [CHANGELOG](CHANGELOG.md)
- [Migration Guide](MIGRATION_GUIDE.md)

## Sponsors

- [MDigital](https://mdigital.com.pl)
