Add plausible analytics if env variable exists
This commit is contained in:
parent
698a2db6a7
commit
36c8a83018
5 changed files with 28 additions and 0 deletions
|
@ -37,3 +37,7 @@ def git_version(request):
|
|||
version = "latest"
|
||||
url = settings.BLOG["repo"]["log"]
|
||||
return {"git_version": version, "git_version_url": url}
|
||||
|
||||
|
||||
def plausible(request):
|
||||
return {"plausible_domain": settings.PLAUSIBLE_DOMAIN}
|
||||
|
|
3
articles/templates/articles/analytics.html
Normal file
3
articles/templates/articles/analytics.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
{% if plausible_domain is not None %}
|
||||
<script async defer data-domain="{{ plausible_domain }}" src="https://plausible.augendre.info/js/plausible.js"></script>
|
||||
{% endif %}
|
|
@ -11,6 +11,7 @@
|
|||
<script src="{% static 'toggle-dark-mode.js' %}" async></script>
|
||||
<link rel="alternate" type="application/rss+xml" title="Gab's Notes » Feed" href="{% url 'complete-feed' %}">
|
||||
{% include "articles/favicon.html" %}
|
||||
{% include "articles/analytics.html" %}
|
||||
</head>
|
||||
<body>
|
||||
<nav>
|
||||
|
|
|
@ -42,3 +42,20 @@ def test_access_article_by_slug(client: Client, published_article: Article):
|
|||
content = res.content.decode("utf-8")
|
||||
assert published_article.title in content
|
||||
assert published_article.get_formatted_content() in content
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_has_plausible_if_set(client: Client, settings):
|
||||
settings.PLAUSIBLE_DOMAIN = "gabnotes.org"
|
||||
res = client.get(reverse("articles-list"))
|
||||
content = res.content.decode("utf-8")
|
||||
assert "https://plausible.augendre.info/js/plausible.js" in content
|
||||
assert 'data-domain="gabnotes.org"' in content
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_doesnt_have_plausible_if_unset(client: Client, settings):
|
||||
settings.PLAUSIBLE_DOMAIN = None
|
||||
res = client.get(reverse("articles-list"))
|
||||
content = res.content.decode("utf-8")
|
||||
assert "https://plausible.augendre.info/js/plausible.js" not in content
|
||||
|
|
|
@ -100,6 +100,7 @@ TEMPLATES = [
|
|||
"articles.context_processors.drafts_count",
|
||||
"articles.context_processors.date_format",
|
||||
"articles.context_processors.git_version",
|
||||
"articles.context_processors.plausible",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -184,3 +185,5 @@ BLOG = {
|
|||
}
|
||||
|
||||
SHORTPIXEL_API_KEY = os.getenv("SHORTPIXEL_API_KEY")
|
||||
|
||||
PLAUSIBLE_DOMAIN = os.getenv("PLAUSIBLE_DOMAIN")
|
||||
|
|
Reference in a new issue