Skip to content

Commit

Permalink
feat: add plausible analytics & rm GTM
Browse files Browse the repository at this point in the history
  • Loading branch information
fivehanz committed Sep 13, 2024
1 parent 75c53c9 commit cb62bc8
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 37 deletions.
16 changes: 16 additions & 0 deletions base/migrations/0004_delete_googletagmanagersettings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 5.0.7 on 2024-09-13 17:16

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('base', '0003_googletagmanagersettings'),
]

operations = [
migrations.DeleteModel(
name='GoogleTagManagerSettings',
),
]
34 changes: 17 additions & 17 deletions base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ class NavigationSettings(BaseGenericSetting):
]


@register_setting
class GoogleTagManagerSettings(BaseSiteSetting):
""" google tag manager id settings """

class Meta:
verbose_name = "Google Tag Manager"

google_tag_manager_id = models.CharField(
verbose_name="Google Tag Manager ID",
max_length=255,
blank=True,
help_text='Begins with "GTM-"',
)

panels = [
FieldPanel("google_tag_manager_id"),
]
# @register_setting
# class GoogleTagManagerSettings(BaseSiteSetting):
# """ google tag manager id settings """

# class Meta:
# verbose_name = "Google Tag Manager"

# google_tag_manager_id = models.CharField(
# verbose_name="Google Tag Manager ID",
# max_length=255,
# blank=True,
# help_text='Begins with "GTM-"',
# )

# panels = [
# FieldPanel("google_tag_manager_id"),
# ]


class FormField(AbstractFormField):
Expand Down
1 change: 1 addition & 0 deletions hanz/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"wagtail.search",
"wagtail.admin",
"wagtail",
"plausible.contrib.wagtail",
"modelcluster",
"taggit",
"django.contrib.admin",
Expand Down
19 changes: 18 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ django-anymail = "<12,>=11.0"
wagtail-storages = "<2,>=1.1"
celery = "^5.4.0"
django-celery-beat = "^2.6.0"
django-plausible = "^0.5.0"


[tool.poetry.group.dev.dependencies]
Expand Down
22 changes: 3 additions & 19 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<!-- SEO -->
{% include "wagtailseo/meta.html" %}

Expand Down Expand Up @@ -36,7 +36,7 @@
{% compress css file tailwind %}
<link rel="stylesheet" href="{% static 'css/output.css' %}">
{% endcompress %}

{% block extra_css %}
{# Override this in templates to add extra stylesheets #}
{% endblock %}
Expand All @@ -45,22 +45,6 @@
{% compress js file htmx %}
<script defer src="{% static 'js/htmx.min.js' %}"></script>
{% endcompress %}

<!-- Google Tag Manager -->
{% block tracking %}
{% if settings.base.GoogleTagManagerSettings.google_tag_manager_id %}
{% compress js inline gtm %}
<script>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','{{ settings.base.GoogleTagManagerSettings.google_tag_manager_id }}');
</script>
{% endcompress %}
{% endif %}
{% endblock %}
<!-- end Google Tag Manager -->
</head>

<body class="bg-white dark:bg-gray-800 max-w-screen-xl mx-auto {% block body_class %}{% endblock %}" {% block body_attributes %}{% endblock %}>
Expand Down Expand Up @@ -97,7 +81,7 @@
<!-- }) -->
</script>
{% endcompress %}

{% block extra_js %}
{# Override this in templates to add extra javascript #}
{% endblock %}
Expand Down

0 comments on commit cb62bc8

Please sign in to comment.