Skip to content

Commit b4c3190

Browse files
committed
Ready for Django 2.2
1 parent d46e68d commit b4c3190

File tree

5 files changed

+185
-2
lines changed

5 files changed

+185
-2
lines changed

README.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,83 @@
1-
# django-plugin
2-
Want privacy friendly analytics for Django?
1+
# simpleanalytics for Django
2+
Want privacy friendly analytics for Django? You're at the right place.
3+
4+
# Installing it
5+
Install the plugin:
6+
7+
`pip install django-simpleanalytics`
8+
9+
# Using it
10+
Add the package to the `INSTALLED_APPS`:
11+
```python
12+
INSTALLED_APPS = [
13+
...,
14+
simpleanalytics,
15+
]
16+
```
17+
18+
Next use the `templatetag` in your template:
19+
```
20+
<!DOCTYPE html>
21+
{% load staticfiles simpleanalytics_tags %}
22+
<html>
23+
<head>
24+
<meta charset="utf-8">
25+
<title>{% block page_title %}{{ site.name }}{% endblock %}</title>
26+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
27+
...
28+
{% simple_analytics_sync %}
29+
...
30+
</head>
31+
<body>
32+
{% simple_analytics_noscript_block %}
33+
</body>
34+
</html>
35+
```
36+
37+
This will translate to roughly this:
38+
```
39+
<!DOCTYPE html>
40+
41+
<html>
42+
<head>
43+
<meta charset="utf-8">
44+
<title>brwnppr.com</title>
45+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
46+
...
47+
<script type="text/javascript" src="https://cdn.simpleanalytics.io/hello.js"></script>
48+
...
49+
</head>
50+
<body>
51+
<noscript><img src="https://api.simpleanalytics.io/hello.gif" alt="hello"></noscript>
52+
</body>
53+
</html>
54+
```
55+
56+
# More
57+
58+
This app has four templatetags:
59+
60+
- simple_analytics_sync
61+
- simple_analytics_async
62+
- simple_analytics_noscript_block
63+
- simple_analytics_noscript_img
64+
65+
`simple_analytics_sync` converts to a plain `<script>` tag without the `async`
66+
keyword.
67+
68+
`simple_analytics_async` converts to a plain `<script>` tag with the `async`
69+
keyword.
70+
71+
`simple_analytics_noscript_block` converts to an `<noscript>` block which
72+
includes an `img` element which is used to load the image. Use this when you
73+
don't have and don't need a `<noscript>` block on your page at all.
74+
75+
`simple_analytics_noscript_img` converts to an `<img>` tag which src points to
76+
the hello.img. Use this when you're using a `<noscript>` block and you want to
77+
add privacy friendly stats to your page.
78+
79+
# Compatibility
80+
81+
Tested on Django 2.2.
82+
83+

setup.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
3+
(c) 2019 by simpleanalytics.io. All rights reserved
4+
5+
This program is distributed in the hope that it will be useful, but is provided AS IS with ABSOLUTELY NO WARRANTY;
6+
The entire risk as to the quality and performance of the program is with you. Should the program prove defective,
7+
you assume the cost of all necessary servicing, repair or correction. In no event will any of the developers, or
8+
any other party, be liable to anyone for damages arising out of the use or inability to use the program.
9+
You may copy and distribute copies of the Program, provided that you keep intact all the notices that refer to the
10+
absence of any warranty.
11+
12+
"""
13+
from setuptools import setup
14+
15+
16+
setup(
17+
name='simpleanalytics',
18+
classifiers=[
19+
"Development Status :: 3 - Alpha",
20+
"Intended Audience :: Developers",
21+
"Environment :: Plugins",
22+
"License :: OSI Approved :: MIT License",
23+
# supported python versions
24+
"Programming Language :: Python",
25+
"Programming Language :: Python :: 3.5",
26+
"Programming Language :: Python :: 3.6",
27+
"Programming Language :: Python :: 3.7",
28+
"Topic :: Internet :: WWW/HTTP :: Dynamic Content :: Page Counters",
29+
"Framework :: Django :: 1.8",
30+
"Framework :: Django :: 1.9",
31+
"Framework :: Django :: 2.0",
32+
"Framework :: Django :: 2.1",
33+
"Framework :: Django :: 2.2",
34+
],
35+
version='0.1.4',
36+
description='simpleanalytics templatetags for Django',
37+
packages=['simpleanalytics', 'simpleanalytics.templatetags', ],
38+
author='simpleanalytics.io',
39+
author_email='support@mail.simpleanalytics.io',
40+
)

simpleanalytics/__init__.py

Whitespace-only changes.

simpleanalytics/templatetags/__init__.py

Whitespace-only changes.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""
2+
3+
(c) 2019 by simpleanalytics.io. All rights reserved
4+
5+
This program is distributed in the hope that it will be useful, but is provided AS IS with ABSOLUTELY NO WARRANTY;
6+
The entire risk as to the quality and performance of the program is with you. Should the program prove defective,
7+
you assume the cost of all necessary servicing, repair or correction. In no event will any of the developers, or
8+
any other party, be liable to anyone for damages arising out of the use or inability to use the program.
9+
You may copy and distribute copies of the Program, provided that you keep intact all the notices that refer to the
10+
absence of any warranty.
11+
12+
"""
13+
from django import template
14+
from django.utils.safestring import mark_safe
15+
16+
17+
register = template.Library()
18+
19+
20+
_script_element = 'https://cdn.simpleanalytics.io/hello.js'
21+
_img_element = 'https://api.simpleanalytics.io/hello.gif'
22+
23+
24+
register.simple_tag(
25+
func=lambda *args, **kwargs: mark_safe(
26+
'<script type="text/javascript" src="{script}"></script>'.format(
27+
script=_script_element,
28+
)
29+
),
30+
name='simple_analytics_sync',
31+
)
32+
33+
34+
register.simple_tag(
35+
func=lambda *args, **kwargs: mark_safe(
36+
'<script async type="text/javascript" src="{script}"></script>'.format(
37+
script=_script_element,
38+
)
39+
),
40+
name='simple_analytics_async',
41+
)
42+
43+
44+
# Installs the simpleanalytics noscript pixel wrapped in an noscript block
45+
register.simple_tag(
46+
func=lambda *args, **kwargs: mark_safe(
47+
'<noscript><img src="{img}" alt="hello"></noscript>'.format(
48+
img=_img_element,
49+
),
50+
),
51+
name='simple_analytics_noscript_block',
52+
)
53+
54+
# Installs the simpleanalytics noscript pixel in an image element
55+
register.simple_tag(
56+
func=lambda *args, **kwargs: mark_safe(
57+
'<img src="{img}" alt="">'.format(
58+
img=_img_element,
59+
),
60+
),
61+
name='simple_analytics_noscript_img',
62+
)

0 commit comments

Comments
 (0)