Repository: mozmeao/snippets-service

Issue:
Fundraising click metrics are not collected in snippets-admin
It seems that Fundraising clicks follow a different pattern in telemetry and thus they don't get collected by snippets-admin etl.


Discussion:

Resolving patch:
diff --git a/snippets/base/admin/adminmodels.py b/snippets/base/admin/adminmodels.py
--- a/snippets/base/admin/adminmodels.py
+++ b/snippets/base/admin/adminmodels.py
@@ -1407,7 +1407,7 @@ class JobDailyPerformanceAdmin(admin.ModelAdmin):
         'adj_client_percentage',
         'data_fetched_on',
     ]
-    search_fields = ['job']
+    search_fields = ['id', 'job__id', 'job__snippet__id']
     fieldsets = [
         ('Metrics', {
             'fields': (
diff --git a/snippets/base/etl.py b/snippets/base/etl.py
--- a/snippets/base/etl.py
+++ b/snippets/base/etl.py
@@ -59,7 +59,12 @@ def process_rows(rows, date, key='message_id'):
         # place the event context. Extract information from both
         # places to identify the event.
         properties = json.loads(row.get('additional_properties', '{}'))
-        event = row['event_context'] or properties.get('value', '') or row['event']
+
+        # Fundraising metrics need special treatment.
+        if row['event_context'] == 'EOYSnippetForm' and row['event'] == 'CLICK_BUTTON':
+            event = 'CLICK'
+        else:
+            event = row['event_context'] or properties.get('value', '') or row['event']
 
         if event in ['CLICK_BUTTON', 'CLICK']:
             event = 'click'


Test patch:
diff --git a/snippets/base/tests/test_etl.py b/snippets/base/tests/test_etl.py
--- a/snippets/base/tests/test_etl.py
+++ b/snippets/base/tests/test_etl.py
@@ -86,6 +86,19 @@ def test_base(self):
                     'no_clients': 50,
                     'no_clients_total': 0,
                 },
+                {
+                    'message_id': '1000',
+                    'event_context': 'EOYSnippetForm',
+                    'event': 'CLICK_BUTTON',
+                    'additional_properties': (
+                        '{"source":"NEWTAB_FOOTER_BAR_CONTENT","id":"NEWTAB_FOOTER_BAR_CONTENT"}'
+                    ),
+                    'channel': 'release',
+                    'country_code': 'IT',
+                    'counts': 10,
+                    'no_clients': 4,
+                    'no_clients_total': 0,
+                },
                 # To be discarded
                 {
                     'message_id': '500',
@@ -216,14 +229,14 @@ def test_base(self):
         jdp1 = JobDailyPerformance.objects.filter(job_id=1000).order_by('-id')[0]
         self.assertEqual(jdp1.impression, 80)
         self.assertEqual(jdp1.impression_no_clients_total, 653)
-        self.assertEqual(jdp1.click, 11)
+        self.assertEqual(jdp1.click, 21)
         self.assertEqual(jdp1.block, 50)
         self.assertEqual(jdp1.dismiss, 0)
         self.assertEqual(jdp1.go_to_scene2, 0)
         self.assertEqual(jdp1.subscribe_error, 0)
         self.assertEqual(jdp1.subscribe_success, 0)
         self.assertEqual(jdp1.other_click, 0)
-        self.assertEqual(len(jdp1.details), 5)
+        self.assertEqual(len(jdp1.details), 6)
         for detail in [
                 {'event': 'click', 'counts': 11, 'channel': 'release',
                  'country': 'GR', 'no_clients': 12, 'no_clients_total': 0},