Skip to content

Commit

Permalink
[FEATURE] Allow Admin to set GTM code snippets via the backend instea…
Browse files Browse the repository at this point in the history
…d of having to edit the code
  • Loading branch information
Numkil committed Sep 3, 2024
1 parent 5065865 commit f259fad
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,58 @@ fieldLayouts:
name: Content
uid: bc4c53fd-5da6-434f-8b07-8bcc6776952a
userCondition: null
-
elementCondition: null
elements:
-
elementCondition: null
fieldUid: c372dc4c-2ba0-4569-89d6-b9e5d3641621 # GTM-Head
handle: null
includeInCards: false
instructions: null
label: null
providesThumbs: false
required: false
tip: null
type: craft\fieldlayoutelements\CustomField
uid: 517fbde2-ca3c-4bc7-bb47-d26c7e07749b
userCondition: null
warning: null
width: 100
-
elementCondition: null
fieldUid: 1722d8e6-c1d8-4e9c-824e-c97bb31fc8e6 # GTM-Body
handle: null
includeInCards: false
instructions: null
label: null
providesThumbs: false
required: false
tip: null
type: craft\fieldlayoutelements\CustomField
uid: f450f30e-1be1-4549-b856-89fc352757bf
userCondition: null
warning: null
width: 100
name: GTM-Codes
uid: b883e8f0-349c-4206-8d15-2165487a7299
userCondition:
class: craft\elements\conditions\users\UserCondition
conditionRules:
-
class: craft\elements\conditions\users\AdminConditionRule
uid: 724b5dae-7ea4-4a96-9b8f-9f93b5a922f2
value: true
elementType: craft\elements\User
fieldContext: global
handle: siteSettings
hasTitleField: false
icon: gear
name: 'Site Settings'
showSlugField: true
showStatusField: false
slugTranslationKeyFormat: null
slugTranslationKeyFormat: ''
slugTranslationMethod: site
titleFormat: '{section.name|raw}'
titleTranslationKeyFormat: null
titleTranslationKeyFormat: ''
titleTranslationMethod: site
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
columnSuffix: null
handle: gtmBody
instructions: 'Copy paste the GTM Body code snippet here.'
name: GTM-Body
searchable: false
settings:
byteLimit: null
charLimit: null
code: true
initialRows: 5
multiline: true
placeholder: null
uiMode: enlarged
translationKeyFormat: null
translationMethod: site
type: craft\fields\PlainText
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
columnSuffix: null
handle: gtmHead
instructions: "Copy paste the GTM Head code snippet here.\r\n"
name: GTM-Head
searchable: false
settings:
byteLimit: null
charLimit: null
code: true
initialRows: 5
multiline: true
placeholder: null
uiMode: enlarged
translationKeyFormat: null
translationMethod: site
type: craft\fields\PlainText
4 changes: 3 additions & 1 deletion config/project/project.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dateModified: 1721629473
dateModified: 1725366690
elementSources:
craft\elements\Entry:
-
Expand Down Expand Up @@ -300,6 +300,7 @@ meta:
776fa716-10bb-48bb-ae08-28870f9d77e7: Entries # Entries
838aabf9-a30e-4616-ad7c-b89fe15d7cae: 'Title (Anchor)' # Title (Anchor)
979c3eeb-f99a-4ca1-bcbe-ce9298a4e4ca: 'Public Files' # Public Files
1722d8e6-c1d8-4e9c-824e-c97bb31fc8e6: GTM-Body # GTM-Body
3196b984-5af4-44dd-a6db-ac2c8f7924d9: 'Content Managers' # Content Managers
03498d1a-eb01-4cb2-9e2b-623015ed0d85: 'Link Style' # Link Style
3857f4aa-a319-44ec-8b5e-d907d3d1bf31: 'Background Color' # Background Color
Expand Down Expand Up @@ -334,6 +335,7 @@ meta:
c7f05fcd-6b9c-44dd-baee-f3e9cd0c47ac: 'News Category' # News Category
c9d6819e-8ea5-4d16-91de-4c691d11b42d: New # New
c25b1e19-dca6-4ab5-a776-a043f6ee4c82: Login # Login
c372dc4c-2ba0-4569-89d6-b9e5d3641621: GTM-Head # GTM-Head
c2198cbb-f6e1-478a-ab4a-bbbaea43ce0e: 'Privacy policy' # Privacy policy
c576870d-abd8-46aa-8fe5-cdd12c40dfa8: 'News items' # News items
cd736fb3-c9b7-4ce1-88a8-da8b64249eb1: Images # Images
Expand Down
12 changes: 6 additions & 6 deletions templates/_site/_layout.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{% set baseUrl = craft.app.config.general.aliases.baseUrl %}
{% set currentLocale = craft.app.language|split('-') %}
{% set generalInfo = craft.entries.section('contact').status(null).one() %}
{% set fallback = craft.entries.section('siteSettings').status(null).one() %}

<!DOCTYPE html>
<html class="" lang="{{ currentLocale[0] }}">
<head>
Expand All @@ -14,12 +17,12 @@
{% if 'statik.be' in baseUrl %}
<meta name="robots" content="noindex">
{% endif %}

{% block head_scripts %}
<link rel="preconnect" href="//www.googletagmanager.com">
{# <link rel="preconnect" href="//fonts.gstatic.com"> #}
{% if not craft.app.request.isPreview() %}
{# put GTM here #}
{{ fallback.gtmHead | raw }}
{% endif %}
{% endblock %}

Expand All @@ -32,7 +35,7 @@
<body class="page-{{ craft.app.request.getSegment(1) ?: 'home' }} {% block bodyClasses %}{% endblock %} preload-transitions">
{% apply enkode_emails %}
{% if not craft.app.request.isPreview() %}
{# put GTM here #}
{{ fallback.gtmBody | raw }}
{% endif %}

{% if systemOffline is not defined %}
Expand All @@ -46,9 +49,6 @@
</a>
{% endif %}

{% set generalInfo = craft.entries.section('contact').status(null).one() %}
{% set fallback = craft.entries.section('siteSettings').status(null).one() %}

<div class="flex flex-col min-h-screen page-wrap " id="mainContentBlock">

<div class="sr-only skip-to-main ie-sr-only">
Expand Down

0 comments on commit f259fad

Please sign in to comment.