From: Radek Czajka Date: Mon, 16 Dec 2019 19:44:39 +0000 (+0000) Subject: More banners and stats. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/a5d97184b87b72f8fb964c862af0f54f3ef788c1?ds=inline;hp=1227b1201c537ea17e310f0faab4ead7cf0d25af More banners and stats. --- diff --git a/src/annoy/models.py b/src/annoy/models.py index 3df56b2ea..5b9009b0c 100644 --- a/src/annoy/models.py +++ b/src/annoy/models.py @@ -74,6 +74,14 @@ class DynamicTextInsert(models.Model): def __str__(self): return str(self.paragraphs) + @classmethod + def get_all(cls, request): + Membership = apps.get_model('club', 'Membership') + if Membership.is_active_for(request.user) and not request.user.is_staff: + return cls.objects.none() + return cls.objects.all() + + def choose(self): return self.dynamictextinserttext_set.order_by('?').first() diff --git a/src/annoy/static/annoy/banner.js b/src/annoy/static/annoy/banner.js index ee4561341..ad5dd66f8 100644 --- a/src/annoy/static/annoy/banner.js +++ b/src/annoy/static/annoy/banner.js @@ -12,21 +12,33 @@ $target.slideDown('fast'); $on.hide(); if (Modernizr.localstorage) localStorage.removeItem(tag); + _paq.push(['trackEvent', 'banner', 'unhide', $on.attr('data-target')]); }); $off.click(function() { $target.slideUp('fast'); $on.show(); if (Modernizr.localstorage) localStorage[tag] = true; + _paq.push(['trackEvent', 'banner', 'hide', $on.attr('data-target')]); }); if (Modernizr.localstorage) { if (!localStorage[tag]) { $on.hide(); $target.show(); + _paq.push(['trackEvent', 'banner', 'show', $on.attr('data-target')]); } } }); + $(document).on('click', ".annoy-banner a", function() { + banner = $(this).closest('.annoy-banner'); + _paq.push(['trackEvent', 'banner', 'click', banner.attr('id')]); + }); + $(document).on('click', ".dynamic-insert a", function() { + banner = $(this).closest('.dynamic-insert'); + _paq.push(['trackEvent', 'dynamic-insert', 'click', banner.attr('data-paragraphs'), banner.attr('data-textid')]); + }); + }); })(jQuery); diff --git a/src/annoy/static/annoy/banner.scss b/src/annoy/static/annoy/banner.scss index c9ddd2ded..e0e0f62d2 100644 --- a/src/annoy/static/annoy/banner.scss +++ b/src/annoy/static/annoy/banner.scss @@ -229,6 +229,7 @@ .dynamic-insert { background: orange; + margin: 1em 0; &.with-image { min-height: 120px; @@ -244,10 +245,12 @@ .text { padding: 2em; flex: 1; + align-self: center; } img { border-radius: 100%; margin: 1em; + align-self: center; } } } diff --git a/src/annoy/static/annoy/book_text.js b/src/annoy/static/annoy/book_text.js index 267d6e1bd..bef1f13d6 100644 --- a/src/annoy/static/annoy/book_text.js +++ b/src/annoy/static/annoy/book_text.js @@ -30,6 +30,7 @@ var counter = 0; $(".paragraph, .stanza").each(function() { var p = $(this); + if (p.prev().hasClass('anchor')) p = p.prev(); if (!underFold) { if (p.offset().top > fold) { underFold = true; diff --git a/src/annoy/templates/annoy/dynamic_insert.html b/src/annoy/templates/annoy/dynamic_insert.html index 8285e2486..6aa725852 100644 --- a/src/annoy/templates/annoy/dynamic_insert.html +++ b/src/annoy/templates/annoy/dynamic_insert.html @@ -1,8 +1,8 @@ {% load thumbnail %} {% with text=insert.choose %} -
- +
+
{{ text.text|safe|linebreaks }}
diff --git a/src/catalogue/templates/catalogue/player.html b/src/catalogue/templates/catalogue/player.html index 2a48500ef..57fb2ec72 100755 --- a/src/catalogue/templates/catalogue/player.html +++ b/src/catalogue/templates/catalogue/player.html @@ -14,6 +14,7 @@ {% stylesheet 'main' %} {% stylesheet "player" %} + {% tracking_code %} {% if book.cover_thumb %} @@ -69,6 +70,5 @@ {% javascript "player" %} - {% tracking_code %} diff --git a/src/catalogue/templates/catalogue/viewer_base.html b/src/catalogue/templates/catalogue/viewer_base.html index 37c81184d..16ad645cc 100644 --- a/src/catalogue/templates/catalogue/viewer_base.html +++ b/src/catalogue/templates/catalogue/viewer_base.html @@ -12,6 +12,7 @@ {% stylesheet "book_text" %} {% block extrahead %}{% endblock %} + {% tracking_code %} {% annoy_banner 'blackout' %} @@ -66,7 +67,6 @@ {% javascript "book_text" %} - {% tracking_code %} {% block extrabody %}{% endblock %} diff --git a/src/catalogue/views.py b/src/catalogue/views.py index cfed6ca4e..66a2b91b0 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -319,7 +319,7 @@ def book_text(request, slug): return render(request, 'catalogue/book_text.html', { 'book': book, 'book_text': book_text, - 'inserts': DynamicTextInsert.objects.all() + 'inserts': DynamicTextInsert.get_all(request) }) diff --git a/src/club/templates/club/membership_form.html b/src/club/templates/club/membership_form.html index 959bc30c9..2e0c2c50e 100644 --- a/src/club/templates/club/membership_form.html +++ b/src/club/templates/club/membership_form.html @@ -209,6 +209,8 @@
+{% chunk 'club_form_bottom' %} + {% endblock %} diff --git a/src/wolnelektury/templates/base/superbase.html b/src/wolnelektury/templates/base/superbase.html index 8bdd43129..bd7de37e0 100644 --- a/src/wolnelektury/templates/base/superbase.html +++ b/src/wolnelektury/templates/base/superbase.html @@ -30,6 +30,7 @@ {% stylesheet "main" %} {% block extrahead %}{% endblock %} + {% tracking_code %} @@ -173,8 +174,6 @@ {% javascript "base" %} - {% tracking_code %} - {% block extrabody %}{% endblock %} diff --git a/src/wolnelektury/templates/piwik/tracking_code.html b/src/wolnelektury/templates/piwik/tracking_code.html index f09a5c6e5..bbb0cdbf5 100644 --- a/src/wolnelektury/templates/piwik/tracking_code.html +++ b/src/wolnelektury/templates/piwik/tracking_code.html @@ -1,15 +1,17 @@ - + - + var _paq = window._paq || []; + {% for ab, abval in AB.items %} + _paq.push(['setCustomVariable', '{{ forloop.counter }}', "{{ ab }}", "{{ abval }}", "page"]); + {% endfor %} + _paq.push(['trackPageView']); + _paq.push(['enableLinkTracking']); + (function() { + var u="{{ url }}"; + _paq.push(['setTrackerUrl', u+'matomo.php']); + _paq.push(['setSiteId', '{{ id }}']); + var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; + g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); + })(); + +