https://github.com/fourdigits/wagtail-cookie
WIP
https://github.com/fourdigits/wagtail-cookie
Last synced: about 1 year ago
JSON representation
WIP
- Host: GitHub
- URL: https://github.com/fourdigits/wagtail-cookie
- Owner: fourdigits
- Created: 2018-07-18T09:52:39.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-18T14:23:57.000Z (almost 8 years ago)
- Last Synced: 2025-02-05T05:41:24.068Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.rst
- Authors: AUTHORS.rst
Awesome Lists containing this project
README
Cookie
======
Reusable Wagtail app to setup a cookie wall.
Install
-------
pip install -e git+git ...#egg=cookie
Add 'cookie' AFTER your app. Also make sure 'django.contrib.sessions' is in installed apps:
INSTALLED_APPS = [
'your_app',
'cookie',
...
'django.contrib.sessions'
]
Make sure the session backend is enabled.
MIDDLEWARE = [
...
'django.contrib.sessions.middleware.SessionMiddleware',
...
]
Include cookie urls in your urls.py BEFORE wagtail urls:
from cookie import urls as cookie_urls
url_patterns = [
...
url(r'', include(cookie_urls, namespace='cookie')),
url(r'', include(wagtail_urls)),
]
Register the cookie settings in your wagtail_hooks.py:
from cookie.wagtail_hooks import AbstractCookie
@register_setting
class Cookie(AbstractCookie):
pass
Add the cookie template tag to your base template head section:
{% load cookie_tags %}
...
{% cookie_modal %}
Wrap all template code that set third_party cookies in a `{% if request|third_party_cookies %}`:
{% if request|third_party_cookies %}
{% include_block self %}
{% else %}
Schakel third cookies in om embeds te zien.
{% endif %}
Wrap all template code that set analytical cookies in a `{% if request|analytical_cookies %}`:
{% if request|analytical_cookies %}
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXX-XX');
{% endif %}
Override templates
------------------
If you want to customise the templates. Copy them to your own project:
$ cp cookie/templates/modal.html yourapp/templates/cookie/
Production
----------
As users create new sessions on your website, session data can accumulate in your session store. The django_session
database table will grow and needs to be cleaned up from time to time.
Setup a cronjob (Every day at 3AM) to run the clear sessions management command. Eg:
$ crontab -e
* 3 * * * cd /path/to/project && /path/to/python manage.py clearsessions --setttings=settings.production >/dev/null 2>&1