Giter VIP home page Giter VIP logo

jberghoef / wagtail-tag-manager Goto Github PK

View Code? Open in Web Editor NEW
70.0 8.0 23.0 6.43 MB

A Wagtail add-on for managing scripts and tags. Ready to go with a cookie bar and consent management.

Home Page: https://pypi.org/project/wagtail-tag-manager/

License: BSD 3-Clause "New" or "Revised" License

JavaScript 14.49% Python 60.56% HTML 5.12% Makefile 0.67% CSS 10.53% TypeScript 6.25% SCSS 2.37%
gdpr cookies cookiebar consent consent-management cookie-declarations cookie-consent tag-management

wagtail-tag-manager's Introduction

Wagtail Tag Manager

CircleCI CodeCov Codacy License Fossa Version Downloads Black Prettier Gitpod ready-to-code

Wagtail Tag Manager (WTM for short) is a Wagtail addon that allows for easier and GDPR compliant administration of scripts and tags.

Screenshot

In this package the term "tag" is being used for code snippets being injected into HTML. This is not to be confused with tags used to identify content in the CMS, such as pictures and documents.

‼️ Breaking changes

As of version 2.0, consent is stored differently in the wtm cookie. The reason for this change is to prevent so-called "cache-busting" and only refresh the WTM cookie after a certain period of time (specified in WTM_COOKIE_REFRESH). The cookie will now contain a base64 and uri encoded JSON string which stores both the consent state and additional information. Old versions of the cookie (e.g. necessary:true|preferences:unset|statistics:pending|marketing:false) will automatically be upgraded when detected. Once decoded, it will look something like this:

{
  "meta": {
    "id": "b402114a-352f-488f-8481-834cd91a1b2b",
    "refresh_timestamp": 1694520568.531865,
    "set_timestamp": 1694520573.685324
  },
  "state": {
    "necessary": "true",
    "preferences": "unset",
    "statistics": "pending",
    "marketing": "false"
  }
}

To easily parse the cookie using JavaScript, you can use this code snippet:

const { meta, state } = JSON.parse(atob(decodeURIComponent(cookie_content_goes_here)));

You can ready more on how to easily access this state from your front-end here.

Features

Wagtail Tag Manager offers functionality similar to platforms like Adobe Dynamic Tag Management, Google Tag Manager and Tealium iQ without the need of a third party. It's fully integrated into Wagtail.

This approach comes with a couple of advantages, most prominently the ability to inject tags into a page before the response is send to a client.

Administrators

  • Manage scripts and tags from within Wagtail, with powerful options to define load order.
  • Store reusable content in constants and variables and easily add them to your tags.
  • Create triggers to load tags based on events in the browser.
  • Create cookie declarations to provide end-users with a full picture of the tracking taking place.

Developers

  • Create custom variables to give administrators functionality specific to your use-cases.

Table of content

Disclaimer

This package attempts to ease the implementation of tags by the new ePrivacy rules as defined by the European Union. I urge you to read about these new rules and ensure you are properly configuring your tags. This package is free and the author can not be held responsible for the correctness of your implementation, or the assumptions made in this package to comply with the new ePrivacy regulation.

Read more about the ePrivacy Regulation.

Included in this package is a cookie bar which admittedly provides too little information to end users regarding the purpose of the scripts you are placing on the website. For compliance, please use the cookie_bar.html template to change the text shown in the cookie bar.

Requirements

Package Version(s)
Django 3.2, 4.0, 4.1, 4.2
Wagtail 4.1, 4.2, 5.0. 5.1
Python 3.8, 3.9, 3.10, 3.11

Instructions

Installation:

pip install wagtail-tag-manager

Add the application to your INSTALLED_APPS:

INSTALLED_APPS = [
    # ...
    'wagtail_modeladmin',
    'wagtail_tag_manager',
    # ...
]

If you wish to enable the cookie bar settings (allowing you to change to title and text displayed in the cookie bar), also include wagtail.contrib.settings in the INSTALLED_APPS.

Include the middleware:

MIDDLEWARE = [
    # ...
    "wagtail_tag_manager.middleware.CookieConsentMiddleware",
    'wagtail_tag_manager.middleware.TagManagerMiddleware', # optional
    # ...
]

WTM offers two ways to implement it's functionality. You can either choose to use the TagManagerMiddleware (which will rewrite the html on each request) or use the {% wtm_instant_tags %} and {% wtm_lazy_manager %} template tags.

