Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
T-101 committed Mar 8, 2022
0 parents commit 1cc26cb
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode/*
.idea/*
dist/*
21 changes: 21 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Antti Rummukainen

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.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## Django Simple Plausible

A dead simple package to add Plausible Analytics html tag to your HTML. Tested with Python 2.7 and 3.8. Tested with Django 1.11 and 3.2.

### Usage

1. Install package: `pip install django_simple_plausible`

2. Add `django_simple_plausible` to your `INSTALLED_APPS` in settings.py

3. ADD `PLAUSIBLE_SITES` and `PLAUSIBLE_SCRIPT_URL` keys and values to your settings.py. Without these settings, default values for Plausible will be used.
```
...
PLAUSIBLE_SITES = "example.com"
PLAUSIBLE_SCRIPT_URL = "https://example.com/js/plausible.js"
...
```

4. add the following template tags to your site html:
```
{% load plausible %}
{% plausible %}
```

---

### Configuring details

- PLAUSIBLE_SITES can be a comma separated list without spaces, if you want to use that feature of Plausible

```
PLAUSIBLE_SITES = "example.com,yoursite.com"
```

- Systemwide settings can be overridden giving the template tag some optional parameters:

```
{% plausible plausible_sites="mysite.com" script_url="https://mysite.com/plausible.js" %}
```
5 changes: 5 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
python -m build
rm -rf *.egg-info
echo "Upload to TestPyPi: python -m twine upload --repository testpypi dist/*"
printf "Upload to PyPi: python -m twine upload dist/*\n\n"
Empty file.
Empty file.
21 changes: 21 additions & 0 deletions django_simple_plausible/templatetags/plausible.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django import template
from django.conf import settings
from django.forms.utils import flatatt
from django.utils.safestring import mark_safe

register = template.Library()


@register.simple_tag()
def plausible(site_domains=None, script_url=None):
if site_domains is None:
site_domains = getattr(settings, "PLAUSIBLE_SITES", "plausible.io")
if script_url is None:
script_url = getattr(settings, "PLAUSIBLE_SCRIPT_URL", "https://plausible.io/js/plausible.js")

attrs = {
"data-domain": site_domains,
"src": script_url,
}

return mark_safe("<script defer{}></script>".format(flatatt(attrs)))
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
]
build-backend = "setuptools.build_meta"
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
twine
28 changes: 28 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import codecs
import setuptools

with codecs.open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()

setuptools.setup(
name="django_simple_plausible",
# name="django_simple_plausible-T-101-0.0.2-3",
version="0.0.3",
author="T-101",
description="A simple Django package to render Plausible Analytics html tag",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/T-101/django-simple-plausible",
project_urls={},
classifiers=[
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Framework :: Django",
"Environment :: Web Environment",
],
packages=setuptools.find_packages(exclude=["tests"]),
python_requires=">=2.7",
options={"bdist_wheel": {"universal": True}},
)

0 comments on commit 1cc26cb

Please sign in to comment.