Sfoglia il codice sorgente

Remove discontinued Google Analytics support (Universal Analytics) (#593)

Google shut down Universal Analytics in June 2023, so it will no longer
work. We already support the successor, GA4, so this is just a removal
of the old stuff.
Vince Salvino 1 anno fa
parent
commit
823367e087

+ 16 - 0
coderedcms/migrations/0040_remove_analyticssettings_ga_tracking_id.py

@@ -0,0 +1,16 @@
+# Generated by Django 4.1.12 on 2023-10-20 16:29
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ("coderedcms", "0039_alter_classifierterm_slug"),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name="analyticssettings",
+            name="ga_tracking_id",
+        ),
+    ]

+ 4 - 4
coderedcms/models/tests/test_wagtailsettings_models.py

@@ -23,7 +23,7 @@ class AnalyticsSettingsTestCase(WagtailPageTests):
 
         # Populate settings.
         self.settings = AnalyticsSettings.for_site(self.site)
-        self.settings.ga_tracking_id = "UA-123"
+        self.settings.ga_g_tracking_id = "G-123"
         self.settings.head_scripts = "<script>evil_tracker</script>"
         self.settings.body_scripts = "<script>annoying_tracker</script>"
         self.settings.save()
@@ -35,12 +35,12 @@ class AnalyticsSettingsTestCase(WagtailPageTests):
         response = self.client.get(self.homepage.url, follow=True)
         self.assertEqual(response.status_code, 200)
 
-    def test_ga_tracking_id(self):
+    def test_ga_g_tracking_id(self):
         """
-        Make sure the ga_tracking_id is present.
+        Make sure the ga_g_tracking_id is present.
         """
         response = self.client.get(self.homepage.url, follow=True)
-        self.assertIn(self.settings.ga_tracking_id, str(response.content), 1)
+        self.assertIn(self.settings.ga_g_tracking_id, str(response.content), 1)
 
     def test_head_scripts(self):
         """

+ 0 - 9
coderedcms/models/wagtailsettings_models.py

@@ -265,14 +265,6 @@ class AnalyticsSettings(BaseSiteSetting):
     class Meta:
         verbose_name = _("Tracking")
 
-    ga_tracking_id = models.CharField(
-        blank=True,
-        max_length=255,
-        verbose_name=_("UA Tracking ID"),
-        help_text=_(
-            'Your Google "Universal Analytics" tracking ID (begins with "UA-")'
-        ),
-    )
     ga_g_tracking_id = models.CharField(
         blank=True,
         max_length=255,
@@ -321,7 +313,6 @@ class AnalyticsSettings(BaseSiteSetting):
         MultiFieldPanel(
             [
                 FieldPanel("ga_g_tracking_id"),
-                FieldPanel("ga_tracking_id"),
                 FieldPanel("ga_track_button_clicks"),
             ],
             heading=_("Google Analytics"),

+ 1 - 9
coderedcms/templates/coderedcms/pages/base.html

@@ -7,23 +7,15 @@
 
 <head>
   {% block tracking %}
-  {% if settings.coderedcms.AnalyticsSettings.ga_tracking_id or settings.coderedcms.AnalyticsSettings.ga_g_tracking_id %}
+  {% if settings.coderedcms.AnalyticsSettings.ga_g_tracking_id %}
   <!-- Global site tag (gtag.js) - Google Analytics -->
-  {% if settings.coderedcms.AnalyticsSettings.ga_tracking_id %}
-  <script async src="https://www.googletagmanager.com/gtag/js?id={{settings.coderedcms.AnalyticsSettings.ga_tracking_id}}"></script>
-  {% else %}
   <script async src="https://www.googletagmanager.com/gtag/js?id={{settings.coderedcms.AnalyticsSettings.ga_g_tracking_id}}"></script>
-  {% endif %}
   <script>
     cr_track_clicks = {{settings.coderedcms.AnalyticsSettings.ga_track_button_clicks|yesno:"true,false"}};
     window.dataLayer = window.dataLayer || [];
     function gtag(){dataLayer.push(arguments);}
     gtag('js', new Date());
-    // {% if settings.coderedcms.AnalyticsSettings.ga_tracking_id %}
-    gtag('config', '{{settings.coderedcms.AnalyticsSettings.ga_tracking_id}}');
-    // {% endif %} {% if settings.coderedcms.AnalyticsSettings.ga_g_tracking_id %}
     gtag('config', '{{settings.coderedcms.AnalyticsSettings.ga_g_tracking_id}}');
-    // {% endif %}
   </script>
   {% endif %}
   {% if settings.coderedcms.AnalyticsSettings.gtm_id %}

+ 6 - 6
docs/how_to/add_tracking_scripts.rst

@@ -19,16 +19,16 @@ Google Analytics
 ----------------
 
 There are two types of Google Analytics accounts --- "Google Analytics 4" (GA4)
-and "Universal Analytics" (for old accounts created before 2021):
+and "Universal Analytics" (which is discontinued as of July 2023):
 
 * **Google Analytics 4 (GA4)** account IDs begin with **G-**
 
-* **Universal Analytics** account IDs begin with **UA-**. Google is shutting
-  down UA accounts in July 2023, so it is recommended to use GA4 accounts
-  instead.
+* **Universal Analytics** account IDs begin with **UA-**. Google shut
+  down UA accounts in July 2023, so these will no longer work.
 
-* If you are using both account types, you can enter both IDs and the data will
-  populate both accounts.
+.. deprecated:: 3.0
+
+   Support for Universal Analytics was removed in CRX version 3.0.
 
 
 Google Tag Manager (GTM)

+ 1 - 2
tutorial/mysite/website/fixtures/database.json

@@ -4703,7 +4703,7 @@
                 "localhost",
                 80
             ],
-            "ga_tracking_id": "",
+            "ga_g_tracking_id": "",
             "ga_track_button_clicks": false
         }
     },
@@ -4995,4 +4995,3 @@
         }
     }
     ]
-