Skip to content

Commit

Permalink
Merge pull request #954 from readthedocs/davidfischer/offer-domain-co…
Browse files Browse the repository at this point in the history
…llection

Collect the domain on offer creation
  • Loading branch information
davidfischer authored Dec 3, 2024
2 parents 477eabe + 141dd29 commit dbc93c7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
28 changes: 28 additions & 0 deletions adserver/migrations/0100_add_offer_domain.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
6 changes: 6 additions & 0 deletions adserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions adserver/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit dbc93c7

Please sign in to comment.