If you prefer to use the template tags to inject tags into your templates, set the WTM_INJECT_TAGS and WTM_INJECT_SCRIPT settings to False and implement the template tags as follows:

{% load wtm_tags %}

<head>
  {% wtm_instant_tags 'top_head' %} ... {% wtm_instant_tags 'bottom_head' %}
</head>
<body>
  {% wtm_instant_tags 'top_body' %} ... {% wtm_instant_tags 'bottom_body' %} {% wtm_lazy_manager %}
</body>

Include the urls:

from django.urls import include, path
from wagtail_tag_manager import urls as wtm_urls

urlpatterns = [
    # ...
    path('wtm/', include(wtm_urls)),
    # ...
    path('', include(wagtail_urls)),
    # ...
]

Template tags

As an alternative to using the middleware you can use the wtm_instant_tags and wtm_lazy_manager template tags. Please be sure to use the TagManagerMiddleware OR the template tags, never both.

wtm_instant_tags

To load all instant tags at once:

{% load wtm_tags %}

<head>
  ... {% wtm_instant_tags %}
</head>

To load tags corresponding to a certain position:

{% load wtm_tags %}

<head>
  {% wtm_instant_tags 'top_head' %} ... {% wtm_instant_tags 'bottom_head' %}
</head>
<body>
  {% wtm_instant_tags 'top_body' %} ... {% wtm_instant_tags 'bottom_body' %}
</body>

wtm_lazy_manager

{% load wtm_tags %}

<body>
  ... {% wtm_lazy_manager %}
</body>

Optionally, you can disable either the script and/or the styling.

{% load wtm_tags %}

<body>
  ... {% wtm_lazy_manager include_style=False include_script=False %}
</body>

wtm_cookie_bar

Cookie bar with form

Cookie bar with form and details

{% load wtm_tags %}

<body>
  {% wtm_cookie_bar %} ...
</body>

wtm_include

WTM comes with the wtm_include template tag to accommodate loading of resources and markup based on the tag strategy and consent given. It can be used as a way to load html, css or javascript files.

{% load wtm_tags %}

<body>
  ... {% wtm_include "necessary" "css/style.css" %} {% wtm_include "necessary" "js/style.js" %} {%
  wtm_include "necessary" "content.html" %} ...
</body>

Alternatively, you can use it as a block:

{% load wtm_tags %}

<body>
  ... {% wtm_include "statistics" %}
  <script>
    console.log("Included conditionally");
  </script>
  {% wtm_endinclude %} ...
</body>

Preference management

You can use the following provided template tags to render a tag status overview, a table with cookie declarations or a consent form.

{% wtm_tag_table %} {% wtm_declaration_table %} {% wtm_manage_form %}

Context processors

To enable the context processors, add the following to your settings:

"context_processors": [
    # ...
    "wagtail_tag_manager.context_processors.consent_state",
]

You can now use the following value in your templates:

{{ wtm_consent_state.necessary }} {{ wtm_consent_state.preferences }} {{
wtm_consent_state.statistics }} {{ wtm_consent_state.marketing }}

These will return a boolean indicating wether or not tags specific to the corresponding state should load.

Settings

WTM_TAG_TYPES

WTM_TAG_TYPES = {
    # key, verbose name, setting
    "necessary": (_("Necessary"), "required"),
    "preferences": (_("Preferences"), "initial"),
    "statistics": (_("Statistics"), "initial"),
    "marketing": (_("Marketing"), ""),
}

Allows you to define the tag types available. This can be helpful if you'd like the change the terminology used, or when you'd prefer to split a type in multiple sections. Notice the two keywords (required and initial) used.

Tags marked as required can not be disabled and will always be included on every page.

Tags marked as initial will be included as long as no explicit consent has been given by the end user, provided the browser allows cookies. While no consent has been given, these tags will be loaded lazily to honor the browser settings (which we can only read using javascript).

The third option is to mark a tag as delayed. This will ensure the tag will not load on the first page load, but only from the second load forward.

WTM_INJECT_TAGS

WTM_INJECT_TAGS = True

Instructs the middleware to inject all tags marked "instant load" in the document. Disable this if you would rather use the {% wtm_instant_tags %} template tags.

WTM_MANAGE_VIEW

WTM_MANAGE_VIEW = True

