This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

[bug 843732] Handle utm_source and utm_campaign

  • Loading branch information...
willkg committed Feb 20, 2014
1 parent 64c52ea commit 878db23c2444960b4a08af5c21d721c75fcdcb11
@@ -0,0 +1,72 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding field 'Response.source'
+ db.add_column(u'feedback_response', 'source',
+ self.gf('django.db.models.fields.CharField')(default=u'', max_length=100, null=True, blank=True),
+ keep_default=False)
+
+ # Adding field 'Response.campaign'
+ db.add_column(u'feedback_response', 'campaign',
+ self.gf('django.db.models.fields.CharField')(default=u'', max_length=100, null=True, blank=True),
+ keep_default=False)
+
+
+ def backwards(self, orm):
+ # Deleting field 'Response.source'
+ db.delete_column(u'feedback_response', 'source')
+
+ # Deleting field 'Response.campaign'
+ db.delete_column(u'feedback_response', 'campaign')
+
+
+ models = {
+ u'feedback.product': {
+ 'Meta': {'object_name': 'Product'},
+ 'db_name': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
+ 'display_name': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
+ 'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'notes': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'on_dashboard': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'slug': ('django.db.models.fields.CharField', [], {'max_length': '20'})
+ },
+ u'feedback.response': {
+ 'Meta': {'ordering': "['-created']", 'object_name': 'Response'},
+ 'browser': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'browser_version': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'campaign': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'channel': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'country': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '4', 'null': 'True', 'blank': 'True'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'device': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'happy': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'locale': ('django.db.models.fields.CharField', [], {'max_length': '8', 'blank': 'True'}),
+ 'manufacturer': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'platform': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'prodchan': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'product': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'source': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'translated_description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
+ 'user_agent': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'version': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'})
+ },
+ u'feedback.responseemail': {
+ 'Meta': {'object_name': 'ResponseEmail'},
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'opinion': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['feedback.Response']"})
+ }
+ }
+
+ complete_apps = ['feedback']
View
@@ -104,6 +104,11 @@ class Response(ModelBase):
browser_version = models.CharField(max_length=30, blank=True)
platform = models.CharField(max_length=30, blank=True)
+ source = models.CharField(max_length=100, blank=True, null=True,
+ default=u'')
+ campaign = models.CharField(max_length=100, blank=True, null=True,
+ default=u'')
+
created = models.DateTimeField(default=datetime.now)
class Meta:
@@ -401,6 +401,48 @@ def test_email_invalid(self):
# Bad email if the box is not checked is not an error.
eq_(r.status_code, 302)
+ def test_src_to_source(self):
+ """We capture the src querystring arg in the source column"""
+ url = reverse('feedback', args=('firefox.desktop.stable',))
+
+ r = self.client.post(url + '?src=newsletter', {
+ 'happy': 0,
+ 'description': u"I like the colors.",
+ })
+
+ self.assertRedirects(r, reverse('thanks'))
+
+ feedback = models.Response.objects.latest(field_name='id')
+ eq_(feedback.source, u'newsletter')
+
+ def test_utm_source_to_source(self):
+ """We capture the utm_source querystring arg in the source column"""
+ url = reverse('feedback', args=('firefox.desktop.stable',))
+
+ r = self.client.post(url + '?utm_source=newsletter', {
+ 'happy': 0,
+ 'description': u"I like the colors.",
+ })
+
+ self.assertRedirects(r, reverse('thanks'))
+
+ feedback = models.Response.objects.latest(field_name='id')
+ eq_(feedback.source, u'newsletter')
+
+ def test_utm_campaign_to_source(self):
+ """We capture the utm_campaign querystring arg in the source column"""
+ url = reverse('feedback', args=('firefox.desktop.stable',))
+
+ r = self.client.post(url + '?utm_campaign=20140220_email', {
+ 'happy': 0,
+ 'description': u"I like the colors.",
+ })
+
+ self.assertRedirects(r, reverse('thanks'))
+
+ feedback = models.Response.objects.latest(field_name='id')
+ eq_(feedback.campaign, u'20140220_email')
+
def test_deprecated_firefox_for_android_feedback_works(self):
"""Verify firefox for android can post feedback"""
data = {
View
@@ -79,6 +79,13 @@ def _handle_feedback_post(request, locale=None, product=None,
channel = smart_str(channel).lower()
version = smart_str(version)
+ # src, then source, then utm_source
+ source = request.GET.get('src', u'')
+ if not source:
+ source = request.GET.get('utm_source', u'')
+
+ campaign = request.GET.get('utm_campaign', u'')
+
data = form.cleaned_data
# Most platforms aren't different enough between versions to care.
@@ -109,6 +116,12 @@ def _handle_feedback_post(request, locale=None, product=None,
device=data.get('device', ''),
)
+ if source:
+ opinion.source = source[:100]
+
+ if campaign:
+ opinion.campaign = campaign[:100]
+
if product:
# If we picked up the product from the url, we use url
# bits for everything.

0 comments on commit 878db23

Please sign in to comment.