Add a 'do not track' setting on user profile that will prevent the use of Google Analytics and embedded social media buttons for the user

This commit is contained in:
Michael Hall 2018-08-03 22:56:48 -04:00
parent 8e5d8c9a7e
commit 1ff59d5d7d
7 changed files with 66 additions and 9 deletions

View file

@ -333,9 +333,10 @@ class UserForm(forms.ModelForm):
class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = ['avatar', 'realname', 'city', 'tz', 'send_notifications']
fields = ['avatar', 'realname', 'city', 'tz', 'send_notifications', 'do_not_track']
labels = {
'send_notifications': _('Send me notification emails'),
'do_not_track': _('Do not track'),
}
widgets = {
'city': Lookup(source=City),

View file

@ -0,0 +1,18 @@
# Generated by Django 2.0 on 2018-08-04 02:19
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0038_add_common_event_continent'),
]
operations = [
migrations.AddField(
model_name='userprofile',
name='do_not_track',
field=models.BooleanField(default=False, verbose_name='Do not track'),
),
]

View file

@ -39,6 +39,7 @@ class UserProfile(models.Model):
facebook = models.URLField(verbose_name=_('Facebook URL'), max_length=32, blank=True, null=True)
send_notifications = models.BooleanField(verbose_name=_('Send notification emails'), default=True)
do_not_track = models.BooleanField(verbose_name=_("Do not track"), default=False)
secret_key = models.UUIDField(default=uuid.uuid4, editable=True)

View file

@ -12,7 +12,7 @@
{% block meta %}{% endblock %}
{% if settings.GOOGLE_ANALYTICS_ID %}
{% if settings.GOOGLE_ANALYTICS_ID and not request.user.profile.do_not_track %}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{settings.GOOGLE_ANALYTICS_ID}}"></script>
<script>
@ -28,8 +28,13 @@
{% endfor %}
{% block extra_google_analytics %}{% endblock %}
</script>
{% else %}
{% comment %}delete any analytics events recorded in this session" {% endcomment %}
{% for event in ga_events %}{% endfor %}
{% endif %}
{% block scripts %}{% endblock %}
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="{% static 'css/bootstrap/css/bootstrap.min.css' %}">
<link href="{% static 'js/tether/css/tether.min.css' %}" rel="stylesheet">
@ -37,9 +42,7 @@
<link href="{% static 'css/get_together.css' %}" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- style overrides -->
{%block styles %}{% endblock %}
<style>
</style>
{% block styles %}{% endblock %}
</head>
<body>

View file

@ -28,6 +28,10 @@
}
</style>
{% endblock %}
{% block scripts %}
{% if not request.user.profile.do_not_track %}
{% if settings.SOCIAL_AUTH_FACEBOOK_KEY %}
<script>
window.fbAsyncInit = function() {
@ -59,6 +63,7 @@
}
</script>
{% endif %}
{% if settings.SOCIAL_AUTH_TWITTER_KEY %}
<script>window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
@ -78,8 +83,8 @@
}(document, "script", "twitter-wjs"));
</script>
{% endif %}
{% if settings.SOCIAL_AUTH_LINKEDIN_KEY %}
{% if settings.SOCIAL_AUTH_LINKEDIN_KEY %}
<script type="text/javascript">
// Use the API call wrapper to share content on LinkedIn
@ -92,7 +97,10 @@
'height=300,width=400');
}
</script>{% endif %}
</script>
{% endif %}
{% endif %}
{% endblock %}
{% block content %}
@ -108,7 +116,7 @@
<h2>{{ event.name }}</h2>
{% endif %}
<p class="text-muted">Hosted by <a href="{% url "show-team-by-slug" team.slug %}">{{ team.name }}</a></p>
{% if event.status != event.CANCELED %}
{% if event.status != event.CANCELED and not request.user.profile.do_not_track %}
{% if settings.SOCIAL_AUTH_TWITTER_KEY %}
<a href="https://twitter.com/intent/tweet?text=I'm+having+a+get+together!%0D{{event.name|urlencode}}&original_referer={{event.get_full_url|urlencode}}&url={{event.get_full_url|urlencode}}&hashtags=gettogether" data-size="large" class="btn btn-twitter btn-sm"><i class="fa fa-twitter"></i> Tweet</a>
{% endif %}

View file

@ -26,6 +26,10 @@
border-top: none;
}
</style>
{% endblock %}
{% block scripts %}
{% if not request.user.profile.do_not_track %}
{% if settings.SOCIAL_AUTH_FACEBOOK_KEY %}
<script>
window.fbAsyncInit = function() {
@ -57,6 +61,7 @@
}
</script>
{% endif %}
{% if settings.SOCIAL_AUTH_TWITTER_KEY %}
<script>window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
@ -75,7 +80,10 @@
return t;
}(document, "script", "twitter-wjs"));
</script>
{% endif %}{% endblock %}
{% endif %}
{% endif %}
{% endblock %}
{% block content %}
<div class="fluid-container container-primary">
@ -94,12 +102,14 @@
{% endif %}
<div class="mb-2">
{% if not request.user.profile.do_not_track %}
{% if settings.SOCIAL_AUTH_TWITTER_KEY %}
<a href="https://twitter.com/intent/tweet?text=I'm+having+a+get+together!%0D{{common_event.name|urlencode}}&original_referer={{common_event.get_full_url|urlencode}}&url={{common_event.get_full_url|urlencode}}&hashtags=gettogether" data-size="large" class="btn btn-twitter btn-sm"><i class="fa fa-twitter"></i> Tweet</a>
{% endif %}
{% if settings.SOCIAL_AUTH_FACEBOOK_KEY %}
<a href="#" onClick="shareFacebook();" class="btn btn-facebook btn-sm"><i class="fa fa-facebook-official"></i> Share</a>
{% endif %}
{% endif %}
</div>

View file

@ -53,6 +53,22 @@ $(document).ready(function(){
}
});
$("#id_tz").selectmenu()
$("#id_send_notifications").change(function(event) {
if (!this.checked) {
if (!window.confirm("If you opt out you will not receive emails reminding you of your upcoming events, when people join your team, or interact with your events.\n\nAre you sure you want to do this?")) {
this.checked = true;
}
}
});
$("#id_do_not_track").change(function(event) {
if (this.checked) {
if (!window.confirm("By opting out of tracking, your activity will not be included in site analytics that we use to improve GetTogether, and you will not you be shown sharing buttons that make it easy to promote teams and events to your social media accounts.\n\nAre you sure you want to do this?")) {
this.checked = false;
}
}
});
});
</script>
{% endblock %}