Allows you to enable or disable the included "manage" view allowing users to get insight in the tags running on your site and adjust their preferences. The view is enabled by default.

WTM_COOKIE_EXPIRE

WTM_COOKIE_EXPIRE = 365

Sets the expiration time in days of WTM's cookies. Notice that this is only applicable to the consent cookies used by WTM, not any cookies placed by tags.

WTM_COOKIE_REFRESH

WTM_COOKIE_REFRESH = 30

Sets the refresh time in days of WTM's cookies. Notice that this is only applicable to the consent cookies used by WTM, not any cookies placed by tags.

WTM_CACHE_TIMEOUT

WTM_CACHE_TIMEOUT = 1800

Sets the amount of seconds the cache will be preserved. At the moment, caching is only applied to constants, which will refresh when a constant is saved. Default is 30 minutes.

WTM_PRESERVE_VARIABLES

WTM_PRESERVE_VARIABLES = True

Configures whether the variables are preserved for each request, or refreshed for each tag applied to a response. When set to False, a query will be done for each single tag which will add up quickly.

WTM_INJECT_STYLE

WTM_INJECT_STYLE = True

Change to False to prevent WTM's included styles from loading. This is useful if you wish to style the cookiebar yourself.

WTM_INJECT_SCRIPT

WTM_INJECT_SCRIPT = True

Change to False to prevent WTM's included scripts from loading. This is useful if you don't want to use the inlcuded lazy loading and cookie bar functionality. While enabled, the script will expose the window.wtm.consent() function. When called, the function will retrieve the current consent state and information from the wtm cookie. This will like something like this:

{
  "meta": {
    "id": "b402114a-352f-488f-8481-834cd91a1b2b",
    "refresh_timestamp": 1694520568.531865,
    "set_timestamp": 1694520573.685324
  },
  "state": {
    "marketing": "false",
    "necessary": "true",
    "preferences": "true",
    "statistics": "true"
  }
}

WTM_SUMMARY_PANELS

WTM_SUMMARY_PANELS = False

Disables or enables the summary panels visible on the Wagtail admin dashboard.

Admin summary panels

WTM_ENABLE_SCANNER

This is an experimental feature.

WTM_ENABLE_SCANNER = False

When enabled, allows scanning of cookies placed on the website. Use this to automatically generate cookie declarations. Will attempt to use Chrome Driver when available, and will fall back to regular requests if not.

WTM_CHROMEDRIVER_URL

This is an experimental feature.

WTM_CHROMEDRIVER_URL = "http://0.0.0.0:4444/wd/hub"

Allows configuration of the docker container running an instance of selenium/standalone-chrome.

When developing, use the following command to run the docker container and ensure that your site is configured be accessible over your computer's public ip. Otherwise the docker container won't be able to access the website.

https://hub.docker.com/r/selenium/standalone-chrome/

Custom variables

In addition to managing variables in the admin interface, variables can also be created in your source code by registering a CustomVariable.

from wagtail_tag_manager.decorators import register_variable
from wagtail_tag_manager.options import CustomVariable

@register_variable
class Variable(CustomVariable):
    name = "Custom variable"
    description = "Returns a custom value."
    key = "custom"

    def get_value(self, request):
        return "This is a custom variable."

Admin custom variables

Page tag mixin

If you would like to include tags on a page, include the TagMixin mixin. Under the "Settings" tab of the corresponding page type a list of tags will be shown. By selecting these, these tags will be included when the page loads.

Additionally, by selecting the "Include children" field, all descending pages of the configured page will also load the chosen tags.

Note that the consent state is being applied to these tags. If the selected tag is marked as, for example, "marketing", the end-user still must allow this type of tags before is is being injected.

from wagtail_tag_manager.mixins import TagMixin

class HomePage(TagMixin, Page):
    pass

Tag mixin admin

Lazy triggers

Triggers allow you to monitor events on the frontend of your website and load a tag after a specified event has occurred. By using conditions you are able to harness (custom) variables to only trigger a tag once your event complies with the conditions that you specified.

Trigger admin

Sandbox

To experiment with the package you can use the sandbox provided in this repository. To install this you will need to create and activate a virtualenv and then run make sandbox. This will start a fresh Wagtail install, with the tag manager module enabled, on http://localhost:8000 and http://localhost:8000/cms/. The superuser credentials are superuser with the password testing.

