From 141dd29883bc0756545e0310a76bc86b1cb1cc16 Mon Sep 17 00:00:00 2001 From: David Fischer Date: Mon, 2 Dec 2024 15:54:20 -0800 Subject: [PATCH] Collect the domain on offer creation --- adserver/migrations/0100_add_offer_domain.py | 28 ++++++++++++++++++++ adserver/models.py | 6 +++++ adserver/tests/test_models.py | 1 + 3 files changed, 35 insertions(+) create mode 100644 adserver/migrations/0100_add_offer_domain.py diff --git a/adserver/migrations/0100_add_offer_domain.py b/adserver/migrations/0100_add_offer_domain.py new file mode 100644 index 00000000..0a8e675d --- /dev/null +++ b/adserver/migrations/0100_add_offer_domain.py @@ -0,0 +1,28 @@ +# Generated by Django 5.0.9 on 2024-12-02 23:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('adserver', '0099_link_advertiser_guide'), + ] + + operations = [ + migrations.AddField( + model_name='click', + name='domain', + field=models.CharField(blank=True, max_length=10000, null=True, verbose_name='Domain'), + ), + migrations.AddField( + model_name='offer', + name='domain', + field=models.CharField(blank=True, max_length=10000, null=True, verbose_name='Domain'), + ), + migrations.AddField( + model_name='view', + name='domain', + field=models.CharField(blank=True, max_length=10000, null=True, verbose_name='Domain'), + ), + ] diff --git a/adserver/models.py b/adserver/models.py index fe69f013..6009e53a 100644 --- a/adserver/models.py +++ b/adserver/models.py @@ -1775,6 +1775,7 @@ def _record_base( parsed_ua = parse(user_agent) country = get_client_country(request) url = url or request.headers.get("referer") + domain = get_domain_from_url(url) if ( model != Click @@ -1799,6 +1800,7 @@ def _record_base( client_id=client_id, country=country, url=url, + domain=domain, paid_eligible=paid_eligible, rotations=rotations, # Derived user agent data @@ -2589,6 +2591,10 @@ class AdBase(TimeStampedModel, IndestructibleModel): country = CountryField(null=True) url = models.CharField(_("Page URL"), max_length=10000, blank=True, null=True) + # Domain of the URL or None if the URL is not available + # Should not include http or any characters after the TLD + domain = models.CharField(_("Domain"), max_length=10000, blank=True, null=True) + # Fields derived from the user agent - these should not be user identifiable browser_family = models.CharField( _("Browser Family"), max_length=1000, blank=True, null=True, default=None diff --git a/adserver/tests/test_models.py b/adserver/tests/test_models.py index 8e9d036b..11bf59ec 100644 --- a/adserver/tests/test_models.py +++ b/adserver/tests/test_models.py @@ -633,6 +633,7 @@ def test_offer_ad(self): self.assertEqual(offer.advertisement, self.ad1) self.assertEqual(offer.div_id, div_id) self.assertEqual(offer.url, url) + self.assertEqual(offer.domain, "example.com") self.assertEqual(offer.ip, "1.1.0.0") # anonymized self.assertEqual(offer.os_family, "Linux") self.assertEqual(offer.browser_family, "Chrome")