Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Plausible Code #428

Merged
merged 5 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions django_app/redbox_app/jinja2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import humanize
import jinja2
from compressor.contrib.jinja2ext import CompressorExtension
from django.conf import settings
from django.templatetags.static import static
from django.urls import reverse
from markdown_it import MarkdownIt
Expand Down Expand Up @@ -56,11 +57,20 @@ def environment(**options):
**extra_options,
},
)
env.filters.update(
{
"static": static,
"url": url,
"humanize_timedelta": humanize_timedelta,
"environment": settings.ENVIRONMENT,
}
)
env.globals.update(
{
"static": static,
"url": url,
"humanize_timedelta": humanize_timedelta,
"environment": settings.ENVIRONMENT,
}
)
return env
3 changes: 2 additions & 1 deletion django_app/redbox_app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@
CSP_DEFAULT_SRC = (
"'self'",
"s3.amazonaws.com",
"plausible.io",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this in DEFAULT as well as SCRIPT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes just tried with out and it thew an CSP error

)
CSP_SCRIPT_SRC = (
"'self'",
"plausible.io",
"'sha256-GUQ5ad8JK5KmEWmROf3LZd9ge94daqNvd8xy9YS1iDw='",
"plausible.io",
)
CSP_OBJECT_SRC = ("'none'",)
CSP_REQUIRE_TRUSTED_TYPES_FOR = ("'script'",)
Expand Down
10 changes: 10 additions & 0 deletions django_app/redbox_app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
<link rel="stylesheet" type="text/css" href="{{static('style.css')}}" />
{% endif %}


{% if environment | lower in ["dev", "preprod"] %}
<script defer
event-environment="{{environment}}"
data-domain="redbox-dev.ai.cabinetoffice.gov.uk" src="https://plausible.io/js/script.pageview-props.tagged-events.outbound-links.file-downloads.local.js"></script>
{% elif environment | lower == "prod" %}
<script defer
data-domain="redbox.ai.cabinetoffice.gov.uk" src="https://plausible.io/js/script.pageview-props.tagged-events.outbound-links.file-downloads.js"></script>
{% endif %}

<script type="module" src="{{static('js/libs/govuk-frontend.min.js')}}"></script>

</head>
Expand Down
Loading