Various types of tags, constants and variables are enabled out of the box. Check out the console in your browser to see them in action.

Concept

WTM comes with the following tag types pre-configured:

Name Setting
Necessary Required
Preferences Initial
Statistics Initial
Marketing Default

These types correspond to the segmentation made by the EU here.

State Required Initial Delayed Default
No cookies accepted. yes no no no
Cookies implicitly accepted through browser settings. yes yes yes¹ no
Cookies explicitly accepted, noting tracking functionality.² yes yes yes¹ yes

¹ From the second page load onward.

² According to the ePrivacy regulation, mentioning that you are using tracking functionality is mandatory.

Note that in the case of Statistics cookies or local storage, you are obliged to still show a notification at least once, noting that you are using cookies for analytical and performance measurement purposes.

When implementing Marketing cookies, the user has to explicitly give permission for you to enable them for their session. When asking for permission, you must explicitly state the tracking functionality of the script you are using.

To ease the implementation by this concept, Wagtail Tag Manager allows you to define a tag as "Necessary", "Preferences", "Statistics" or "Marketing". When properly configured, it'll take care of loading the correct tag at the correct time, taking in account the following scenario's:

  1. The user has not accepted cookies.

    Required Initial Delayed Default
    Instant yes no no no
    Lazy yes no no no
  2. The user has accepted cookies through browser settings.

    Required Initial Delayed Default
    Instant yes yes¹ yes² no
    Lazy yes yes yes² no

    ¹ Will be loaded lazily.

    ² From the second page load onward.

    As the acceptance of "Initial" tags can only be verified client side, we'll first load all the "Initial" tags lazy (whether they are instant or not).

    Please note that we still have to show a message stating that we are using tags with analytical purposes.

  3. The user has explicitly accepted cookies for your site.

    Required Initial Delayed Default
    Instant yes yes yes yes
    Lazy yes yes yes yes

Who’s using it?

I'd love to hear from sites and applications where WTM is being used. Please contact me if you'd like your implementation to be listed here!

License

To make Wagtail Tag Manager accessible, it's is published under the BSD 3-Clause "New" or "Revised" License. For more information, please refer to the LICENSE file in this repository.

FOSSA Status

wagtail-tag-manager's People

Contributors

davidweterings avatar dependabot[bot] avatar ekersten avatar garrettc avatar igoranze avatar jberghoef avatar nnist avatar ntbrown avatar shaquille-lab avatar zuse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wagtail-tag-manager's Issues

Docs compatiblity

This is a great plugin!!!!

Docs say only compatible to 3.0. Maybe update it?
Currently it not installs for 4.1 with pip. So docs are true :)

Wagtail 2.11, 2.12, 2.13, 2.14, 2.15, 2.16, 3.0

Admin descriptions for specific features

Is your feature request related to a problem? Please describe.
The applications contains a couple of terms (eg. "variables" and "triggers") that are not self-explanatory.

Describe the solution you'd like
Some information popups on the corresponding detail pages with a concise description of functionality and what to expect when using the functionality.

Additional context
image (1)
image

Page tags

Allow tags to be added per page, with option to include tags in all underlying pages.

Relates to pull request #32 in branch feature/page-tag-inclusion

Can't be used with wagtail 6.0.0.

Describe the bug
Can't be used with wagtail 6.0.0.

To Reproduce
Steps to reproduce the behavior:
In my case

  1. add package to pipfile
  2. run pipenv lock
  3. See error
    CRITICAL:pipenv.patched.pip._internal.resolution.resolvelib.factory:Cannot install -r C:\Users\User\AppData\Local\Temp\pipenv-ei_tpsd4-requirements\pipenv-vdw1fhj6-constraints.txt (line 2) and wagtail==6.0 because these package versions have conflicting dependencies.

Selenium tests

Add selenium tests for proper testing of the lazy loading functionality.

Cookie declaration scanner fallback

Add option to the cookie declaration scanner to use requests to scrape cookies (instead of webdriver) when no better options are available.

AttributeError - 'NoneType' object has no attribute 'get_parent'

Describe the bug
Added application, cookie consent middleware, urls and template tags to my project, as the readme specifies.
I made sure not to include the other middleware since I'm using the template tags directly in the templates.

The tags cause the following traceback however.

