Support for map and analytics settings

This commit is contained in:
Oleg Lavrovsky 2017-05-10 16:40:06 +02:00
parent b57a833e11
commit 49053ff741
3 changed files with 75 additions and 1 deletions

View file

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-05-10 14:27
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('home', '0016_socialcontact'),
]
operations = [
migrations.AddField(
model_name='contact',
name='analytics',
field=models.CharField(blank=True, default='', help_text='Optional web analytics property code', max_length=60),
),
migrations.AddField(
model_name='contact',
name='map_url',
field=models.URLField(blank=True, help_text='Optional link of address to mapping provider', null=True),
),
migrations.AlterField(
model_name='socialcontact',
name='profile',
field=models.CharField(default='', help_text='Name of the account, e.g. @myaccount, or full URL', max_length=255),
),
]

View file

@ -59,6 +59,10 @@ class Contact(models.Model):
phone = models.CharField(max_length=40, default="")
email = models.EmailField(max_length=100, default="")
www = models.URLField(null=True, blank=True)
map_url = models.URLField(null=True, blank=True,
help_text="Optional link of address to mapping provider")
analytics = models.CharField(max_length=60, default="", blank=True,
help_text="Optional web analytics property code")
panels = Page.content_panels + [
FieldPanel('title_fr'),
@ -66,6 +70,8 @@ class Contact(models.Model):
FieldPanel('phone'),
FieldPanel('email'),
FieldPanel('www'),
FieldPanel('map_url'),
FieldPanel('analytics'),
]
def phone_link(self):
@ -74,6 +80,13 @@ class Contact(models.Model):
return 'mailto:%s' % self.email
def www_domain(self):
return self.www.replace('http://', '').replace('https://', '')
def is_google_analytics(self):
return self.analytics.startswith('UA-')
def get_piwik_analytics(self):
# When formatted as "server|site_id", assume Piwik
if not '|' in self.analytics: return False
sa = self.analytics.split('|')
return { 'server': sa[0], 'site': sa[1] }
def trans_title_styled(self):
v = self.trans_title.split(' ')
if len(v) != 3: return v

View file

@ -1,6 +1,10 @@
<address>
<p>{{ contact.trans_title }}<br>
{% if contact.map_url %}
<a href="{{ contact.map_url }}">{{ contact.address }}</a>
{% else %}
{{ contact.address }}
{% endif %}
</p>
<p>Tel. <a href="{{ contact.phone_link }}">{{ contact.phone }}</a><br>
<a href="{{ contact.email_link }}">{{ contact.email }}</a><br>
@ -14,3 +18,30 @@
{{ sc.network_title }}</a>
{% endfor %}
</div>
{% if contact.is_google_analytics %}
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', '{{ contact.analytics }}', 'auto');
ga('send', 'pageview');
</script>
{% elif contact.get_piwik_analytics %}
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(["setCookieDomain", document.domain]);
_paq.push(["setDomains", [document.domain,"*." + document.domain]]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//{{ contact.get_piwik_analytics.server }}";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', {{ contact.get_piwik_analytics.site }}]);
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+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
{% endif %}