Skip to content

Commit

Permalink
Merge pull request #1 from keitaroinc/gtag
Browse files Browse the repository at this point in the history
Gtag
  • Loading branch information
FilipMitrovski authored Aug 22, 2024
2 parents fc8fa1a + bf241b1 commit 89c24b2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ckanext/alisea/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from ckan.plugins import toolkit as tk
import logging


def get_google_tag():
gtag = tk.config.get('ckan.alisea.gtag')
return gtag
10 changes: 10 additions & 0 deletions ckanext/alisea/plugin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit

from ckanext.alisea import helpers as h


class AliseaPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IConfigurer)
plugins.implements(plugins.ITemplateHelpers)


# IConfigurer
Expand All @@ -13,4 +16,11 @@ def update_config(self, config_):
toolkit.add_public_directory(config_, "public")
toolkit.add_resource("assets", "alisea")


# ITemplateHelpers
def get_helpers(self):
return {
'get_google_tag':h.get_google_tag
}


15 changes: 15 additions & 0 deletions ckanext/alisea/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% ckan_extends %}

{% block htmltag %}
{{ super() }}
{% block gtag %}
{% include 'snippets/gtm.html' %}
{% endblock %}
{% endblock %}

{% block bodytag %}
{{ super() }}
{% block gtm %}
{% include 'snippets/gtm_noscript.html' %}
{% endblock %}
{% endblock %}
7 changes: 7 additions & 0 deletions ckanext/alisea/templates/snippets/gtm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- Google Tag Manager -->
<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','{{ h.get_google_tag() }}');</script>
<!-- End Google Tag Manager -->
5 changes: 5 additions & 0 deletions ckanext/alisea/templates/snippets/gtm_noscript.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- Google Tag Manager (noscript) -->
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id={{ h.get_google_tag() }}" height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
<!-- End Google Tag Manager (noscript) -->

0 comments on commit 89c24b2

Please sign in to comment.