Additional context

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 145, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 143, in _get_response
    response = response.render()
  File "/usr/local/lib/python3.7/site-packages/django/template/response.py", line 105, in render
    self.content = self.rendered_content
  File "/usr/local/lib/python3.7/site-packages/django/template/response.py", line 83, in rendered_content
    return template.render(context, self._request)
  File "/usr/local/lib/python3.7/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/base.py", line 171, in render
    return self._render(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.7/site-packages/django/template/library.py", line 214, in render
    _dict = self.func(*resolved_args, **resolved_kwargs)
  File "/usr/local/lib/python3.7/site-packages/wagtail_tag_manager/templatetags/wtm_tags.py", line 108, in wtm_instant_tags
    for tag in TagStrategy(request).result:
  File "/usr/local/lib/python3.7/site-packages/wagtail_tag_manager/strategy.py", line 163, in result
    result = [*self._get_tags_for_request(), *self._get_tags_for_page()]
  File "/usr/local/lib/python3.7/site-packages/wagtail_tag_manager/strategy.py", line 200, in _get_tags_for_page
    while parent.get_parent():

Exception Type: AttributeError at /
Exception Value: 'NoneType' object has no attribute 'get_parent'

Accept all / Reject all buttons

Is your feature request related to a problem? Please describe.
If there are multiple checkboxes on the cookie bar then it is not a good user experience to check/uncheck all.
Having a quicker method would improve the user experience.

Describe the solution you'd like
Optional "Accept all" and "Reject all" buttons - with configurable styles so it is easy to distinguish them.
When The buttons are pressed, the checkboxes are filled in accordingly, and the form is submitted.

Describe alternatives you've considered
The alternative is the current solution we have.

Additional context
The possibility to have the "Accept all" button increases the chance that users allow more cookies out of mere convenience. Similarly, the "Reject all" is saving some time for those that are more careful.

Tag manager installation downgrades wagtail

Collecting wagtail<2.12,>=2.1
Using cached wagtail-2.11.6-py3-none-any.whl (11.0 MB)

Installing collected packages: wagtail
Attempting uninstall: wagtail
Found existing installation: wagtail 2.12.3
Uninstalling wagtail-2.12.3:
Successfully uninstalled wagtail-2.12.3
Successfully installed wagtail-2.11.6

Accept all button cookie_bar

Hey,
is it possible to add an accept all button to the cookie_bar and deselect "Preferences" and "Statistics" by default?

Wagtail Tag Manager breaks sitemap generator

Describe the bug
WTM seems to break the generation of the sitemap.xml.

Traceback (most recent call last):
  File "venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "venv/lib/python3.7/site-packages/wagtail_tag_manager/middleware.py", line 31, in __call__
    self._add_instant_tags()
  File "venv/lib/python3.7/site-packages/wagtail_tag_manager/middleware.py", line 55, in _add_instant_tags
    body.append(element)
AttributeError: 'NoneType' object has no attribute 'append'

To Reproduce
Install WTM with middleware enabled according to docs

Load sitemap in your urls
path('^sitemap.xml$', sitemap),

from wagtail.contrib.sitemaps.views import sitemap

add it to urls

Expected behavior
Sitemap.xml should be generated

Screenshots
No need, see above

Desktop (please complete the following information):

  • OS: Ubuntu
  • Browser: All
  • Version: wagtail-tag-manager==0.20.1, wagtail==2.6.2

Additional context
Add any other context about the problem here.

End-user accessibility

Verify accessibility of the built in user-facing functionalities such as the cookie bar and other template tag rendered views.

wtm_include with EmbedBlock

I have this in a HTML template:

        {% wtm_include "media" %}
            <div class="twitter-tweet-wrapper col-xs-20 col-md-14">
                {{ value.embed }}
            </div>
        {% wtm_endinclude %}

This is triggering the following error:

'dict' object has no attribute 'template'

Which seems to be triggered by:

'dict' object has no attribute 'use_tz'

If I remove the wtm_include wrappers, it renders without error.

I'm using WTM 1.2.1 at the moment...

Make included static files configurable

I think it should be possible to decide, if wtm.bundle.js and wtm.bundle.css are included, when using the middleware or the templatetags. wtm.bundle.css makes the customization of the cookie bar pretty hard.

Cannot install Wagtail==4.2.4. because setup.py requires wagtail-modeladmin>=1.0.0 which requires Wagtail>=5

Describe the bug
Cannot install Wagtail==4.2.4 because wagtail-modeladmin requires Wagtail >= 5 and wagtail-tag-manager requires "wagtail_modeladmin>=1.0.0,<1.1.0",

"wagtail_modeladmin>=1.0.0,<1.1.0",

To Reproduce
Steps to reproduce the behavior:

  1. pip install -r requirements/base.txt with Wagtail<=5.0.0
    2.ERROR: Cannot install -r requirements/base.txt (line XX), wagtail-tag-manager and wagtail==4.2.4 because these package versions have conflicting dependencies.

Expected behavior
That Wagtail Tag Manager worked with Wagtail 4.2.4 like the setup.py indicates.

Screenshots
Screenshot 2023-11-20 at 16 27 39

Additional context
Add any other context about the problem here.

Bug in regex searching

There's a pretty big bug that needs to be fixed in this when actually including the bundles.

If there's a pattern that is invalid it'll save, but raise an error on the backend when rendering as expected.

Some form of validation should be provided.

Python lower than 3.6 not supported

Describe the bug
When using python 3.5 or lower the following code is "invalid syntax"

return int(random.random() * 2_147_483_647)
                                         ^
SyntaxError: invalid syntax

The code can be found in "wagtail_tag_manager/config.py", line 140"

The underscore in numerical literals is not supported in lower versions of python: https://www.python.org/dev/peps/pep-0515/

To Reproduce
Steps to reproduce the behavior:

  1. Install everything with python3.5
  2. run migrations

Expected behavior
Migration file is created, but this does not happen because the code fails.

Desktop (please complete the following information):

  • Debian 9
  • Python 3.5
  • Wagtail 2.5.1 / Django 2.2.3

Cookie bar not shown when only required/default tag types are used

Describe the bug
When WTM_TAG_TYPES only contains default, or required types, the cookie bar does not show even at the first page load.

When any tag type is set to delayed or initial, the cookie bar shows at the first page load.

To Reproduce
Steps to reproduce the behavior:

  1. In the settings set WTM_TAG_TYPES to either "", or "required". Do not set "delayed" or "initial" for any tags.
  2. Load a page
  3. See the lack of the cookie banner

Expected behavior
The cookie banner is shown at first page load.

Screenshots
N/A

Desktop (please complete the following information):

  • OS: Linux
  • Browser: Chrome Version 101.0.4951.64 (Official Build) (64-bit) & Firefox 91.9.0esr (64-bit)
  • Version

Smartphone (please complete the following information):

  • Device: Sony Xperiz XZ1 Compact
  • OS: Android 9
  • Browser Chrome
  • Version 102.0.5005.59

** Installed packages **
wagtail-tag-manager==1.3.2

  • selenium [required: >=3.141.0,<3.142.0, installed: 3.141.0]
    • urllib3 [required: Any, installed: 1.26.9]
  • wagtail [required: >=2.11,<2.17, installed: 2.16.2]
    • anyascii [required: >=0.1.5, installed: 0.3.1]
    • beautifulsoup4 [required: >=4.8,<4.10, installed: 4.9.3]
      • soupsieve [required: >1.2, installed: 2.3.2.post1]
    • Django [required: >=3.2,<4.1, installed: 3.2.13]
      • asgiref [required: >=3.3.2,<4, installed: 3.5.2]
      • pytz [required: Any, installed: 2022.1]
      • sqlparse [required: >=0.2.2, installed: 0.4.2]
    • django-filter [required: >=2.2,<22, installed: 21.1]
      • Django [required: >=2.2, installed: 3.2.13]
        • asgiref [required: >=3.3.2,<4, installed: 3.5.2]
        • pytz [required: Any, installed: 2022.1]
        • sqlparse [required: >=0.2.2, installed: 0.4.2]
    • django-modelcluster [required: >=5.2,<6.0, installed: 5.3]
      • pytz [required: >=2015.2, installed: 2022.1]
    • django-taggit [required: >=2.0,<3.0, installed: 2.1.0]
      • Django [required: >=2.2, installed: 3.2.13]
        • asgiref [required: >=3.3.2,<4, installed: 3.5.2]
        • pytz [required: Any, installed: 2022.1]
        • sqlparse [required: >=0.2.2, installed: 0.4.2]
    • django-treebeard [required: >=4.5.1,<5.0, installed: 4.5.1]
      • Django [required: >=2.2, installed: 3.2.13]
        • asgiref [required: >=3.3.2,<4, installed: 3.5.2]
        • pytz [required: Any, installed: 2022.1]
        • sqlparse [required: >=0.2.2, installed: 0.4.2]
    • djangorestframework [required: >=3.11.1,<4.0, installed: 3.13.1]
      • django [required: >=2.2, installed: 3.2.13]
        • asgiref [required: >=3.3.2,<4, installed: 3.5.2]
        • pytz [required: Any, installed: 2022.1]
        • sqlparse [required: >=0.2.2, installed: 0.4.2]
      • pytz [required: Any, installed: 2022.1]
    • draftjs-exporter [required: >=2.1.5,<3.0, installed: 2.1.7]
    • html5lib [required: >=0.999,<2, installed: 1.1]
      • six [required: >=1.9, installed: 1.16.0]
      • webencodings [required: Any, installed: 0.5.1]
    • l18n [required: >=2018.5, installed: 2021.3]
      • pytz [required: >=2020.1, installed: 2022.1]
      • six [required: Any, installed: 1.16.0]
    • Pillow [required: >=4.0.0,<10.0.0, installed: 9.1.1]
    • requests [required: >=2.11.1,<3.0, installed: 2.27.1]
      • certifi [required: >=2017.4.17, installed: 2022.5.18.1]
      • charset-normalizer [required: ~=2.0.0, installed: 2.0.12]
      • idna [required: >=2.5,<4, installed: 3.3]
      • urllib3 [required: >=1.21.1,<1.27, installed: 1.26.9]
    • tablib [required: >=0.14.0, installed: 3.2.1]
    • telepath [required: >=0.1.1,<1, installed: 0.2]
    • Willow [required: >=1.4,<1.5, installed: 1.4.1]
    • xlsxwriter [required: >=1.2.8,<4.0, installed: 3.0.3]

Additional context
In many countries it is illegal to have consent boxed pre-checked. Therefore the correct approach there is to use only required or default type tags, in which case the cookie bar is not shown, so there's no chance that the user can be asked on a relatively easy way to give consent.

External WebDriver instance

Accommodate external use of a webdriver instance to avoid having to run webdriver in the same instance or container that Wagtail is running in.

Trigger methods

Research trigger methods in addition to the regex matching currently available.

  • Page load trigger (already built into the lazy tag loading mechanism)
  • Click trigger
  • Visibility of element trigger
  • Form submit trigger
  • History API change trigger
  • JavaScript error trigger
  • Scroll distance trigger
  • Timer-trigger
  • Custom trigger(?)

Source: https://support.google.com/tagmanager/topic/7679108

Missing migrations for Django 3.2.12

Describe the bug
Migrations are missing for this package on Django 3.2.12

To Reproduce
Steps to reproduce the behavior:

  1. Upgrade Django to version 3.2.12.
  2. Run python manage.py makemigrations and migration 0018 is created for this package.

Got the following output:

Migrations for 'wagtail_tag_manager':
 /python3.8/site-packages/wagtail_tag_manager/migrations/0018_auto_20220421_1356.py
    - Alter field id on constant
    - Alter field id on cookiebarsettings
    - Alter field id on cookieconsent
    - Alter field id on cookiedeclaration
    - Alter field id on tag
    - Alter field id on trigger
    - Alter field id on triggercondition
    - Alter field id on variable

Expected behavior
There shouldn't be any migrations for this package when upgrading Django.

CSRF issue - Admin Panel

Describe the bug
CSRF Token missing error in debug console.

Forbidden (CSRF token missing or incorrect.): /admin/wagtail_tag_manager/variable/create/
[15/Apr/2021 11:58:36] "POST /admin/wagtail_tag_manager/variable/create/ HTTP/1.1" 403 2513

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'admin panel'
  2. Click on 'Add ...' (tag, variable, constant... anything)
  3. Check console

Expected behavior
Need to handle CSRF or use exempt.

Screenshots
image

Desktop (please complete the following information):

  • OS: Ubuntu
  • Browser: Firefox

Pinned selenium version causes issues

Selenium's version is pinned to selenium>=3.141.0,<3.142.0 which makes dependency resolution impossible if the most recent version (4.13.0 at the moment) is also required by another package. Given that this dependency is only required for tests and an experimental (and disabled by default) feature, it would be nice if it were optional to install it if and only if someone wants to run tests or do cookie scanning.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.