Metadata-Version: 2.4
Name: datasette-google-analytics
Version: 0.1.1
Summary: Datasette plugin that adds Google Analytics tracking code to your Datasette instance
Home-page: https://github.com/ngshiheng/datasette-google-analytics
Author: Jerry Ng
License: MIT
Project-URL: Issues, https://github.com/ngshiheng/datasette-google-analytics/issues
Project-URL: CI, https://github.com/ngshiheng/datasette-google-analytics/actions
Project-URL: Changelog, https://github.com/ngshiheng/datasette-google-analytics/releases
Classifier: Framework :: Datasette
Classifier: License :: OSI Approved :: MIT License
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: datasette>=0.54
Provides-Extra: test
Requires-Dist: beautifulsoup4; extra == "test"
Requires-Dist: pytest-asyncio; extra == "test"
Requires-Dist: pytest; extra == "test"
Requires-Dist: python-semantic-release; extra == "test"
Provides-Extra: build
Requires-Dist: wheel; extra == "build"
Requires-Dist: build; extra == "build"
Requires-Dist: setuptools; extra == "build"
Dynamic: author
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: project-url
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# datasette-google-analytics

A [Datasette](https://datasette.io/) plugin that adds Google Analytics tracking code to your Datasette instance.

## Installation

Install this plugin in the same environment as Datasette:

```sh
pip install datasette-google-analytics
```

## Usage

Configure the plugin by adding a `metadata.json` file with your Google Analytics tracking ID:

```json
{
    "plugins": {
        "datasette-google-analytics": {
            "tracking_id": "G-XXXXXXXXXX"
        }
    }
}
```

Replace `G-XXXXXXXXXX` with your actual Google Analytics 4 tracking ID.

Then start Datasette with:

```sh
datasette --metadata metadata.json your-database.db
```

## Development

To set up this plugin locally:

```sh
cd datasette-google-analytics
python -m venv venv
source venv/bin/activate
pip install -e '.[test]'
```

## How This Works

1. The plugin creates a custom template that extends the default base template
2. It uses the `extra_template_vars` hook to pass the Google Analytics tracking ID to the template
3. It uses the `prepare_jinja2_environment` hook to modify the Jinjia2 environment by adding our template directories
4. The custom template adds the Google Analytics tracking code in the `extra_head` block

This approach follows Google's recommendations for placing the tracking code immediately after the `<head>` element.
